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