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.6.1 11.6.2 11.7 11.7.1 11.7.2 11.7.3 11.8 11.8.3 11.8.4 11.8.5 11.8.6 11.9 11.9.1 11.9.2 11.9.3 12.0 12.0.1 12.0.2 12.1 12.1.1 12.1.2 12.2 12.2.1 12.2.2 12.3 12.3.1 12.4 12.4.1 12.5 12.5.1 12.6 12.6.1 12.6.2 12.6.3 12.7 12.7.1 12.7.2 12.8 12.8.1 12.8.2 12.9 12.9.1 12.9.2 12.9.3 12.9.4 13.0 13.0.1 13.1 13.1.1 13.1.2 13.1.3 13.1.4 13.2 13.2.1 13.2.2 13.2.3 13.3 13.3.1 13.3.2 13.4 13.4.1 13.4.2 13.4.3 13.4.4 13.5 13.5.1 13.6 13.6.1 13.7 13.7.1 13.8 13.8.1 13.8.2 13.9 13.9.1 14.0 14.1 14.2 14.2.1 14.3 14.4 14.4.1 14.5 14.6 14.7 14.8 14.9 14.9.1 15.0 15.0.1 15.0.2 15.1 15.1.1 15.2 15.3 15.3.1 15.4 15.5 15.6 15.7 15.7-a.1 15.7-a.3 15.7-a.5 15.7-a.7 15.7-beta
jetpack / modules / sharedaddy / admin-sharing.js
jetpack / modules / sharedaddy Last commit date
images 2 months ago services 7 months ago admin-sharing-rtl.css 4 months ago admin-sharing-rtl.min.css 1 month ago admin-sharing.css 4 months ago admin-sharing.js 2 months ago admin-sharing.min.css 1 month ago amp-sharing.css 4 months ago recaptcha.php 1 month ago sharedaddy.php 7 months ago sharing-service.php 1 month ago sharing-sources.php 1 month ago sharing.css 4 months ago sharing.js 3 years ago sharing.php 2 months ago
admin-sharing.js
520 lines
1 /* global sharing_loading_icon */
2
3 ( function ( $ ) {
4 $( document ).ready( function () {
5 function enable_share_button() {
6 $( '.preview a.sharing-anchor' )
7 .unbind( 'mouseenter mouseenter' )
8 .hover(
9 function () {
10 if ( $( this ).data( 'hasappeared' ) !== true ) {
11 var item = $( '.sharing-hidden .inner' );
12 var original = $( this ).parents( 'li' );
13
14 // Create a timer to make the area appear if the mouse hovers for a period
15 var timer = setTimeout( function () {
16 $( item )
17 .css( {
18 left: $( original ).position().left + 'px',
19 top: $( original ).position().top + $( original ).height() + 3 + 'px',
20 } )
21 .slideDown( 200, function () {
22 // Mark the item as have being appeared by the hover
23 $( original )
24 .data( 'hasappeared', true )
25 .data( 'hasoriginal', true )
26 .data( 'hasitem', false );
27
28 // Remove all special handlers
29 $( item ).mouseleave( handler_item_leave ).mouseenter( handler_item_enter );
30 $( original )
31 .mouseleave( handler_original_leave )
32 .mouseenter( handler_original_enter );
33
34 // Add a special handler to quickly close the item
35 $( original ).click( close_it );
36 } );
37
38 // 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
39 var handler_item_leave = function () {
40 $( original ).data( 'hasitem', false );
41
42 if ( $( original ).data( 'hasoriginal' ) === false ) {
43 var timer2 = setTimeout( close_it, 800 );
44 $( original ).data( 'timer2', timer2 );
45 }
46 };
47
48 var handler_item_enter = function () {
49 $( original ).data( 'hasitem', true );
50 clearTimeout( $( original ).data( 'timer2' ) );
51 };
52
53 var handler_original_leave = function () {
54 $( original ).data( 'hasoriginal', false );
55
56 if ( $( original ).data( 'hasitem' ) === false ) {
57 var timer2 = setTimeout( close_it, 800 );
58 $( original ).data( 'timer2', timer2 );
59 }
60 };
61
62 var handler_original_enter = function () {
63 $( original ).data( 'hasoriginal', true );
64 clearTimeout( $( original ).data( 'timer2' ) );
65 };
66
67 var close_it = function () {
68 item.slideUp( 200 );
69
70 // Clear all hooks
71 $( original )
72 .unbind( 'mouseleave', handler_original_leave )
73 .unbind( 'mouseenter', handler_original_enter );
74 $( item )
75 .unbind( 'mouseleave', handler_item_leave )
76 .unbind( 'mouseenter', handler_item_leave );
77 $( original ).data( 'hasappeared', false );
78 $( original ).unbind( 'click', close_it );
79 return false;
80 };
81 }, 200 );
82
83 // Remember the timer so we can detect it on the mouseout
84 $( this ).data( 'timer', timer );
85 }
86 },
87 function () {
88 // Mouse out - remove any timer
89 clearTimeout( $( this ).data( 'timer' ) );
90 $( this ).data( 'timer', false );
91 }
92 );
93 }
94
95 function update_preview() {
96 var button_style = $( '#button_style' ).val();
97
98 // Toggle .sd-social-official class
99 var sharedaddy = $( '.sharedaddy' );
100 var oficialClass = 'sd-social-official';
101 if ( 'official' === button_style ) {
102 sharedaddy.addClass( oficialClass );
103 } else {
104 sharedaddy.removeClass( oficialClass );
105 }
106
107 // Clear the live preview
108 $( '#live-preview ul.preview li' ).remove();
109
110 // Add label
111 if (
112 $( '#save-enabled-shares input[name=visible]' ).val() ||
113 $( '#save-enabled-shares input[name=hidden]' ).val()
114 ) {
115 $( '#live-preview ul.preview' ).append(
116 $( '#live-preview ul.archive .sharing-label' ).clone()
117 );
118 }
119
120 // Re-insert all the enabled items
121 $( 'ul.services-enabled li' ).each( function () {
122 if ( $( this ).hasClass( 'service' ) ) {
123 var service = $( this ).attr( 'id' );
124 $( '#live-preview ul.preview' ).append(
125 $( '#live-preview ul.archive li.preview-' + service ).clone()
126 );
127 }
128 } );
129
130 // Add any hidden items
131 if ( $( '#save-enabled-shares input[name=hidden]' ).val() ) {
132 // Add share button
133 $( '#live-preview ul.preview' ).append(
134 $( '#live-preview ul.archive .share-more' ).parent().clone()
135 );
136
137 $( '.sharing-hidden ul li' ).remove();
138
139 // Add hidden items into the inner panel
140 $( 'ul.services-hidden li' ).each( function ( /*pos, item*/ ) {
141 if ( $( this ).hasClass( 'service' ) ) {
142 var service = $( this ).attr( 'id' );
143 $( '.sharing-hidden .inner ul' ).append(
144 $( '#live-preview ul.archive .preview-' + service ).clone()
145 );
146 }
147 } );
148
149 enable_share_button();
150 }
151
152 $( '#live-preview div.sharedaddy' ).removeClass( 'sd-social-icon' );
153 $( '#live-preview li.advanced' ).removeClass( 'no-icon' );
154
155 // Button style
156 if ( 'icon' === button_style ) {
157 $( '#live-preview ul.preview div span, .sharing-hidden .inner ul div span' )
158 .html( ' ' )
159 .parent()
160 .addClass( 'no-text' );
161 $( '#live-preview div.sharedaddy' ).addClass( 'sd-social-icon' );
162 } else if ( 'official' === button_style ) {
163 $( '#live-preview ul.preview .advanced, .sharing-hidden .inner ul .advanced' ).each(
164 function ( /*i*/ ) {
165 if (
166 ! $( this ).hasClass( 'preview-press-this' ) &&
167 ! $( this ).hasClass( 'preview-email' ) &&
168 ! $( this ).hasClass( 'preview-mastodon' ) &&
169 ! $( this ).hasClass( 'preview-nextdoor' ) &&
170 ! $( this ).hasClass( 'preview-bluesky' ) &&
171 ! $( this ).hasClass( 'preview-print' ) &&
172 ! $( this ).hasClass( 'preview-reddit' ) &&
173 ! $( this ).hasClass( 'preview-telegram' ) &&
174 ! $( this ).hasClass( 'preview-threads' ) &&
175 ! $( this ).hasClass( 'preview-jetpack-whatsapp' ) &&
176 ! $( this ).hasClass( 'share-custom' ) &&
177 ! $( this ).hasClass( 'share-deprecated' )
178 ) {
179 $( this )
180 .find( '.option a span' )
181 .html( '' )
182 .parent()
183 .removeClass( 'sd-button' )
184 .parent()
185 .attr( 'class', 'option option-smart-on' );
186 }
187 }
188 );
189 } else if ( 'text' === button_style ) {
190 $( '#live-preview li.advanced' ).addClass( 'no-icon' );
191 }
192 }
193
194 window.sharing_option_changed = function () {
195 var item = this;
196
197 // Loading icon
198 $( this )
199 .parents( 'li:first' )
200 .css( 'backgroundImage', 'url("' + sharing_loading_icon + '")' );
201
202 // Save
203 $( this )
204 .parents( 'form' )
205 .ajaxSubmit( function ( response ) {
206 if ( response.indexOf( '<!---' ) >= 0 ) {
207 var button = response.substring( 0, response.indexOf( '<!--->' ) );
208 var preview = response.substring( response.indexOf( '<!--->' ) + 6 );
209
210 if ( $( item ).is( ':submit' ) === true ) {
211 // Update the DOM using a bit of cut/paste technology
212
213 $( item ).parents( 'li:first' ).replaceWith( button );
214 }
215
216 $(
217 '#live-preview ul.archive li.preview-' +
218 $( item ).parents( 'form' ).find( 'input[name=service]' ).val()
219 ).replaceWith( preview );
220 }
221
222 // Update preview
223 update_preview();
224
225 // Restore the icon
226 $( item ).parents( 'li:first' ).removeAttr( 'style' );
227 } );
228
229 if ( $( item ).is( ':submit' ) === true ) {
230 return false;
231 }
232 return true;
233 };
234
235 function showExtraOptions( service ) {
236 jQuery( '.' + service + '-extra-options' )
237 .css( { backgroundColor: '#ffffcc' } )
238 .fadeIn();
239 }
240
241 function hideExtraOptions( service ) {
242 jQuery( '.' + service + '-extra-options' ).fadeOut( 'slow' );
243 }
244
245 function save_services() {
246 $( '#enabled-services h3 .spinner' ).addClass( 'is-active' );
247
248 // Toggle various dividers/help texts
249 if ( $( '#enabled-services ul.services-enabled li.service' ).length > 0 ) {
250 $( '#drag-instructions' ).hide();
251 } else {
252 $( '#drag-instructions' ).show();
253 }
254
255 if ( $( '#enabled-services li.service' ).length > 0 ) {
256 $( '#live-preview .services h2' ).hide();
257 } else {
258 $( '#live-preview .services h2' ).show();
259 }
260
261 // Gather the modules
262 var visible = [],
263 hidden = [];
264
265 $( 'ul.services-enabled li' ).each( function () {
266 if ( $( this ).hasClass( 'service' ) ) {
267 // Ready for saving
268 visible[ visible.length ] = $( this ).attr( 'id' );
269 showExtraOptions( $( this ).attr( 'id' ) );
270 }
271 } );
272
273 $( 'ul.services-available li' ).each( function () {
274 if ( $( this ).hasClass( 'service' ) ) {
275 hideExtraOptions( $( this ).attr( 'id' ) );
276 }
277 } );
278
279 $( 'ul.services-hidden li' ).each( function () {
280 if ( $( this ).hasClass( 'service' ) ) {
281 // Ready for saving
282 hidden[ hidden.length ] = $( this ).attr( 'id' );
283 showExtraOptions( $( this ).attr( 'id' ) );
284 }
285 } );
286
287 // Set the hidden element values
288 $( '#save-enabled-shares input[name=visible]' ).val( visible.join( ',' ) );
289 $( '#save-enabled-shares input[name=hidden]' ).val( hidden.join( ',' ) );
290
291 update_preview();
292
293 // Save it
294 $( '#save-enabled-shares' ).ajaxSubmit( function () {
295 $( '#enabled-services h3 .spinner' ).removeClass( 'is-active' );
296 } );
297 }
298
299 $( '#enabled-services .services ul' ).sortable( {
300 receive: function ( /*event, ui*/ ) {
301 save_services();
302 },
303 stop: function () {
304 save_services();
305 $( 'li.service' ).enableSelection(); // Fixes a problem with Chrome
306 },
307 over: function ( /*event, ui*/ ) {
308 $( this ).find( 'ul' ).addClass( 'dropping' );
309
310 // Ensure the 'end-fix' is at the end
311 $( '#enabled-services li.end-fix' ).remove();
312 $( '#enabled-services ul' ).append( '<li class="end-fix"></li>' );
313 },
314 out: function ( /*event, ui*/ ) {
315 $( this ).find( 'ul' ).removeClass( 'dropping' );
316
317 // Ensure the 'end-fix' is at the end
318 $( '#enabled-services li.end-fix' ).remove();
319 $( '#enabled-services ul' ).append( '<li class="end-fix"></li>' );
320 },
321 helper: function ( event, ui ) {
322 ui.find( '.advanced-form' ).hide();
323
324 return ui.clone();
325 },
326 start: function ( /*event, ui*/ ) {
327 // Make sure that the advanced section is closed
328 $( '.advanced-form' ).hide();
329 $( 'li.service' ).disableSelection(); // Fixes a problem with Chrome
330 },
331 placeholder: 'dropzone',
332 opacity: 0.8,
333 delay: 150,
334 forcePlaceholderSize: true,
335 items: 'li',
336 connectWith: '#available-services ul, #enabled-services .services ul',
337 cancel: '.advanced-form',
338 } );
339
340 $( '#available-services ul' ).sortable( {
341 opacity: 0.8,
342 delay: 150,
343 cursor: 'move',
344 connectWith: '#enabled-services .services ul',
345 placeholder: 'dropzone',
346 forcePlaceholderSize: true,
347 start: function () {
348 $( '.advanced-form' ).hide();
349 },
350 } );
351
352 // Accessibility keyboard shortcurts
353 $( '.service' ).on( 'keydown', function ( e ) {
354 // Reposition if one of the directional keys is pressed
355 switch ( e.keyCode ) {
356 case 13:
357 keyboardDragDrop( $( this ) );
358 break; // Enter
359 case 32:
360 keyboardDragDrop( $( this ) );
361 break; // Space
362 case 37:
363 keyboardChangeOrder( $( this ), 'left' );
364 break; // Left
365 case 39:
366 keyboardChangeOrder( $( this ), 'right' );
367 break; // Right
368 default:
369 return true; // Exit and bubble
370 }
371
372 e.preventDefault();
373 } );
374
375 function keyboardChangeOrder( $this, dir ) {
376 var thisParent = $this.parent(),
377 thisParentsChildren = thisParent.find( 'li' ),
378 thisPosition = thisParentsChildren.index( $this ) + 1,
379 totalChildren = thisParentsChildren.length - 1,
380 thisService;
381
382 // No need to be able to sort order for the "Available Services" section
383 if ( thisParent.hasClass( 'services-available' ) ) {
384 return;
385 }
386
387 if ( 'left' === dir ) {
388 if ( 1 === thisPosition ) {
389 return;
390 }
391
392 // Find service to left
393 var prevSibling = $this.prev();
394
395 // Detach this service from DOM
396 thisService = $this.detach();
397
398 // Move it to the appropriate area and add focus back to service
399 prevSibling.before( thisService );
400
401 // Add focus
402 prevSibling.prev().focus();
403 }
404
405 if ( 'right' === dir ) {
406 if ( thisPosition === totalChildren ) {
407 return;
408 }
409
410 // Find service to left
411 var nextSibling = $this.next();
412
413 // Detach this service from DOM
414 thisService = $this.detach();
415
416 // Move it to the appropriate area and add focus back to service
417 nextSibling.after( thisService );
418
419 // Add focus
420 nextSibling.next().focus();
421 }
422
423 //Save changes
424 save_services();
425 }
426
427 function keyboardDragDrop( $this ) {
428 var dropzone,
429 thisParent = $this.parent();
430
431 // Rotate through 3 available dropzones
432 if ( thisParent.hasClass( 'services-available' ) ) {
433 dropzone = 'services-enabled';
434 } else if ( thisParent.hasClass( 'services-enabled' ) ) {
435 dropzone = 'services-hidden';
436 } else {
437 dropzone = 'services-available';
438 }
439
440 // Detach this service from DOM
441 var thisService = $this.detach();
442
443 // Move it to the appropriate area and add focus back to service
444 $( '.' + dropzone )
445 .prepend( thisService )
446 .find( 'li:first-child' )
447 .focus();
448
449 //Save changes
450 save_services();
451 }
452
453 // Live preview 'hidden' button
454 $( '.preview-hidden a' ).click( function () {
455 $( this ).parent().find( '.preview' ).toggle();
456 return false;
457 } );
458
459 // Add service
460 $( '#new-service form' ).ajaxForm( {
461 beforeSubmit: function () {
462 $( '#new-service-form .error' ).hide();
463 $( '#new-service-form .spinner' ).addClass( 'is-active' );
464 $( '#new-service-form input[type="submit"]' ).prop( 'disabled', true );
465 },
466 success: function ( response ) {
467 $( '#new-service-form .spinner' ).removeClass( 'is-active' );
468
469 if ( '' + response === '1' ) {
470 $( '#new-service-form .inerror' ).removeClass( 'inerror' ).addClass( 'error' );
471 $( '#new-service-form .error' ).show();
472 $( '#new-service-form input[type="submit"]' ).prop( 'disabled', false );
473 } else {
474 document.location.reload();
475 }
476 },
477 } );
478
479 function init_handlers() {
480 $( '#services-config a.remove' )
481 .unbind( 'click' )
482 .click( function () {
483 var form = $( this ).parent().next();
484
485 // Loading icon
486 $( this )
487 .parents( 'li:first' )
488 .css( 'backgroundImage', 'url("' + sharing_loading_icon + '")' );
489
490 // Save
491 form.ajaxSubmit( function ( /*response*/ ) {
492 // Remove the item
493 form.parents( 'li:first' ).fadeOut( function () {
494 $( this ).remove();
495
496 // Update preview
497 update_preview();
498 } );
499 } );
500
501 return false;
502 } );
503 }
504
505 $( '#button_style' )
506 .change( function () {
507 update_preview();
508 return true;
509 } )
510 .change();
511
512 $( 'input[name=sharing_label]' ).blur( function () {
513 $( '#live-preview h3.sd-title' ).text( $( '<div/>' ).text( $( this ).val() ).html() );
514 } );
515
516 init_handlers();
517 enable_share_button();
518 } );
519 } )( jQuery );
520