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 |