Initial Commit
This commit is contained in:
parent
4c352bf02e
commit
1ab6e5f0b0
1085 changed files with 195258 additions and 0 deletions
18
plugins/jetpack/modules/likes/post-count-jetpack.js
Normal file
18
plugins/jetpack/modules/likes/post-count-jetpack.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
var wpPostLikeCount = wpPostLikeCount || {};
|
||||
|
||||
(function($) {
|
||||
|
||||
wpPostLikeCount = jQuery.extend( wpPostLikeCount, {
|
||||
request: function( options ) {
|
||||
return $.ajax( {
|
||||
type: 'GET',
|
||||
url: wpPostLikeCount.jsonAPIbase + options.path,
|
||||
dataType : 'jsonp',
|
||||
data: options.data,
|
||||
success: function( response ) { options.success( response ); },
|
||||
error: function( response ) { options.error( response ); }
|
||||
} );
|
||||
}
|
||||
} );
|
||||
|
||||
})(jQuery);
|
62
plugins/jetpack/modules/likes/post-count.js
Normal file
62
plugins/jetpack/modules/likes/post-count.js
Normal file
|
@ -0,0 +1,62 @@
|
|||
/* jshint onevar: false, smarttabs: true */
|
||||
|
||||
var wpPostLikeCount = wpPostLikeCount || {};
|
||||
|
||||
(function($) {
|
||||
|
||||
wpPostLikeCount = jQuery.extend( wpPostLikeCount, {
|
||||
|
||||
jsonAPIbase: 'https://public-api.wordpress.com/rest/v1',
|
||||
APIqueue: [],
|
||||
|
||||
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' );
|
||||
} );
|
||||
wpPostLikeCount.getCounts();
|
||||
},
|
||||
|
||||
showCount: function( post_id, count ) {
|
||||
if ( count > 0 ) {
|
||||
$( '#post-like-count-' + post_id ).find( '.comment-count' ).hide();
|
||||
$( '#post-like-count-' + post_id ).find( '.comment-count' ).text( count );
|
||||
$( '#post-like-count-' + post_id ).find( '.comment-count' ).fadeIn();
|
||||
}
|
||||
},
|
||||
|
||||
getCounts: function() {
|
||||
var batchRequest = {
|
||||
path: '/batch',
|
||||
data: '',
|
||||
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 );
|
||||
}
|
||||
}
|
||||
},
|
||||
error: function( /*response*/ ) {
|
||||
}
|
||||
};
|
||||
|
||||
var amp = '';
|
||||
for( var i = 0; i < wpPostLikeCount.APIqueue.length; i++ ) {
|
||||
if ( i > 0 ) {
|
||||
amp = '&';
|
||||
}
|
||||
batchRequest.data += amp + 'urls[]=' + wpPostLikeCount.APIqueue[i];
|
||||
}
|
||||
|
||||
wpPostLikeCount.request( batchRequest );
|
||||
}
|
||||
} );
|
||||
|
||||
})(jQuery);
|
||||
|
||||
jQuery(document).ready(function(/*$*/) {
|
||||
wpPostLikeCount.wpPostLikeCount();
|
||||
});
|
278
plugins/jetpack/modules/likes/queuehandler.js
Normal file
278
plugins/jetpack/modules/likes/queuehandler.js
Normal file
|
@ -0,0 +1,278 @@
|
|||
/* global pm, wpcom_reblog */
|
||||
|
||||
var jetpackLikesWidgetQueue = [];
|
||||
var jetpackLikesWidgetBatch = [];
|
||||
var jetpackLikesMasterReady = false;
|
||||
|
||||
function JetpackLikespostMessage( message, target ) {
|
||||
if ( 'string' === typeof message ){
|
||||
try {
|
||||
message = JSON.parse( message );
|
||||
} catch(e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
pm( {
|
||||
target: target,
|
||||
type: 'likesMessage',
|
||||
data: message,
|
||||
origin: '*'
|
||||
} );
|
||||
}
|
||||
|
||||
function JetpackLikesBatchHandler() {
|
||||
var requests = [];
|
||||
jQuery( 'div.jetpack-likes-widget-unloaded' ).each( function() {
|
||||
if ( jetpackLikesWidgetBatch.indexOf( this.id ) > -1 ) {
|
||||
return;
|
||||
}
|
||||
jetpackLikesWidgetBatch.push( this.id );
|
||||
var regex = /like-(post|comment)-wrapper-(\d+)-(\d+)-(\w+)/,
|
||||
match = regex.exec( this.id ),
|
||||
info;
|
||||
|
||||
if ( ! match || match.length !== 5 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
info = {
|
||||
blog_id: match[2],
|
||||
width: this.width
|
||||
};
|
||||
|
||||
if ( 'post' === match[1] ) {
|
||||
info.post_id = match[3];
|
||||
} else if ( 'comment' === match[1] ) {
|
||||
info.comment_id = match[3];
|
||||
}
|
||||
|
||||
info.obj_id = match[4];
|
||||
|
||||
requests.push( info );
|
||||
});
|
||||
|
||||
if ( requests.length > 0 ) {
|
||||
JetpackLikespostMessage( { event: 'initialBatch', requests: requests }, window.frames['likes-master'] );
|
||||
}
|
||||
}
|
||||
|
||||
function JetpackLikesMessageListener( event, message ) {
|
||||
var allowedOrigin, $container, $list, offset, rowLength, height, scrollbarWidth;
|
||||
|
||||
if ( 'undefined' === typeof event.event ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// We only allow messages from one origin
|
||||
allowedOrigin = window.location.protocol + '//widgets.wp.com';
|
||||
if ( allowedOrigin !== message.origin ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 'masterReady' === event.event ) {
|
||||
jQuery( document ).ready( function() {
|
||||
jetpackLikesMasterReady = true;
|
||||
|
||||
var stylesData = {
|
||||
event: 'injectStyles'
|
||||
},
|
||||
$sdTextColor = jQuery( '.sd-text-color' ),
|
||||
$sdLinkColor = jQuery( '.sd-link-color' );
|
||||
|
||||
if ( jQuery( 'iframe.admin-bar-likes-widget' ).length > 0 ) {
|
||||
JetpackLikespostMessage( { event: 'adminBarEnabled' }, window.frames[ 'likes-master' ] );
|
||||
|
||||
stylesData.adminBarStyles = {
|
||||
background: jQuery( '#wpadminbar .quicklinks li#wp-admin-bar-wpl-like > a' ).css( 'background' ),
|
||||
isRtl: ( 'rtl' === jQuery( '#wpadminbar' ).css( 'direction' ) )
|
||||
};
|
||||
}
|
||||
|
||||
if ( ! window.addEventListener ) {
|
||||
jQuery( '#wp-admin-bar-admin-bar-likes-widget' ).hide();
|
||||
}
|
||||
|
||||
stylesData.textStyles = {
|
||||
color: $sdTextColor.css( 'color' ),
|
||||
fontFamily: $sdTextColor.css( 'font-family' ),
|
||||
fontSize: $sdTextColor.css( 'font-size' ),
|
||||
direction: $sdTextColor.css( 'direction' ),
|
||||
fontWeight: $sdTextColor.css( 'font-weight' ),
|
||||
fontStyle: $sdTextColor.css( 'font-style' ),
|
||||
textDecoration: $sdTextColor.css('text-decoration')
|
||||
};
|
||||
|
||||
stylesData.linkStyles = {
|
||||
color: $sdLinkColor.css('color'),
|
||||
fontFamily: $sdLinkColor.css('font-family'),
|
||||
fontSize: $sdLinkColor.css('font-size'),
|
||||
textDecoration: $sdLinkColor.css('text-decoration'),
|
||||
fontWeight: $sdLinkColor.css( 'font-weight' ),
|
||||
fontStyle: $sdLinkColor.css( 'font-style' )
|
||||
};
|
||||
|
||||
JetpackLikespostMessage( stylesData, window.frames[ 'likes-master' ] );
|
||||
|
||||
JetpackLikesBatchHandler();
|
||||
|
||||
jQuery( document ).on( 'inview', 'div.jetpack-likes-widget-unloaded', function() {
|
||||
jetpackLikesWidgetQueue.push( this.id );
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if ( 'showLikeWidget' === event.event ) {
|
||||
jQuery( '#' + event.id + ' .post-likes-widget-placeholder' ).fadeOut( 'fast', function() {
|
||||
jQuery( '#' + event.id + ' .post-likes-widget' ).fadeIn( 'fast', function() {
|
||||
JetpackLikespostMessage( { event: 'likeWidgetDisplayed', blog_id: event.blog_id, post_id: event.post_id, obj_id: event.obj_id }, window.frames['likes-master'] );
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if ( 'clickReblogFlair' === event.event ) {
|
||||
wpcom_reblog.toggle_reblog_box_flair( event.obj_id );
|
||||
}
|
||||
|
||||
if ( 'showOtherGravatars' === event.event ) {
|
||||
$container = jQuery( '#likes-other-gravatars' );
|
||||
$list = $container.find( 'ul' );
|
||||
|
||||
$container.hide();
|
||||
$list.html( '' );
|
||||
|
||||
$container.find( '.likes-text span' ).text( event.total );
|
||||
|
||||
jQuery.each( event.likers, function( i, liker ) {
|
||||
var element;
|
||||
|
||||
if ( 'http' !== liker.profile_URL.substr( 0, 4 ) ) {
|
||||
// We only display gravatars with http or https schema
|
||||
return;
|
||||
}
|
||||
|
||||
element = jQuery( '<li><a><img /></a></li>' );
|
||||
element.addClass( liker.css_class );
|
||||
|
||||
element.find( 'a' ).
|
||||
attr({
|
||||
href: liker.profile_URL,
|
||||
rel: 'nofollow',
|
||||
target: '_parent'
|
||||
}).
|
||||
addClass( 'wpl-liker' );
|
||||
|
||||
element.find( 'img' ).
|
||||
attr({
|
||||
src: liker.avatar_URL,
|
||||
alt: liker.name
|
||||
}).
|
||||
css({
|
||||
width: '30px',
|
||||
height: '30px',
|
||||
paddingRight: '3px'
|
||||
});
|
||||
|
||||
$list.append( element );
|
||||
} );
|
||||
|
||||
offset = jQuery( '[name=\'' + event.parent + '\']' ).offset();
|
||||
|
||||
$container.css( 'left', offset.left + event.position.left - 10 + 'px' );
|
||||
$container.css( 'top', offset.top + event.position.top - 33 + 'px' );
|
||||
|
||||
rowLength = Math.floor( event.width / 37 );
|
||||
height = ( Math.ceil( event.likers.length / rowLength ) * 37 ) + 13;
|
||||
if ( height > 204 ) {
|
||||
height = 204;
|
||||
}
|
||||
|
||||
$container.css( 'height', height + 'px' );
|
||||
$container.css( 'width', rowLength * 37 - 7 + 'px' );
|
||||
|
||||
$list.css( 'width', rowLength * 37 + 'px' );
|
||||
|
||||
$container.fadeIn( 'slow' );
|
||||
|
||||
scrollbarWidth = $list[0].offsetWidth - $list[0].clientWidth;
|
||||
if ( scrollbarWidth > 0 ) {
|
||||
$container.width( $container.width() + scrollbarWidth );
|
||||
$list.width( $list.width() + scrollbarWidth );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pm.bind( 'likesMessage', JetpackLikesMessageListener );
|
||||
|
||||
jQuery( document ).click( function( e ) {
|
||||
var $container = jQuery( '#likes-other-gravatars' );
|
||||
|
||||
if ( $container.has( e.target ).length === 0 ) {
|
||||
$container.fadeOut( 'slow' );
|
||||
}
|
||||
});
|
||||
|
||||
function JetpackLikesWidgetQueueHandler() {
|
||||
var $wrapper, wrapperID, found;
|
||||
if ( ! jetpackLikesMasterReady ) {
|
||||
setTimeout( JetpackLikesWidgetQueueHandler, 500 );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( jetpackLikesWidgetQueue.length > 0 ) {
|
||||
// We may have a widget that needs creating now
|
||||
found = false;
|
||||
while( jetpackLikesWidgetQueue.length > 0 ) {
|
||||
// Grab the first member of the queue that isn't already loading.
|
||||
wrapperID = jetpackLikesWidgetQueue.splice( 0, 1 )[0];
|
||||
if ( jQuery( '#' + wrapperID ).hasClass( 'jetpack-likes-widget-unloaded' ) ) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( ! found ) {
|
||||
setTimeout( JetpackLikesWidgetQueueHandler, 500 );
|
||||
return;
|
||||
}
|
||||
} else if ( jQuery( 'div.jetpack-likes-widget-unloaded' ).length > 0 ) {
|
||||
// Grab any unloaded widgets for a batch request
|
||||
JetpackLikesBatchHandler();
|
||||
|
||||
// Get the next unloaded widget
|
||||
wrapperID = jQuery( 'div.jetpack-likes-widget-unloaded' ).first()[0].id;
|
||||
if ( ! wrapperID ) {
|
||||
// Everything is currently loaded
|
||||
setTimeout( JetpackLikesWidgetQueueHandler, 500 );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( 'undefined' === typeof wrapperID ) {
|
||||
setTimeout( JetpackLikesWidgetQueueHandler, 500 );
|
||||
return;
|
||||
}
|
||||
|
||||
$wrapper = jQuery( '#' + wrapperID );
|
||||
$wrapper.find( 'iframe' ).remove();
|
||||
|
||||
if ( $wrapper.hasClass( 'slim-likes-widget' ) ) {
|
||||
$wrapper.find( '.post-likes-widget-placeholder' ).after( '<iframe class="post-likes-widget jetpack-likes-widget" name="' + $wrapper.data( 'name' ) + '" height="22px" width="68px" frameBorder="0" scrolling="no" src="' + $wrapper.data( 'src' ) + '"></iframe>' );
|
||||
} else {
|
||||
$wrapper.find( '.post-likes-widget-placeholder' ).after( '<iframe class="post-likes-widget jetpack-likes-widget" name="' + $wrapper.data( 'name' ) + '" height="55px" width="100%" frameBorder="0" src="' + $wrapper.data( 'src' ) + '"></iframe>' );
|
||||
}
|
||||
|
||||
$wrapper.removeClass( 'jetpack-likes-widget-unloaded' ).addClass( 'jetpack-likes-widget-loading' );
|
||||
|
||||
$wrapper.find( 'iframe' ).load( function( e ) {
|
||||
var $iframe = jQuery( e.target );
|
||||
$wrapper.removeClass( 'jetpack-likes-widget-loading' ).addClass( 'jetpack-likes-widget-loaded' );
|
||||
|
||||
JetpackLikespostMessage( { event: 'loadLikeWidget', name: $iframe.attr( 'name' ), width: $iframe.width() }, window.frames[ 'likes-master' ] );
|
||||
|
||||
if ( $wrapper.hasClass( 'slim-likes-widget' ) ) {
|
||||
$wrapper.find( 'iframe' ).Jetpack( 'resizeable' );
|
||||
}
|
||||
});
|
||||
setTimeout( JetpackLikesWidgetQueueHandler, 250 );
|
||||
}
|
||||
JetpackLikesWidgetQueueHandler();
|
193
plugins/jetpack/modules/likes/style.css
Normal file
193
plugins/jetpack/modules/likes/style.css
Normal file
|
@ -0,0 +1,193 @@
|
|||
/**
|
||||
* Like Button toolbar button, loading text & container styles
|
||||
*
|
||||
* @todo: doesn't look like "style.css" is used anymore.
|
||||
*/
|
||||
|
||||
|
||||
/* Master container */
|
||||
#jp-post-flair {
|
||||
padding-top: .5em;
|
||||
}
|
||||
|
||||
/* Overall Sharedaddy block title */
|
||||
div.sharedaddy,
|
||||
#content div.sharedaddy,
|
||||
#main div.sharedaddy {
|
||||
clear: both;
|
||||
}
|
||||
|
||||
div.sharedaddy h3.sd-title {
|
||||
margin: 0 0 1em 0;
|
||||
display: inline-block;
|
||||
line-height: 1.2;
|
||||
font-size: 9pt;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
div.sharedaddy h3.sd-title:before {
|
||||
content: "";
|
||||
display: block;
|
||||
width: 100%;
|
||||
min-width: 30px;
|
||||
border-top: 1px solid #ddd;
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
|
||||
|
||||
/* Toolbar */
|
||||
#wpadminbar li#wp-admin-bar-admin-bar-likes-widget {
|
||||
width: 61px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#wpadminbar iframe.admin-bar-likes-widget {
|
||||
width: 61px;
|
||||
height: 28px;
|
||||
min-height: 28px;
|
||||
border-width: 0px;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
div.jetpack-likes-widget-wrapper {
|
||||
width: 100%;
|
||||
min-height: 50px; /* Previous height, 60px */
|
||||
position: relative; /* Need to abs position placeholder and iframe so there isn't a jarring jump */
|
||||
}
|
||||
|
||||
div.jetpack-likes-widget-wrapper .sd-link-color {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
div.jetpack-likes-widget-wrapper.slim-likes-widget {
|
||||
width: 1px; /* initial default */
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
#likes-other-gravatars {
|
||||
display: none;
|
||||
position: absolute;
|
||||
padding: 10px 10px 12px 10px;
|
||||
background-color: #2e4453;
|
||||
border-width: 0;
|
||||
box-shadow: 0 0 10px #2e4453;
|
||||
box-shadow: 0 0 10px rgba(46,68,83,.6);
|
||||
min-width: 130px;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
#likes-other-gravatars * {
|
||||
line-height: normal;
|
||||
}
|
||||
|
||||
#likes-other-gravatars .likes-text {
|
||||
color: white;
|
||||
font-size: 12px;
|
||||
padding-bottom: 8px;
|
||||
}
|
||||
|
||||
#likes-other-gravatars ul,
|
||||
#likes-other-gravatars li {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
text-indent: 0;
|
||||
list-style-type: none;
|
||||
}
|
||||
|
||||
#likes-other-gravatars li::before {
|
||||
content: "";
|
||||
}
|
||||
|
||||
#likes-other-gravatars ul.wpl-avatars {
|
||||
overflow: auto;
|
||||
display: block;
|
||||
max-height: 190px;
|
||||
}
|
||||
|
||||
#likes-other-gravatars ul.wpl-avatars li {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
float: left;
|
||||
margin: 0 5px 5px 0;
|
||||
}
|
||||
|
||||
#likes-other-gravatars ul.wpl-avatars li a {
|
||||
margin: 0 2px 0 0;
|
||||
border-bottom: none !important;
|
||||
display: block;
|
||||
}
|
||||
|
||||
#likes-other-gravatars ul.wpl-avatars li a img {
|
||||
background: none;
|
||||
border: none;
|
||||
margin: 0 !important;
|
||||
padding: 0 !important;
|
||||
position: static;
|
||||
}
|
||||
|
||||
div.sd-box {
|
||||
border-top: 1px solid #ddd;
|
||||
border-top: 1px solid rgba(0,0,0,.13);
|
||||
}
|
||||
|
||||
.entry-content .post-likes-widget, .post-likes-widget,
|
||||
.comment-likes-widget {
|
||||
margin: 0;
|
||||
border-width: 0;
|
||||
display: block;
|
||||
}
|
||||
|
||||
|
||||
/* Loading text */
|
||||
.post-likes-widget-placeholder {
|
||||
margin: 0;
|
||||
border-width: 0;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.post-likes-widget-placeholder .button {
|
||||
display: none; /* Let's not show a dummy like button, let's just make a great button experience once it's loaded */
|
||||
}
|
||||
|
||||
.post-likes-widget-placeholder .button span {
|
||||
}
|
||||
|
||||
.post-likes-widget-placeholder .loading {
|
||||
color: #999;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.slim-likes-widget .post-likes-widget {
|
||||
width: auto;
|
||||
float: none;
|
||||
}
|
||||
|
||||
|
||||
/* Like Special cases (display on it's own) */
|
||||
div.sharedaddy.sd-like-enabled .sd-like h3 {
|
||||
display: none;
|
||||
}
|
||||
|
||||
div.sharedaddy.sd-like-enabled .sd-like .post-likes-widget {
|
||||
width: 100%;
|
||||
float: none;
|
||||
position: absolute; /* Need to abs position placeholder and iframe so there isn't a jarring jump */
|
||||
top: 0;
|
||||
}
|
||||
|
||||
.comment-likes-widget {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
|
||||
/* Make ratings block. @todo: make !important unnecessary by removing inline style */
|
||||
.pd-rating {
|
||||
display: block !important;
|
||||
}
|
||||
|
||||
|
||||
/* Hide G+ title */
|
||||
.sd-gplus .sd-title {
|
||||
display: none;
|
||||
}
|
Reference in a new issue