Valerii Vasin (valerii) wrote in changelog,
Valerii Vasin
valerii
changelog

[livejournal] r23244: LJSUP-14136: [Friends Feed] Optimize lik...

Committer: vvasin
LJSUP-14136: [Friends Feed] Optimize like buttons parsing. Provide documentation.
U   trunk/htdocs/js/livejournal.js
Modified: trunk/htdocs/js/livejournal.js
===================================================================
--- trunk/htdocs/js/livejournal.js	2012-11-01 14:40:54 UTC (rev 23243)
+++ trunk/htdocs/js/livejournal.js	2012-11-01 14:54:58 UTC (rev 23244)
@@ -412,7 +412,7 @@
 
 	/**
 	 * Parse lj-like buttons
-	 * @param  {Object} context jQuery Node (with class .lj-like)
+	 * @param  {Object} $node jQuery .lj-like node
 	 */
 	function parse($node) {
 		parseFacebook($node);
@@ -424,7 +424,36 @@
 	}
 
 	/**
+	 * Create iframe node with default params and ability to redefine them (iframe factory)
+	 * @param  {Object} params Params to substitute for iframe {src, width, height...}
+	 * @return {Element}       Created iframe node
+	 */
+	function createIframe(params) {
+		var iframe = document.createElement('iframe'),
+			param;
+
+		// defaults
+		iframe.frameBorder = 0;
+		iframe.scrolling = 'no';
+		iframe.allowTransparency = 'true';
+		iframe.width = 110;
+		iframe.height = 20;
+
+		// reassign params
+		if (params) {
+			for (param in params) {
+				if (params.hasOwnProperty(param)) {
+					iframe[param] = params[param];
+				}
+			}
+		}
+
+		return iframe;
+	}
+
+	/**
 	 * Parse facebook likes
+	 * Documentation: http://developers.facebook.com/docs/reference/javascript/FB.XFBML.parse/
 	 * @param  {jQuery} $node jQuery collection
 	 */
 	function parseFacebook($node) {
@@ -437,45 +466,22 @@
 
 	/**
 	 * Parse google +1 button
+	 * Documentation: https://developers.google.com/+/plugins/+1button/#jsapi
 	 * @param  {jQuery} $node jQuery node with likes in which we will search for google +1 button for parsing
 	 */
 	function parseGoogle($node) {
 		// gapi could
 		try {
-			gapi.plusone.go( $node.find('.lj-like-item-google').get(0) );
+			window.gapi.plusone.go( $node.find('.lj-like-item-google').get(0) );
 		} catch (e) {
 			console.warn(e.message);
 		}
 	}
 
 	/**
-	 * Create iframe node with params
-	 * @param  {Object} params Params for iframe {src, width, height...}
-	 * @return {DOM}        [description]
+	 * Parse and replace twitter button
+	 * @param  {jQuery} $node jQuery node with .lj-like class
 	 */
-	function createIframe(params) {
-		var iframe = document.createElement('iframe'),
-			param;
-
-		// defaults
-		iframe.frameBorder = 0;
-		iframe.scrolling = 'no';
-		iframe.allowTransparency = 'true';
-		iframe.width = 110;
-		iframe.height = 20;
-
-		// reassign params
-		if (params) {
-			for (param in params) {
-				if (params.hasOwnProperty(param)) {
-					iframe[param] = params[param];
-				}
-			}
-		}
-
-		return iframe;
-	}
-
 	function parseTwitter($node) {
 		var params = null,
 			iframe = null,
@@ -497,6 +503,10 @@
 		link.replaceWith(iframe);
 	}
 
+	/**
+	 * Parse surfingbird share button
+	 * @param  {jQuery} $node jQuery .lj-like node
+	 */
 	function parseSurfingbird($node) {
 		var link = $node.find('.surfinbird__like_button'),
 			iframe = null,
@@ -515,6 +525,10 @@
 		link.replaceWith(iframe);
 	}
 
+	/**
+	 * Parse tumblr share button
+	 * @param  {jQuery} $node jQuery .lj-like node
+	 */
 	function parseTumblr($node) {
 		var link = $node.find('.tumblr-share-button'),
 			href = link.attr('href'),
@@ -526,6 +540,10 @@
 		link.attr('href', LiveJournal.constructUrl(href, params));
 	}
 
+	/**
+	 * Parse repost button
+	 * @param  {jQuery} $node jQuery .lj-like node
+	 */
 	function parseRepost($node) {
 		var link = $node.find('.lj-like-item-repost').find('a'),
 			url = link.data('url');

Tags: invis89, js, livejournal, vvasin
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