can3p (can3p) wrote in changelog,
can3p
can3p
changelog

[livejournal] r22112: LJSUP-11909: Fast Repost feature. Add pa...

Committer: dpetrov
LJSUP-11909: Fast Repost feature. Add parse code for repost button and the initialization code for lj.api.
U   trunk/htdocs/js/livejournal.js
Modified: trunk/htdocs/js/livejournal.js
===================================================================
--- trunk/htdocs/js/livejournal.js	2012-05-30 11:21:52 UTC (rev 22111)
+++ trunk/htdocs/js/livejournal.js	2012-05-30 11:24:38 UTC (rev 22112)
@@ -37,6 +37,10 @@
 		return;
 	}
 
+	if (LJ.Api) {
+		LJ.Api.init({ auth_token: Site.auth_token });
+	}
+
 	//register system hooks
 	LiveJournal.register_hook('update_wallet_balance', LiveJournal.updateWalletBalance);
 	LiveJournal.register_hook('xdr/message', LiveJournal.processXdr);
@@ -365,7 +369,7 @@
 	}, 'json');
 };
 
-LiveJournal.parseLikeButtons = function() {
+LiveJournal.parseLikeButtons = function(ctx) {
 	try {
 		FB.XFBML.parse();
 	} catch(e) {}
@@ -393,7 +397,7 @@
 		gapi.plusone.go();
 	} catch(e) {}
 
-	jQuery('a.twitter-share-button').each(function() {
+	jQuery('a.twitter-share-button', ctx || document).each(function() {
 		if (this.href != 'http://twitter.com/share') {
 			return;
 		}
@@ -412,6 +416,27 @@
 		.attr('src', LiveJournal.constructUrl('http://platform.twitter.com/widgets/tweet_button.html', params))
 		.insertBefore(link));
 	});
+
+	var initRepostButton = function(link, url, data) {
+		data = data || {};
+		var reposted = !!data.reposted;
+
+		var repostNode = LJ.UI.template('templates-CleanHtml-Repost', { url: url,
+			count: data.count || 0, reposted: reposted });
+		link.replaceWith(repostNode);
+
+		repostNode.repostbutton({
+			url: url,
+			reposted: reposted
+		});
+	}
+	
+	jQuery('div.lj-like-item-repost > a', ctx || document).each(function() {
+		var link = jQuery(this),
+			url = link.data('url');
+
+		LJ.Api.call('repost.get_status', { url: url }, initRepostButton.bind(null, link, url));
+	});
 };
 
 /**

Tags: can3p, 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