1/* global WPCOM_sharing_counts, grecaptcha */ 2var sharing_js_options; 3if ( sharing_js_options && sharing_js_options.counts ) { 4 var WPCOMSharing = { 5 done_urls : [], 6 get_counts : function() { 7 var url, requests, id, service, service_request; 8 9 if ( 'undefined' === typeof WPCOM_sharing_counts ) { 10 return; 11 } 12 13 for ( url in WPCOM_sharing_counts ) { 14 id = WPCOM_sharing_counts[ url ]; 15 16 if ( 'undefined' !== typeof WPCOMSharing.done_urls[ id ] ) { 17 continue; 18 } 19 20 requests = { 21 // LinkedIn actually gets the share count for both the http and https version automatically -- so we don't need to do extra magic 22 linkedin: [ 23 'https://www.linkedin.com/countserv/count/share?format=jsonp&callback=WPCOMSharing.update_linkedin_count&url=' + 24 encodeURIComponent( url ) 25 ], 26 // Pinterest, like LinkedIn, handles share counts for both http and https 27 pinterest: [ 28 window.location.protocol + 29 '//api.pinterest.com/v1/urls/count.json?callback=WPCOMSharing.update_pinterest_count&url=' + 30 encodeURIComponent( url ) 31 ], 32 // Facebook protocol summing has been shown to falsely double counts, so we only request the current URL 33 facebook: [ 34 window.location.protocol + 35 '//graph.facebook.com/?callback=WPCOMSharing.update_facebook_count&ids=' + 36 encodeURIComponent( url ) 37 ] 38 }; 39 40 for ( service in requests ) { 41 if ( ! jQuery( 'a[data-shared=sharing-' + service + '-' + id + ']' ).length ) { 42 continue; 43 } 44 45 while ( ( service_request = requests[ service ].pop() ) ) { 46 jQuery.getScript( service_request ); 47 } 48 49 WPCOMSharing.bump_sharing_count_stat( service ); 50 } 51 52 WPCOMSharing.done_urls[ id ] = true; 53 } 54 }, 55 56 // get the version of the url that was stored in the dom (sharing-$service-URL) 57 get_permalink: function( url ) { 58 if ( 'https:' === window.location.protocol ) { 59 url = url.replace( /^http:\/\//i, 'https://' ); 60 } else { 61 url = url.replace( /^https:\/\//i, 'http://' ); 62 } 63 64 return url; 65 }, 66 update_facebook_count: function( data ) { 67 var url, permalink; 68 69 if ( ! data ) { 70 return; 71 } 72 73 for ( url in data ) { 74 if ( ! data.hasOwnProperty( url ) || ! data[ url ].shares ) { 75 continue; 76 } 77 78 permalink = WPCOMSharing.get_permalink( url ); 79 80 if ( ! ( permalink in WPCOM_sharing_counts ) ) { 81 continue; 82 } 83 84 WPCOMSharing.inject_share_count( 'sharing-facebook-' + WPCOM_sharing_counts[ permalink ], data[ url ].shares ); 85 } 86 }, 87 update_linkedin_count : function( data ) { 88 if ( 'undefined' !== typeof data.count && ( data.count * 1 ) > 0 ) { 89 WPCOMSharing.inject_share_count( 'sharing-linkedin-' + WPCOM_sharing_counts[ data.url ], data.count ); 90 } 91 }, 92 update_pinterest_count : function( data ) { 93 if ( 'undefined' !== typeof data.count && ( data.count * 1 ) > 0 ) { 94 WPCOMSharing.inject_share_count( 'sharing-pinterest-' + WPCOM_sharing_counts[ data.url ], data.count ); 95 } 96 }, 97 inject_share_count : function( id, count ) { 98 var $share = jQuery( 'a[data-shared=' + id + '] > span'); 99 $share.find( '.share-count' ).remove(); 100 $share.append( '<span class="share-count">' + WPCOMSharing.format_count( count ) + '</span>' ); 101 }, 102 format_count : function( count ) { 103 if ( count < 1000 ) { 104 return count; 105 } 106 if ( count >= 1000 && count < 10000 ) { 107 return String( count ).substring( 0, 1 ) + 'K+'; 108 } 109 return '10K+'; 110 }, 111 bump_sharing_count_stat: function( service ) { 112 new Image().src = document.location.protocol + '//pixel.wp.com/g.gif?v=wpcom-no-pv&x_sharing-count-request=' + service + '&r=' + Math.random(); 113 } 114 }; 115} 116 117(function($){ 118 var $body, $sharing_email; 119 120 $.fn.extend( { 121 share_is_email: function() { 122 return /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test( this.val() ); 123 } 124 } ); 125 126 $body = $( document.body ).on( 'post-load', WPCOMSharing_do ); 127 $( document ).on( 'ready', function() { 128 $sharing_email = $( '#sharing_email' ); 129 $body.append( $sharing_email ); 130 WPCOMSharing_do(); 131 } ); 132 133 function WPCOMSharing_do() { 134 var $more_sharing_buttons; 135 if ( 'undefined' !== typeof WPCOMSharing ) { 136 WPCOMSharing.get_counts(); 137 } 138 $more_sharing_buttons = $( '.sharedaddy a.sharing-anchor' ); 139 140 $more_sharing_buttons.click( function() { 141 return false;
142 } ); 143 144 $( '.sharedaddy a' ).each( function() { 145 if ( $( this ).attr( 'href' ) && $( this ).attr( 'href' ).indexOf( 'share=' ) !== -1 ) { 146 $( this ).attr( 'href', $( this ).attr( 'href' ) + '&nb=1' ); 147 } 148 } ); 149 150 // Show hidden buttons 151 152 // Touchscreen device: use click. 153 // Non-touchscreen device: use click if not already appearing due to a hover event 154 $more_sharing_buttons.on( 'click', function() { 155 var $more_sharing_button = $( this ), 156 $more_sharing_pane = $more_sharing_button.parents( 'div:first' ).find( '.inner' ); 157 158 if ( $more_sharing_pane.is( ':animated' ) ) { 159 // We're in the middle of some other event's animation 160 return; 161 } 162 163 if ( true === $more_sharing_pane.data( 'justSlid' ) ) { 164 // We just finished some other event's animation - don't process click event so that slow-to-react-clickers don't get confused 165 return; 166 } 167 168 $sharing_email.slideUp( 200 ); 169 170 $more_sharing_pane.css( { 171 left: $more_sharing_button.position().left + 'px', 172 top: $more_sharing_button.position().top + $more_sharing_button.height() + 3 + 'px' 173 } ).slideToggle( 200 ); 174 } ); 175 176 if ( document.ontouchstart === undefined ) { 177 // Non-touchscreen device: use hover/mouseout with delay 178 $more_sharing_buttons.hover( function() { 179 var $more_sharing_button = $( this ), 180 $more_sharing_pane = $more_sharing_button.parents( 'div:first' ).find( '.inner' ), 181 timer; 182 183 if ( ! $more_sharing_pane.is( ':animated' ) ) { 184 // Create a timer to make the area appear if the mouse hovers for a period 185 timer = setTimeout( function() { 186 var handler_item_leave, handler_item_enter, handler_original_leave, handler_original_enter, close_it; 187 188 $sharing_email.slideUp( 200 ); 189 190 $more_sharing_pane.data( 'justSlid', true ); 191 $more_sharing_pane.css( { 192 left: $more_sharing_button.position().left + 'px', 193 top: $more_sharing_button.position().top + $more_sharing_button.height() + 3 + 'px' 194 } ).slideDown( 200, function() { 195 // Mark the item as have being appeared by the hover 196 $more_sharing_button.data( 'hasoriginal', true ).data( 'hasitem', false ); 197 198 setTimeout( function() { 199 $more_sharing_pane.data( 'justSlid', false ); 200 }, 300 ); 201 202 if ( $more_sharing_pane.find( '.share-google-plus-1' ).size() ) { 203 // The pane needs to stay open for the Google+ Button 204 return; 205 } 206 207 $more_sharing_pane.mouseleave( handler_item_leave ).mouseenter( handler_item_enter ); 208 $more_sharing_button.mouseleave( handler_original_leave ).mouseenter( handler_original_enter ); 209 } ); 210 211 // The following handlers take care of the mouseenter/mouseleave for the share button and the share area - if both are left then we close the share area 212 handler_item_leave = function() { 213 $more_sharing_button.data( 'hasitem', false ); 214 215 if ( $more_sharing_button.data( 'hasoriginal' ) === false ) { 216 var timer = setTimeout( close_it, 800 ); 217 $more_sharing_button.data( 'timer2', timer ); 218 } 219 }; 220 221 handler_item_enter = function() { 222 $more_sharing_button.data( 'hasitem', true ); 223 clearTimeout( $more_sharing_button.data( 'timer2' ) ); 224 }; 225 226 handler_original_leave = function() { 227 $more_sharing_button.data( 'hasoriginal', false ); 228 229 if ( $more_sharing_button.data( 'hasitem' ) === false ) { 230 var timer = setTimeout( close_it, 800 ); 231 $more_sharing_button.data( 'timer2', timer ); 232 } 233 }; 234 235 handler_original_enter = function() { 236 $more_sharing_button.data( 'hasoriginal', true ); 237 clearTimeout( $more_sharing_button.data( 'timer2' ) ); 238 }; 239 240 close_it = function() { 241 $more_sharing_pane.data( 'justSlid', true ); 242 $more_sharing_pane.slideUp( 200, function() { 243 setTimeout( function() { 244 $more_sharing_pane.data( 'justSlid', false ); 245 }, 300 ); 246 } ); 247 248 // Clear all hooks 249 $more_sharing_button.unbind( 'mouseleave', handler_original_leave ).unbind( 'mouseenter', handler_original_enter ); 250 $more_sharing_pane.unbind( 'mouseleave', handler_item_leave ).unbind( 'mouseenter', handler_item_leave ); 251 return false;
252 }; 253 }, 200 ); 254 255 // Remember the timer so we can detect it on the mouseout 256 $more_sharing_button.data( 'timer', timer ); 257 } 258 }, function() { 259 // Mouse out - remove any timer 260 $more_sharing_buttons.each( function() { 261 clearTimeout( $( this ).data( 'timer' ) ); 262 } ); 263 $more_sharing_buttons.data( 'timer', false ); 264 } ); 265 } 266 267 $( document ).click(function() { 268 269 // Click outside 270 // remove any timer 271 $more_sharing_buttons.each( function() { 272 clearTimeout( $( this ).data( 'timer' ) ); 273 } ); 274 $more_sharing_buttons.data( 'timer', false ); 275 276 // slide down forcibly 277 $( '.sharedaddy .inner' ).slideUp(); 278 279 }); 280 281 // Add click functionality 282 $( '.sharedaddy ul' ).each( function() { 283 284 if ( 'yep' === $( this ).data( 'has-click-events' ) ) { 285 return; 286 } 287 $( this ).data( 'has-click-events', 'yep' ); 288 289 var printUrl = function ( uniqueId, urlToPrint ) { 290 $( 'body:first' ).append( '<iframe style="position:fixed;top:100;left:100;height:1px;width:1px;border:none;" id="printFrame-' + uniqueId + '" name="printFrame-' + uniqueId + '" src="' + urlToPrint + '" onload="frames[\'printFrame-' + uniqueId + '\'].focus();frames[\'printFrame-' + uniqueId + '\'].print();"></iframe>' ); 291 }; 292 293 // Print button 294 $( this ).find( 'a.share-print' ).click( function() { 295 var ref = $( this ).attr( 'href' ), 296 do_print = function() { 297 if ( ref.indexOf( '#print' ) === -1 ) { 298 var uid = new Date().getTime(); 299 printUrl( uid , ref ); 300 } else { 301 print(); 302 } 303 }; 304 305 // Is the button in a dropdown? 306 if ( $( this ).parents( '.sharing-hidden' ).length > 0 ) { 307 $( this ).parents( '.inner' ).slideUp( 0, function() { 308 do_print(); 309 } ); 310 } else { 311 do_print(); 312 } 313 314 return false; 315 } ); 316 317 // Press This button 318 $( this ).find( 'a.share-press-this' ).click( function() { 319 var s = ''; 320 321 if ( window.getSelection ) { 322 s = window.getSelection(); 323 } else if( document.getSelection ) { 324 s = document.getSelection(); 325 } else if( document.selection ) { 326 s = document.selection.createRange().text; 327 } 328 329 if ( s ) { 330 $( this ).attr( 'href', $( this ).attr( 'href' ) + '&sel=' + encodeURI( s ) ); 331 } 332 333 if ( !window.open( $( this ).attr( 'href' ), 't', 'toolbar=0,resizable=1,scrollbars=1,status=1,width=720,height=570' ) ) { 334 document.location.href = $( this ).attr( 'href' ); 335 } 336 337 return false; 338 } ); 339 340 // Email button 341 $( 'a.share-email', this ).on( 'click', function() { 342 var url = $( this ).attr( 'href' ); 343 344 if ( $sharing_email.is( ':visible' ) ) { 345 $sharing_email.slideUp( 200 ); 346 } else { 347 $( '.sharedaddy .inner' ).slideUp(); 348 349 $( '#sharing_email .response' ).remove(); 350 $( '#sharing_email form' ).show(); 351 $( '#sharing_email form input[type=submit]' ).removeAttr( 'disabled' ); 352 $( '#sharing_email form a.sharing_cancel' ).show(); 353 354 // Reset reCATPCHA if exists. 355 if ( 'object' === typeof grecaptcha && 'function' === typeof grecaptcha.reset ) { 356 grecaptcha.reset(); 357 } 358 359 // Show dialog 360 $sharing_email.css( { 361 left: $( this ).offset().left + 'px', 362 top: $( this ).offset().top + $( this ).height() + 'px' 363 } ).slideDown( 200 ); 364 365 // Hook up other buttons 366 $( '#sharing_email a.sharing_cancel' ).unbind( 'click' ).click( function() { 367 $( '#sharing_email .errors' ).hide(); 368 $sharing_email.slideUp( 200 ); 369 $( '#sharing_background' ).fadeOut(); 370 return false; 371 } ); 372 373 // Submit validation 374 $( '#sharing_email input[type=submit]' ).unbind( 'click' ).click( function() { 375 var form = $( this ).parents( 'form' ); 376 377 // Disable buttons + enable loading icon 378 $( this ).prop( 'disabled', true ); 379 form.find( 'a.sharing_cancel' ).hide();
380 form.find( 'img.loading' ).show(); 381 382 $( '#sharing_email .errors' ).hide(); 383 $( '#sharing_email .error' ).removeClass( 'error' ); 384 385 if ( ! $( '#sharing_email input[name=source_email]' ).share_is_email() ) { 386 $( '#sharing_email input[name=source_email]' ).addClass( 'error' ); 387 } 388 389 if ( ! $( '#sharing_email input[name=target_email]' ).share_is_email() ) { 390 $( '#sharing_email input[name=target_email]' ).addClass( 'error' ); 391 } 392 393 if ( $( '#sharing_email .error' ).length === 0 ) { 394 // AJAX send the form 395 $.ajax( { 396 url: url, 397 type: 'POST', 398 data: form.serialize(), 399 success: function( response ) { 400 form.find( 'img.loading' ).hide(); 401 402 if ( response === '1' || response === '2' || response === '3' ) { 403 $( '#sharing_email .errors-' + response ).show(); 404 form.find( 'input[type=submit]' ).removeAttr( 'disabled' ); 405 form.find( 'a.sharing_cancel' ).show(); 406 407 if ( 'object' === typeof grecaptcha && 'function' === typeof grecaptcha.reset ) { 408 grecaptcha.reset(); 409 } 410 } 411 else { 412 $( '#sharing_email form' ).hide(); 413 $sharing_email.append( response ); 414 $( '#sharing_email a.sharing_cancel' ).click( function() { 415 $sharing_email.slideUp( 200 ); 416 $( '#sharing_background' ).fadeOut(); 417 return false; 418 } ); 419 } 420 } 421 } ); 422 423 return false; 424 } 425
426 form.find( 'img.loading' ).hide(); 427 form.find( 'input[type=submit]' ).removeAttr( 'disabled' ); 428 form.find( 'a.sharing_cancel' ).show(); 429 $( '#sharing_email .errors-1' ).show(); 430 431 return false; 432 } ); 433 } 434 435 return false; 436 } ); 437 } ); 438 439 $( 'li.share-email, li.share-custom a.sharing-anchor' ).addClass( 'share-service-visible' ); 440 } 441})( jQuery );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.