PageSourceSearch

https://ladybrillemag.com/wp-content/plugins/jetpack/modules/sharedaddy/sharing.js

js ladybrillemag.com collected 2026-10-02 13:39:38 UTC 15,310 bytes, 446 lines download raw bytes

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