can3p (can3p) wrote in changelog,
can3p
can3p
changelog

[livejournal] r21757: LJSUP-11891: Like buttons on the journal...

Committer: dpetrov
LJSUP-11891: Like buttons on the journal pages should be loaded only when they become visible on the screen.
U   trunk/htdocs/js/journal.js
U   trunk/htdocs/stc/lj_base.css
Modified: trunk/htdocs/js/journal.js
===================================================================
--- trunk/htdocs/js/journal.js	2012-04-19 14:42:59 UTC (rev 21756)
+++ trunk/htdocs/js/journal.js	2012-04-19 15:00:54 UTC (rev 21757)
@@ -397,3 +397,51 @@
 	widgets.forEach(function(prop) { prop.handler(); });
 })();
 
+
+/**
+* delayed like buttons loader
+*/
+(function() {
+	var likePos = [];
+
+	LiveJournal.register_hook('page_load', function() {
+		
+		likePos = jQuery('.lj-like').map(function() {
+			return {
+				el: this,
+				top: jQuery(this).position().top,
+				init: false
+			};
+		}).toArray();
+
+		fullInit();
+
+		if (likePos.length > 0) jQuery(window).scroll(fullInit);
+	});
+
+	function fullInit() {
+		if (likePos.length > 0) {
+			
+			var scrollTop = jQuery(window).scrollTop(),
+				windowHeight = jQuery(window).height(),
+
+				toInit = likePos.filter(function(like) {
+					return (!like.init &&
+							 like.top > scrollTop &&
+							 like.top < scrollTop + windowHeight + 200);
+				});
+
+			toInit.forEach(function(like) {
+				var jEl = jQuery(like.el),
+					likeHtml = jEl.html();
+				
+
+				jEl.html(likeHtml.slice(4, -3)); // strip '<!--' and '-->'
+				LiveJournal.parseLikeButtons();
+
+				like.init = true;
+			});
+		}
+	}
+	
+})();

Modified: trunk/htdocs/stc/lj_base.css
===================================================================
--- trunk/htdocs/stc/lj_base.css	2012-04-19 14:42:59 UTC (rev 21756)
+++ trunk/htdocs/stc/lj_base.css	2012-04-19 15:00:54 UTC (rev 21757)
@@ -3685,6 +3685,7 @@
 /* LJ like buttons 
 -----------------------------------------------*/
 .lj-like {
+	min-height: 48px;
 	margin:12px 0!important;
 	}
 	.lj-like-item {

Tags: can3p, css, dpetrov, js, livejournal
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments