diff options
Diffstat (limited to 'plugins/jetpack/modules/likes/post-count.js')
-rw-r--r-- | plugins/jetpack/modules/likes/post-count.js | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/plugins/jetpack/modules/likes/post-count.js b/plugins/jetpack/modules/likes/post-count.js index 6f4c779f..8ea4466a 100644 --- a/plugins/jetpack/modules/likes/post-count.js +++ b/plugins/jetpack/modules/likes/post-count.js @@ -1,20 +1,22 @@ -var wpPostLikeCount = wpPostLikeCount || {}; +window.wpPostLikeCount = window.wpPostLikeCount || {}; -( function( $ ) { - wpPostLikeCount = jQuery.extend( wpPostLikeCount, { +( function ( $ ) { + window.wpPostLikeCount = jQuery.extend( window.wpPostLikeCount, { jsonAPIbase: 'https://public-api.wordpress.com/rest/v1', APIqueue: [], - wpPostLikeCount: function() { - $( '.post-like-count' ).each( function() { + wpPostLikeCount: function () { + $( '.post-like-count' ).each( function () { var post_id = $( this ).attr( 'data-post-id' ); var blog_id = $( this ).attr( 'data-blog-id' ); - wpPostLikeCount.APIqueue.push( '/sites/' + blog_id + '/posts/' + post_id + '/likes' ); + window.wpPostLikeCount.APIqueue.push( + '/sites/' + blog_id + '/posts/' + post_id + '/likes' + ); } ); - wpPostLikeCount.getCounts(); + window.wpPostLikeCount.getCounts(); }, - showCount: function( post_id, count ) { + showCount: function ( post_id, count ) { if ( count > 0 ) { $( '#post-like-count-' + post_id ) .find( '.comment-count' ) @@ -28,35 +30,35 @@ var wpPostLikeCount = wpPostLikeCount || {}; } }, - getCounts: function() { + getCounts: function () { var batchRequest = { path: '/batch', data: '', - success: function( response ) { + success: function ( response ) { for ( var path in response ) { if ( ! response[ path ].error_data ) { var urlPieces = path.split( '/' ); // pieces[4] = post id; var post_id = urlPieces[ 4 ]; - wpPostLikeCount.showCount( post_id, response[ path ].found ); + window.wpPostLikeCount.showCount( post_id, response[ path ].found ); } } }, - error: function(/*response*/) {}, + error: function (/*response*/) {}, }; var amp = ''; - for ( var i = 0; i < wpPostLikeCount.APIqueue.length; i++ ) { + for ( var i = 0; i < window.wpPostLikeCount.APIqueue.length; i++ ) { if ( i > 0 ) { amp = '&'; } - batchRequest.data += amp + 'urls[]=' + wpPostLikeCount.APIqueue[ i ]; + batchRequest.data += amp + 'urls[]=' + window.wpPostLikeCount.APIqueue[ i ]; } - wpPostLikeCount.request( batchRequest ); + window.wpPostLikeCount.request( batchRequest ); }, } ); } )( jQuery ); -jQuery( document ).ready( function(/*$*/) { - wpPostLikeCount.wpPostLikeCount(); +jQuery( document ).ready( function (/*$*/) { + window.wpPostLikeCount.wpPostLikeCount(); } ); |