PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.5
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.5
16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 All 506 releases
jetpack / modules / likes / post-count.js

post-count.js in Jetpack – WP Security, Backup, Speed, & Growth 16.3-a.5, at modules/likes/post-count.js

65 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 window.wpPostLikeCount = window.wpPostLikeCount || {};
2
3 ( function ( $ ) {
4 window.wpPostLikeCount = jQuery.extend( window.wpPostLikeCount, {
5 jsonAPIbase: 'https://public-api.wordpress.com/rest/v1',
6 APIqueue: [],
7
8 wpPostLikeCount: function () {
9 $( '.post-like-count' ).each( function () {
10 var post_id = $( this ).attr( 'data-post-id' );
11 var blog_id = $( this ).attr( 'data-blog-id' );
12 window.wpPostLikeCount.APIqueue.push(
13 '/sites/' + blog_id + '/posts/' + post_id + '/likes'
14 );
15 } );
16 window.wpPostLikeCount.getCounts();
17 },
18
19 showCount: function ( post_id, count ) {
20 if ( count > 0 ) {
21 $( '#post-like-count-' + post_id )
22 .find( '.comment-count' )
23 .hide();
24 $( '#post-like-count-' + post_id )
25 .find( '.comment-count' )
26 .text( count );
27 $( '#post-like-count-' + post_id )
28 .find( '.comment-count' )
29 .fadeIn();
30 }
31 },
32
33 getCounts: function () {
34 var batchRequest = {
35 path: '/batch',
36 data: '',
37 success: function ( response ) {
38 for ( var path in response ) {
39 if ( ! response[ path ].error_data ) {
40 var urlPieces = path.split( '/' ); // pieces[4] = post id;
41 var post_id = urlPieces[ 4 ];
42 window.wpPostLikeCount.showCount( post_id, response[ path ].found );
43 }
44 }
45 },
46 error: function ( /*response*/ ) {},
47 };
48
49 var amp = '';
50 for ( var i = 0; i < window.wpPostLikeCount.APIqueue.length; i++ ) {
51 if ( i > 0 ) {
52 amp = '&';
53 }
54 batchRequest.data += amp + 'urls[]=' + window.wpPostLikeCount.APIqueue[ i ];
55 }
56
57 window.wpPostLikeCount.request( batchRequest );
58 },
59 } );
60 } )( jQuery );
61
62 jQuery( document ).ready( function ( /*$*/ ) {
63 window.wpPostLikeCount.wpPostLikeCount();
64 } );
65