diff --git src/wp-admin/js/common.js src/wp-admin/js/common.js
index d8748f53af..7c92850a3a 100644
|
|
|
|
| 1 | 1 | /* global setUserSetting, ajaxurl, commonL10n, alert, confirm, pagenow */ |
| 2 | 2 | var showNotice, adminMenu, columns, validateForm, screenMeta; |
| | 3 | |
| | 4 | /** |
| | 5 | * @summary Adds common WordPress functionality to the window. |
| | 6 | * |
| | 7 | * @param {jQuery} $ jQuery object. |
| | 8 | * @param {Object} window The window object. |
| | 9 | * @param {mixed} undefined Unused. |
| | 10 | */ |
| 3 | 11 | ( function( $, window, undefined ) { |
| 4 | 12 | var $document = $( document ), |
| 5 | 13 | $window = $( window ), |
| 6 | 14 | $body = $( document.body ); |
| 7 | 15 | |
| 8 | | // Removed in 3.3. |
| 9 | | // (perhaps) needed for back-compat |
| | 16 | /** |
| | 17 | * @summary Removed in 3.3.0, needed for back-compatibility. |
| | 18 | * |
| | 19 | * @since 2.7.0 |
| | 20 | * @deprecated 3.3.0 |
| | 21 | */ |
| 10 | 22 | adminMenu = { |
| 11 | 23 | init : function() {}, |
| 12 | 24 | fold : function() {}, |
| … |
… |
adminMenu = { |
| 15 | 27 | favorites : function() {} |
| 16 | 28 | }; |
| 17 | 29 | |
| 18 | | // show/hide/save table columns |
| | 30 | // Show/hide/save table columns. |
| 19 | 31 | columns = { |
| | 32 | |
| | 33 | /** |
| | 34 | * @summary Initializes the column toggles in the screen options. |
| | 35 | * |
| | 36 | * Binds an onClick event to the checkboxes to show or hide the table columns |
| | 37 | * based on their toggled state. And persists the toggled state. |
| | 38 | * |
| | 39 | * @since 2.7.0 |
| | 40 | * |
| | 41 | * @returns {void} |
| | 42 | */ |
| 20 | 43 | init : function() { |
| 21 | 44 | var that = this; |
| 22 | 45 | $('.hide-column-tog', '#adv-settings').click( function() { |
| … |
… |
columns = { |
| 30 | 53 | }); |
| 31 | 54 | }, |
| 32 | 55 | |
| | 56 | /** |
| | 57 | * @summary Saves the toggled state for the columns. |
| | 58 | * |
| | 59 | * Saves whether the columns should be shown or hidden on a page. |
| | 60 | * |
| | 61 | * @since 3.0.0 |
| | 62 | * |
| | 63 | * @returns {void} |
| | 64 | */ |
| 33 | 65 | saveManageColumnsState : function() { |
| 34 | 66 | var hidden = this.hidden(); |
| 35 | 67 | $.post(ajaxurl, { |
| … |
… |
columns = { |
| 40 | 72 | }); |
| 41 | 73 | }, |
| 42 | 74 | |
| | 75 | /** |
| | 76 | * @summary Makes a column visible and adjusts the column span for the table. |
| | 77 | * |
| | 78 | * @since 3.0.0 |
| | 79 | * @param {string} column The column name. |
| | 80 | * |
| | 81 | * @returns {void} |
| | 82 | */ |
| 43 | 83 | checked : function(column) { |
| 44 | 84 | $('.column-' + column).removeClass( 'hidden' ); |
| 45 | 85 | this.colSpanChange(+1); |
| 46 | 86 | }, |
| 47 | 87 | |
| | 88 | /** |
| | 89 | * @summary Hides a column and adjusts the column span for the table. |
| | 90 | * |
| | 91 | * @since 3.0.0 |
| | 92 | * @param {string} column The column name. |
| | 93 | * |
| | 94 | * @returns {void} |
| | 95 | */ |
| 48 | 96 | unchecked : function(column) { |
| 49 | 97 | $('.column-' + column).addClass( 'hidden' ); |
| 50 | 98 | this.colSpanChange(-1); |
| 51 | 99 | }, |
| 52 | 100 | |
| | 101 | /** |
| | 102 | * @summary Get all hidden columns. |
| | 103 | * |
| | 104 | * @since 3.0.0 |
| | 105 | * |
| | 106 | * @returns {string} The hidden column names separated by a comma. |
| | 107 | */ |
| 53 | 108 | hidden : function() { |
| 54 | 109 | return $( '.manage-column[id]' ).filter( ':hidden' ).map(function() { |
| 55 | 110 | return this.id; |
| 56 | 111 | }).get().join( ',' ); |
| 57 | 112 | }, |
| 58 | 113 | |
| | 114 | /** |
| | 115 | * @summary Gets the checked column toggles from the screen options. |
| | 116 | * |
| | 117 | * @since 3.0.0 |
| | 118 | * |
| | 119 | * @returns {string} String containing the checked column names. |
| | 120 | */ |
| 59 | 121 | useCheckboxesForHidden : function() { |
| 60 | 122 | this.hidden = function(){ |
| 61 | 123 | return $('.hide-column-tog').not(':checked').map(function() { |
| … |
… |
columns = { |
| 65 | 127 | }; |
| 66 | 128 | }, |
| 67 | 129 | |
| | 130 | /** |
| | 131 | * @summary Adjusts the column span for the table. |
| | 132 | * |
| | 133 | * @since 3.1.0 |
| | 134 | * |
| | 135 | * @param {int} diff The modifier for the column span. |
| | 136 | */ |
| 68 | 137 | colSpanChange : function(diff) { |
| 69 | 138 | var $t = $('table').find('.colspanchange'), n; |
| 70 | 139 | if ( !$t.length ) |
| … |
… |
columns = { |
| 76 | 145 | |
| 77 | 146 | $document.ready(function(){columns.init();}); |
| 78 | 147 | |
| | 148 | /** |
| | 149 | * @summary Validates that the required form fields are not empty. |
| | 150 | * |
| | 151 | * @since 2.9.0 |
| | 152 | * |
| | 153 | * @param {jQuery} form The form to validate. |
| | 154 | * |
| | 155 | * @returns {boolean} Returns true if all required fields are not an empty string. |
| | 156 | */ |
| 79 | 157 | validateForm = function( form ) { |
| 80 | 158 | return !$( form ) |
| 81 | 159 | .find( '.form-required' ) |
| … |
… |
validateForm = function( form ) { |
| 87 | 165 | }; |
| 88 | 166 | |
| 89 | 167 | // stub for doing better warnings |
| | 168 | /** |
| | 169 | * @summary Shows message pop-up notice or confirmation message. |
| | 170 | * |
| | 171 | * @since 2.7.0 |
| | 172 | * |
| | 173 | * @type {{warn: showNotice.warn, note: showNotice.note}} |
| | 174 | * |
| | 175 | * @returns {void} |
| | 176 | */ |
| 90 | 177 | showNotice = { |
| | 178 | |
| | 179 | /** |
| | 180 | * @summary Shows a delete confirmation pop-up message. |
| | 181 | * |
| | 182 | * @since 2.7.0 |
| | 183 | * |
| | 184 | * @returns {boolean} Returns true if the message is confirmed. |
| | 185 | */ |
| 91 | 186 | warn : function() { |
| 92 | 187 | var msg = commonL10n.warnDelete || ''; |
| 93 | 188 | if ( confirm(msg) ) { |
| … |
… |
showNotice = { |
| 97 | 192 | return false; |
| 98 | 193 | }, |
| 99 | 194 | |
| | 195 | /** |
| | 196 | * @summary Shows an alert message. |
| | 197 | * |
| | 198 | * @since 2.7.0 |
| | 199 | * |
| | 200 | * @param text The text to display in the message. |
| | 201 | */ |
| 100 | 202 | note : function(text) { |
| 101 | 203 | alert(text); |
| 102 | 204 | } |
| 103 | 205 | }; |
| 104 | 206 | |
| | 207 | /** |
| | 208 | * @summary Represents the functions for the meta screen options panel. |
| | 209 | * |
| | 210 | * @since 3.2.0 |
| | 211 | * |
| | 212 | * @type {{element: null, toggles: null, page: null, init: screenMeta.init, |
| | 213 | * toggleEvent: screenMeta.toggleEvent, open: screenMeta.open, |
| | 214 | * close: screenMeta.close}} |
| | 215 | * |
| | 216 | * @returns {void} |
| | 217 | */ |
| 105 | 218 | screenMeta = { |
| 106 | 219 | element: null, // #screen-meta |
| 107 | 220 | toggles: null, // .screen-meta-toggle |
| 108 | 221 | page: null, // #wpcontent |
| 109 | 222 | |
| | 223 | /** |
| | 224 | * @summary Initializes the screen meta options panel. |
| | 225 | * |
| | 226 | * @since 3.2.0 |
| | 227 | * |
| | 228 | * @returns {void} |
| | 229 | */ |
| 110 | 230 | init: function() { |
| 111 | 231 | this.element = $('#screen-meta'); |
| 112 | 232 | this.toggles = $( '#screen-meta-links' ).find( '.show-settings' ); |
| … |
… |
screenMeta = { |
| 115 | 235 | this.toggles.click( this.toggleEvent ); |
| 116 | 236 | }, |
| 117 | 237 | |
| | 238 | /** |
| | 239 | * @summary Toggles the screen meta options panel. |
| | 240 | * |
| | 241 | * @since 3.2.0 |
| | 242 | * |
| | 243 | * @returns {void} |
| | 244 | */ |
| 118 | 245 | toggleEvent: function() { |
| 119 | 246 | var panel = $( '#' + $( this ).attr( 'aria-controls' ) ); |
| 120 | 247 | |
| … |
… |
screenMeta = { |
| 127 | 254 | screenMeta.open( panel, $(this) ); |
| 128 | 255 | }, |
| 129 | 256 | |
| | 257 | /** |
| | 258 | * @summary Opens the screen meta options panel. |
| | 259 | * |
| | 260 | * @since 3.2.0 |
| | 261 | * |
| | 262 | * @param {jQuery} panel The screen meta options panel div. |
| | 263 | * @param {jQuery} button The toggle button. |
| | 264 | * |
| | 265 | * @returns {void} |
| | 266 | */ |
| 130 | 267 | open: function( panel, button ) { |
| 131 | 268 | |
| 132 | 269 | $( '#screen-meta-links' ).find( '.screen-meta-toggle' ).not( button.parent() ).css( 'visibility', 'hidden' ); |
| 133 | 270 | |
| 134 | 271 | panel.parent().show(); |
| | 272 | |
| | 273 | /** |
| | 274 | * @summary Sets the focus to the meta options panel and adds the necessary CSS classes. |
| | 275 | * |
| | 276 | * @since 3.2.0 |
| | 277 | * |
| | 278 | * @returns {void} |
| | 279 | */ |
| 135 | 280 | panel.slideDown( 'fast', function() { |
| 136 | 281 | panel.focus(); |
| 137 | 282 | button.addClass( 'screen-meta-active' ).attr( 'aria-expanded', true ); |
| … |
… |
screenMeta = { |
| 140 | 285 | $document.trigger( 'screen:options:open' ); |
| 141 | 286 | }, |
| 142 | 287 | |
| | 288 | /** |
| | 289 | * @summary Closes the screen meta options panel. |
| | 290 | * |
| | 291 | * @since 3.2.0 |
| | 292 | * |
| | 293 | * @param {jQuery} panel The screen meta options panel div. |
| | 294 | * @param {jQuery} button The toggle button. |
| | 295 | * |
| | 296 | * @returns {void} |
| | 297 | */ |
| 143 | 298 | close: function( panel, button ) { |
| | 299 | /** |
| | 300 | * @summary Hides the screen meta options panel. |
| | 301 | * |
| | 302 | * @since 3.2.0 |
| | 303 | * |
| | 304 | * @returns {void} |
| | 305 | */ |
| 144 | 306 | panel.slideUp( 'fast', function() { |
| 145 | 307 | button.removeClass( 'screen-meta-active' ).attr( 'aria-expanded', false ); |
| 146 | 308 | $('.screen-meta-toggle').css('visibility', ''); |
| … |
… |
screenMeta = { |
| 152 | 314 | }; |
| 153 | 315 | |
| 154 | 316 | /** |
| 155 | | * Help tabs. |
| | 317 | * @summary Initializes the help tabs in the help panel. |
| | 318 | * |
| | 319 | * @param {Event} e The event object. |
| | 320 | * |
| | 321 | * @returns {void} |
| 156 | 322 | */ |
| 157 | 323 | $('.contextual-help-tabs').delegate('a', 'click', function(e) { |
| 158 | 324 | var link = $(this), |
| … |
… |
$('.contextual-help-tabs').delegate('a', 'click', function(e) { |
| 178 | 344 | /** |
| 179 | 345 | * Update custom permalink structure via buttons. |
| 180 | 346 | */ |
| 181 | | |
| 182 | 347 | var permalinkStructureFocused = false, |
| 183 | 348 | $permalinkStructure = $( '#permalink_structure' ), |
| 184 | 349 | $permalinkStructureInputs = $( '.permalink-structure input:radio' ), |
| … |
… |
$document.ready( function() { |
| 329 | 494 | }, |
| 330 | 495 | $headerEnd = $( '.wp-header-end' ); |
| 331 | 496 | |
| 332 | | |
| 333 | | // when the menu is folded, make the fly-out submenu header clickable |
| | 497 | /** |
| | 498 | * @summary Makes the fly-out submenu header clickable, when the menu is folded. |
| | 499 | * |
| | 500 | * @param {Event} e The event object. |
| | 501 | * |
| | 502 | * @returns {void} |
| | 503 | */ |
| 334 | 504 | $adminmenu.on('click.wp-submenu-head', '.wp-submenu-head', function(e){ |
| 335 | 505 | $(e.target).parent().siblings('a').get(0).click(); |
| 336 | 506 | }); |
| 337 | 507 | |
| | 508 | /** |
| | 509 | * @summary Collapses the admin menu. |
| | 510 | * |
| | 511 | * @returns {void} |
| | 512 | */ |
| 338 | 513 | $( '#collapse-button' ).on( 'click.collapse-menu', function() { |
| 339 | 514 | var viewportWidth = getViewportWidth() || 961; |
| 340 | 515 | |
| … |
… |
$document.ready( function() { |
| 367 | 542 | $document.trigger( 'wp-collapse-menu', { state: menuState } ); |
| 368 | 543 | }); |
| 369 | 544 | |
| 370 | | // Handle the `aria-haspopup` attribute on the current menu item when it has a sub-menu. |
| | 545 | /** |
| | 546 | * @summary Handles the `aria-haspopup` attribute on the current menu item when it has a submenu. |
| | 547 | * |
| | 548 | * @since 4.4.0 |
| | 549 | * |
| | 550 | * @returns {void} |
| | 551 | */ |
| 371 | 552 | function currentMenuItemHasPopup() { |
| 372 | 553 | var $current = $( 'a.wp-has-current-submenu' ); |
| 373 | 554 | |
| … |
… |
$document.ready( function() { |
| 383 | 564 | $document.on( 'wp-menu-state-set wp-collapse-menu wp-responsive-activate wp-responsive-deactivate', currentMenuItemHasPopup ); |
| 384 | 565 | |
| 385 | 566 | /** |
| 386 | | * Ensure an admin submenu is within the visual viewport. |
| | 567 | * @summary Ensures an admin submenu is within the visual viewport. |
| 387 | 568 | * |
| 388 | 569 | * @since 4.1.0 |
| 389 | 570 | * |
| 390 | 571 | * @param {jQuery} $menuItem The parent menu item containing the submenu. |
| | 572 | * |
| | 573 | * @returns {void} |
| 391 | 574 | */ |
| 392 | 575 | function adjustSubmenu( $menuItem ) { |
| 393 | 576 | var bottomOffset, pageHeight, adjustment, theFold, menutop, wintop, maxtop, |
| … |
… |
$document.ready( function() { |
| 421 | 604 | // iOS Safari works with touchstart, the rest work with click |
| 422 | 605 | mobileEvent = isIOS ? 'touchstart' : 'click'; |
| 423 | 606 | |
| 424 | | // close any open submenus when touch/click is not on the menu |
| | 607 | /** |
| | 608 | * @summary Closes any open submenus when touch/click is not on the menu. |
| | 609 | * |
| | 610 | * @param {Event} e The event object. |
| | 611 | * |
| | 612 | * @returns {void} |
| | 613 | */ |
| 425 | 614 | $body.on( mobileEvent+'.wp-mobile-hover', function(e) { |
| 426 | 615 | if ( $adminmenu.data('wp-responsive') ) { |
| 427 | 616 | return; |
| … |
… |
$document.ready( function() { |
| 432 | 621 | } |
| 433 | 622 | }); |
| 434 | 623 | |
| | 624 | /** |
| | 625 | * @summary Handles the opening or closing the submenu based on the mobile click|touch event. |
| | 626 | * |
| | 627 | * @param {Event} event The event object. |
| | 628 | * |
| | 629 | * @returns {void} |
| | 630 | */ |
| 435 | 631 | $adminmenu.find( 'a.wp-has-submenu' ).on( mobileEvent + '.wp-mobile-hover', function( event ) { |
| 436 | 632 | var $menuItem = $(this).parent(); |
| 437 | 633 | |
| … |
… |
$document.ready( function() { |
| 453 | 649 | |
| 454 | 650 | if ( ! isIOS && ! isAndroid ) { |
| 455 | 651 | $adminmenu.find( 'li.wp-has-submenu' ).hoverIntent({ |
| | 652 | |
| | 653 | /** |
| | 654 | * @summary Opens the submenu when hovered over the menu item for desktops. |
| | 655 | * |
| | 656 | * @returns {void} |
| | 657 | */ |
| 456 | 658 | over: function() { |
| 457 | 659 | var $menuItem = $( this ), |
| 458 | 660 | $submenu = $menuItem.find( '.wp-submenu' ), |
| … |
… |
$document.ready( function() { |
| 471 | 673 | $adminmenu.find( 'li.opensub' ).removeClass( 'opensub' ); |
| 472 | 674 | $menuItem.addClass( 'opensub' ); |
| 473 | 675 | }, |
| | 676 | |
| | 677 | /** |
| | 678 | * @summary Closes the submenu when no longer hovering the menu item. |
| | 679 | * |
| | 680 | * @returns {void} |
| | 681 | */ |
| 474 | 682 | out: function(){ |
| 475 | 683 | if ( $adminmenu.data( 'wp-responsive' ) ) { |
| 476 | 684 | // The menu is in responsive mode, bail |
| … |
… |
$document.ready( function() { |
| 484 | 692 | interval: 90 |
| 485 | 693 | }); |
| 486 | 694 | |
| | 695 | /** |
| | 696 | * @summary Opens the submenu on when focused on the menu item. |
| | 697 | * |
| | 698 | * @param {Event} event The event object. |
| | 699 | * |
| | 700 | * @returns {void} |
| | 701 | */ |
| 487 | 702 | $adminmenu.on( 'focus.adminmenu', '.wp-submenu a', function( event ) { |
| 488 | 703 | if ( $adminmenu.data( 'wp-responsive' ) ) { |
| 489 | 704 | // The menu is in responsive mode, bail |
| … |
… |
$document.ready( function() { |
| 491 | 706 | } |
| 492 | 707 | |
| 493 | 708 | $( event.target ).closest( 'li.menu-top' ).addClass( 'opensub' ); |
| | 709 | |
| | 710 | /** |
| | 711 | * @summary Closes the submenu on blur from the menu item. |
| | 712 | * |
| | 713 | * @param {Event} event The event object. |
| | 714 | * |
| | 715 | * @returns {void} |
| | 716 | */ |
| 494 | 717 | }).on( 'blur.adminmenu', '.wp-submenu a', function( event ) { |
| 495 | 718 | if ( $adminmenu.data( 'wp-responsive' ) ) { |
| 496 | 719 | return; |
| 497 | 720 | } |
| 498 | 721 | |
| 499 | 722 | $( event.target ).closest( 'li.menu-top' ).removeClass( 'opensub' ); |
| | 723 | |
| | 724 | /** |
| | 725 | * @summary Adjusts the size for the submenu. |
| | 726 | * |
| | 727 | * @returns {void} |
| | 728 | */ |
| 500 | 729 | }).find( 'li.wp-has-submenu.wp-not-current-submenu' ).on( 'focusin.adminmenu', function() { |
| 501 | 730 | adjustSubmenu( $( this ) ); |
| 502 | 731 | }); |
| … |
… |
$document.ready( function() { |
| 513 | 742 | } |
| 514 | 743 | $( 'div.updated, div.error, div.notice' ).not( '.inline, .below-h2' ).insertAfter( $headerEnd ); |
| 515 | 744 | |
| 516 | | // Make notices dismissible |
| | 745 | /** |
| | 746 | * @summary Make notices dismissible. |
| | 747 | * |
| | 748 | * @since 4.4.0 |
| | 749 | * |
| | 750 | * @returns {void} |
| | 751 | */ |
| 517 | 752 | function makeNoticesDismissible() { |
| 518 | 753 | $( '.notice.is-dismissible' ).each( function() { |
| 519 | 754 | var $el = $( this ), |
| … |
… |
$document.ready( function() { |
| 540 | 775 | // Init screen meta |
| 541 | 776 | screenMeta.init(); |
| 542 | 777 | |
| 543 | | // This event needs to be delegated. Ticket #37973. |
| | 778 | /** |
| | 779 | * @summary Checks a checkbox. |
| | 780 | * |
| | 781 | * This event needs to be delegated. Ticket #37973. |
| | 782 | * |
| | 783 | * @returns {boolean} Returns whether a checkbox is checked or not. |
| | 784 | */ |
| 544 | 785 | $body.on( 'click', 'tbody > tr > .check-column :checkbox', function( event ) { |
| 545 | 786 | // Shift click to select a range of checkboxes. |
| 546 | 787 | if ( 'undefined' == event.shiftKey ) { return true; } |
| … |
… |
$document.ready( function() { |
| 564 | 805 | |
| 565 | 806 | // Toggle the "Select all" checkboxes depending if the other ones are all checked or not. |
| 566 | 807 | var unchecked = $(this).closest('tbody').find(':checkbox').filter(':visible:enabled').not(':checked'); |
| | 808 | |
| | 809 | /** |
| | 810 | * @summary Determines if all checkboxes are checked. |
| | 811 | * |
| | 812 | * @returns {boolean} Returns true if there are no unchecked checkboxes. |
| | 813 | */ |
| 567 | 814 | $(this).closest('table').children('thead, tfoot').find(':checkbox').prop('checked', function() { |
| 568 | 815 | return ( 0 === unchecked.length ); |
| 569 | 816 | }); |
| … |
… |
$document.ready( function() { |
| 571 | 818 | return true; |
| 572 | 819 | }); |
| 573 | 820 | |
| 574 | | // This event needs to be delegated. Ticket #37973. |
| | 821 | /** |
| | 822 | * @summary Controls all the toggles on bulk toggle change. |
| | 823 | * |
| | 824 | * When the bulk checkbox is changed, all the checkboxes in the tables are changed accordingly. |
| | 825 | * When the shift-button is pressed while changing the bulk checkbox the checkboxes in the table are inverted. |
| | 826 | * |
| | 827 | * This event needs to be delegated. Ticket #37973. |
| | 828 | * |
| | 829 | * @param {Event} event The event object. |
| | 830 | * |
| | 831 | * @returns {boolean} |
| | 832 | */ |
| 575 | 833 | $body.on( 'click.wp-toggle-checkboxes', 'thead .check-column :checkbox, tfoot .check-column :checkbox', function( event ) { |
| 576 | 834 | var $this = $(this), |
| 577 | 835 | $table = $this.closest( 'table' ), |
| … |
… |
$document.ready( function() { |
| 580 | 838 | |
| 581 | 839 | $table.children( 'tbody' ).filter(':visible') |
| 582 | 840 | .children().children('.check-column').find(':checkbox') |
| | 841 | /** |
| | 842 | * @summary Updates the checked state on the checkbox in the table. |
| | 843 | * |
| | 844 | * @returns {boolean} True checks the checkbox, False unchecks the checkbox. |
| | 845 | */ |
| 583 | 846 | .prop('checked', function() { |
| 584 | 847 | if ( $(this).is(':hidden,:disabled') ) { |
| 585 | 848 | return false; |
| … |
… |
$document.ready( function() { |
| 596 | 859 | |
| 597 | 860 | $table.children('thead, tfoot').filter(':visible') |
| 598 | 861 | .children().children('.check-column').find(':checkbox') |
| | 862 | |
| | 863 | /** |
| | 864 | * @summary Syncs the bulk checkboxes on the top and bottom of the table. |
| | 865 | * |
| | 866 | * @returns {boolean} True checks the checkbox, False unchecks the checkbox. |
| | 867 | */ |
| 599 | 868 | .prop('checked', function() { |
| 600 | 869 | if ( toggle ) { |
| 601 | 870 | return false; |
| … |
… |
$document.ready( function() { |
| 607 | 876 | }); |
| 608 | 877 | }); |
| 609 | 878 | |
| 610 | | // Show row actions on keyboard focus of its parent container element or any other elements contained within |
| | 879 | /** |
| | 880 | * @summary Shows row actions on focus of its parent container element or any other elements contained within. |
| | 881 | * |
| | 882 | * @returns {void} |
| | 883 | */ |
| 611 | 884 | $( '#wpbody-content' ).on({ |
| 612 | 885 | focusin: function() { |
| 613 | 886 | clearTimeout( transitionTimeout ); |
| … |
… |
$document.ready( function() { |
| 636 | 909 | return false; |
| 637 | 910 | }); |
| 638 | 911 | |
| 639 | | // tab in textareas |
| | 912 | /** |
| | 913 | * @summary Handles tab keypresses in theme and plugin editor textareas. |
| | 914 | * |
| | 915 | * @param {Event} e The event object. |
| | 916 | * |
| | 917 | * @returns {void} |
| | 918 | */ |
| 640 | 919 | $('#newcontent').bind('keydown.wpevent_InsertTab', function(e) { |
| 641 | 920 | var el = e.target, selStart, selEnd, val, scroll, sel; |
| 642 | 921 | |
| 643 | | if ( e.keyCode == 27 ) { // escape key |
| | 922 | // After pressing escape key (keyCode: 27), the tab key should tab out of the textarea. |
| | 923 | if ( e.keyCode == 27 ) { |
| 644 | 924 | // when pressing Escape: Opera 12 and 27 blur form fields, IE 8 clears them |
| 645 | 925 | e.preventDefault(); |
| 646 | 926 | $(el).data('tab-out', true); |
| 647 | 927 | return; |
| 648 | 928 | } |
| 649 | 929 | |
| 650 | | if ( e.keyCode != 9 || e.ctrlKey || e.altKey || e.shiftKey ) // tab key |
| | 930 | // Only listen for plain tab key (keyCode: 9) without any modifiers. |
| | 931 | if ( e.keyCode != 9 || e.ctrlKey || e.altKey || e.shiftKey ) |
| 651 | 932 | return; |
| 652 | 933 | |
| | 934 | // After tabbing out, reset it so next time the tab key can be used again. |
| 653 | 935 | if ( $(el).data('tab-out') ) { |
| 654 | 936 | $(el).data('tab-out', false); |
| 655 | 937 | return; |
| … |
… |
$document.ready( function() { |
| 659 | 941 | selEnd = el.selectionEnd; |
| 660 | 942 | val = el.value; |
| 661 | 943 | |
| | 944 | // If any text is selected, replace the selection with a tab character. |
| 662 | 945 | if ( document.selection ) { |
| 663 | 946 | el.focus(); |
| 664 | 947 | sel = document.selection.createRange(); |
| … |
… |
$document.ready( function() { |
| 670 | 953 | this.scrollTop = scroll; |
| 671 | 954 | } |
| 672 | 955 | |
| | 956 | // Cancel the regular tab functionality, to prevent losing focus of the textarea. |
| 673 | 957 | if ( e.stopPropagation ) |
| 674 | 958 | e.stopPropagation(); |
| 675 | 959 | if ( e.preventDefault ) |
| 676 | 960 | e.preventDefault(); |
| 677 | 961 | }); |
| 678 | 962 | |
| | 963 | // Reset page number variable for new filters/searches but not for bulk actions. See #17685. |
| 679 | 964 | if ( pageInput.length ) { |
| 680 | | pageInput.closest('form').submit( function() { |
| 681 | 965 | |
| 682 | | // Reset paging var for new filters/searches but not for bulk actions. See #17685. |
| | 966 | /** |
| | 967 | * @summary Handles pagination variable when filtering the list table. |
| | 968 | * |
| | 969 | * Set the pagination argument to the first page when the post-filter form is submitted. |
| | 970 | * This happens when pressing the 'filter' button on the list table page. |
| | 971 | * |
| | 972 | * The pagination argument should not be touched when the bulk action dropdowns are set to do anything. |
| | 973 | * |
| | 974 | * The form closest to the pageInput is the post-filter form. |
| | 975 | * |
| | 976 | * @returns {void} |
| | 977 | */ |
| | 978 | pageInput.closest('form').submit( function() { |
| | 979 | /* |
| | 980 | * action = bulk action dropdown at the top of the table |
| | 981 | * action2 = bulk action dropdow at the bottom of the table |
| | 982 | */ |
| 683 | 983 | if ( $('select[name="action"]').val() == -1 && $('select[name="action2"]').val() == -1 && pageInput.val() == currentPage ) |
| 684 | 984 | pageInput.val('1'); |
| 685 | 985 | }); |
| 686 | 986 | } |
| 687 | 987 | |
| | 988 | /** |
| | 989 | * @summary Resets the bulk actions when the search button is clicked. |
| | 990 | * |
| | 991 | * @returns {void} |
| | 992 | */ |
| 688 | 993 | $('.search-box input[type="search"], .search-box input[type="submit"]').mousedown(function () { |
| 689 | 994 | $('select[name^="action"]').val('-1'); |
| 690 | 995 | }); |
| 691 | 996 | |
| 692 | | // Scroll into view when focused |
| | 997 | /** |
| | 998 | * @summary Scrolls into view when focus.scroll-into-view is triggered. |
| | 999 | * |
| | 1000 | * @param {Event} e The event object. |
| | 1001 | * |
| | 1002 | * @returns {void} |
| | 1003 | */ |
| 693 | 1004 | $('#contextual-help-link, #show-settings-link').on( 'focus.scroll-into-view', function(e){ |
| 694 | 1005 | if ( e.target.scrollIntoView ) |
| 695 | 1006 | e.target.scrollIntoView(false); |
| 696 | 1007 | }); |
| 697 | 1008 | |
| 698 | | // Disable upload buttons until files are selected |
| | 1009 | /** |
| | 1010 | * @summary Disables the submit upload buttons when no data is entered. |
| | 1011 | * |
| | 1012 | * @returns {void} |
| | 1013 | */ |
| 699 | 1014 | (function(){ |
| 700 | 1015 | var button, input, form = $('form.wp-upload-form'); |
| | 1016 | |
| | 1017 | // Exit when no upload form is found. |
| 701 | 1018 | if ( ! form.length ) |
| 702 | 1019 | return; |
| | 1020 | |
| 703 | 1021 | button = form.find('input[type="submit"]'); |
| 704 | 1022 | input = form.find('input[type="file"]'); |
| 705 | 1023 | |
| | 1024 | /** |
| | 1025 | * @summary Determines if any data is entered in any file upload input. |
| | 1026 | * |
| | 1027 | * @since 3.5.0 |
| | 1028 | * |
| | 1029 | * @returns {void} |
| | 1030 | */ |
| 706 | 1031 | function toggleUploadButton() { |
| | 1032 | // When no inputs have a value, disable the upload buttons. |
| 707 | 1033 | button.prop('disabled', '' === input.map( function() { |
| 708 | 1034 | return $(this).val(); |
| 709 | 1035 | }).get().join('')); |
| 710 | 1036 | } |
| | 1037 | |
| | 1038 | // Update the status initially. |
| 711 | 1039 | toggleUploadButton(); |
| | 1040 | // Update the status when any file input changes. |
| 712 | 1041 | input.on('change', toggleUploadButton); |
| 713 | 1042 | })(); |
| 714 | 1043 | |
| | 1044 | /** |
| | 1045 | * @summary Pins the menu while distraction-free writing is enabled. |
| | 1046 | * |
| | 1047 | * @param {Event} event Event data. |
| | 1048 | * |
| | 1049 | * @since 4.1.0 |
| | 1050 | * |
| | 1051 | * @returns {void} |
| | 1052 | */ |
| 715 | 1053 | function pinMenu( event ) { |
| 716 | 1054 | var windowPos = $window.scrollTop(), |
| 717 | 1055 | resizing = ! event || event.type !== 'scroll'; |
| … |
… |
$document.ready( function() { |
| 720 | 1058 | return; |
| 721 | 1059 | } |
| 722 | 1060 | |
| | 1061 | /* |
| | 1062 | * When the menu is higher than the window and smaller than the entire page. |
| | 1063 | * It should be adjusted to be able to see the entire menu. |
| | 1064 | * |
| | 1065 | * Otherwise it can be accessed normally. |
| | 1066 | */ |
| 723 | 1067 | if ( height.menu + height.adminbar < height.window || |
| 724 | 1068 | height.menu + height.adminbar + 20 > height.wpwrap ) { |
| 725 | 1069 | unpinMenu(); |
| … |
… |
$document.ready( function() { |
| 728 | 1072 | |
| 729 | 1073 | menuIsPinned = true; |
| 730 | 1074 | |
| | 1075 | // If the menu is higher than the window, compensate on scroll. |
| 731 | 1076 | if ( height.menu + height.adminbar > height.window ) { |
| 732 | | // Check for overscrolling |
| | 1077 | // Check for overscrolling, this happens when swiping up at the top of the document in modern browsers. |
| 733 | 1078 | if ( windowPos < 0 ) { |
| | 1079 | // Stick the menu to the top. |
| 734 | 1080 | if ( ! pinnedMenuTop ) { |
| 735 | 1081 | pinnedMenuTop = true; |
| 736 | 1082 | pinnedMenuBottom = false; |
| … |
… |
$document.ready( function() { |
| 744 | 1090 | |
| 745 | 1091 | return; |
| 746 | 1092 | } else if ( windowPos + height.window > $document.height() - 1 ) { |
| | 1093 | // When overscrolling at the bottom, stick the menu to the bottom. |
| 747 | 1094 | if ( ! pinnedMenuBottom ) { |
| 748 | 1095 | pinnedMenuBottom = true; |
| 749 | 1096 | pinnedMenuTop = false; |
| … |
… |
$document.ready( function() { |
| 759 | 1106 | } |
| 760 | 1107 | |
| 761 | 1108 | if ( windowPos > lastScrollPosition ) { |
| 762 | | // Scrolling down |
| | 1109 | // When a down scroll has been detected. |
| | 1110 | |
| | 1111 | // If it was pinned to the top, unpin and calculate relative scroll. |
| 763 | 1112 | if ( pinnedMenuTop ) { |
| 764 | | // let it scroll |
| 765 | 1113 | pinnedMenuTop = false; |
| | 1114 | // Calculate new offset position. |
| 766 | 1115 | menuTop = $adminMenuWrap.offset().top - height.adminbar - ( windowPos - lastScrollPosition ); |
| 767 | 1116 | |
| 768 | 1117 | if ( menuTop + height.menu + height.adminbar < windowPos + height.window ) { |
| … |
… |
$document.ready( function() { |
| 775 | 1124 | bottom: '' |
| 776 | 1125 | }); |
| 777 | 1126 | } else if ( ! pinnedMenuBottom && $adminMenuWrap.offset().top + height.menu < windowPos + height.window ) { |
| 778 | | // pin the bottom |
| | 1127 | // Pin it to the bottom. |
| 779 | 1128 | pinnedMenuBottom = true; |
| 780 | 1129 | |
| 781 | 1130 | $adminMenuWrap.css({ |
| … |
… |
$document.ready( function() { |
| 785 | 1134 | }); |
| 786 | 1135 | } |
| 787 | 1136 | } else if ( windowPos < lastScrollPosition ) { |
| 788 | | // Scrolling up |
| | 1137 | // When a scroll up is detected. |
| | 1138 | |
| | 1139 | // If it was pinned to the bottom, unpin and calculate relative scroll. |
| 789 | 1140 | if ( pinnedMenuBottom ) { |
| 790 | | // let it scroll |
| 791 | 1141 | pinnedMenuBottom = false; |
| | 1142 | |
| | 1143 | // Calculate new offset position. |
| 792 | 1144 | menuTop = $adminMenuWrap.offset().top - height.adminbar + ( lastScrollPosition - windowPos ); |
| 793 | 1145 | |
| 794 | 1146 | if ( menuTop + height.menu > windowPos + height.window ) { |
| … |
… |
$document.ready( function() { |
| 801 | 1153 | bottom: '' |
| 802 | 1154 | }); |
| 803 | 1155 | } else if ( ! pinnedMenuTop && $adminMenuWrap.offset().top >= windowPos + height.adminbar ) { |
| 804 | | // pin the top |
| | 1156 | |
| | 1157 | // Pin it to the top. |
| 805 | 1158 | pinnedMenuTop = true; |
| 806 | 1159 | |
| 807 | 1160 | $adminMenuWrap.css({ |
| … |
… |
$document.ready( function() { |
| 811 | 1164 | }); |
| 812 | 1165 | } |
| 813 | 1166 | } else if ( resizing ) { |
| 814 | | // Resizing |
| | 1167 | // Window is being resized. |
| | 1168 | |
| 815 | 1169 | pinnedMenuTop = pinnedMenuBottom = false; |
| | 1170 | |
| | 1171 | // Calculate the new offset. |
| 816 | 1172 | menuTop = windowPos + height.window - height.menu - height.adminbar - 1; |
| 817 | 1173 | |
| 818 | 1174 | if ( menuTop > 0 ) { |
| … |
… |
$document.ready( function() { |
| 830 | 1186 | lastScrollPosition = windowPos; |
| 831 | 1187 | } |
| 832 | 1188 | |
| | 1189 | /** |
| | 1190 | * @summary Determines the height of certain elements. |
| | 1191 | * |
| | 1192 | * @since 4.1.0 |
| | 1193 | * |
| | 1194 | * @returns {void} |
| | 1195 | */ |
| 833 | 1196 | function resetHeights() { |
| 834 | 1197 | height = { |
| 835 | 1198 | window: $window.height(), |
| … |
… |
$document.ready( function() { |
| 839 | 1202 | }; |
| 840 | 1203 | } |
| 841 | 1204 | |
| | 1205 | /** |
| | 1206 | * @summary Unpins the menu. |
| | 1207 | * |
| | 1208 | * @since 4.1.0 |
| | 1209 | * |
| | 1210 | * @returns {void} |
| | 1211 | */ |
| 842 | 1212 | function unpinMenu() { |
| 843 | 1213 | if ( isIOS || ! menuIsPinned ) { |
| 844 | 1214 | return; |
| … |
… |
$document.ready( function() { |
| 852 | 1222 | }); |
| 853 | 1223 | } |
| 854 | 1224 | |
| | 1225 | /** |
| | 1226 | * @summary Pins and unpins the menu when applicable. |
| | 1227 | * |
| | 1228 | * @since 4.1.0 |
| | 1229 | * |
| | 1230 | * @returns {void} |
| | 1231 | */ |
| 855 | 1232 | function setPinMenu() { |
| 856 | 1233 | resetHeights(); |
| 857 | 1234 | |
| … |
… |
$document.ready( function() { |
| 874 | 1251 | }); |
| 875 | 1252 | } |
| 876 | 1253 | |
| | 1254 | /** |
| | 1255 | * @summary Changes properties of metaboxes and body. |
| | 1256 | * |
| | 1257 | * Changes the sortables and responsiveness of metaboxes. |
| | 1258 | * |
| | 1259 | * @since 3.8.0 |
| | 1260 | * |
| | 1261 | *@returns {void} |
| | 1262 | */ |
| 877 | 1263 | window.wpResponsive = { |
| | 1264 | |
| | 1265 | /** |
| | 1266 | * @summary Initializes the wpResponsive object. |
| | 1267 | * |
| | 1268 | * @since 3.8.0 |
| | 1269 | * |
| | 1270 | * @returns {void} |
| | 1271 | */ |
| 878 | 1272 | init: function() { |
| 879 | 1273 | var self = this; |
| 880 | 1274 | |
| … |
… |
$document.ready( function() { |
| 887 | 1281 | |
| 888 | 1282 | $( '#wp-admin-bar-menu-toggle a' ).attr( 'aria-expanded', 'false' ); |
| 889 | 1283 | |
| 890 | | // Toggle sidebar when toggle is clicked |
| | 1284 | // Toggle sidebar when toggle is clicked. |
| 891 | 1285 | $( '#wp-admin-bar-menu-toggle' ).on( 'click.wp-responsive', function( event ) { |
| 892 | 1286 | event.preventDefault(); |
| 893 | 1287 | |
| 894 | | // close any open toolbar submenus |
| | 1288 | // close any open toolbar submenus. |
| 895 | 1289 | $adminbar.find( '.hover' ).removeClass( 'hover' ); |
| 896 | 1290 | |
| 897 | 1291 | $wpwrap.toggleClass( 'wp-responsive-open' ); |
| … |
… |
$document.ready( function() { |
| 903 | 1297 | } |
| 904 | 1298 | } ); |
| 905 | 1299 | |
| 906 | | // Add menu events |
| | 1300 | // Add menu events. |
| 907 | 1301 | $adminmenu.on( 'click.wp-responsive', 'li.wp-has-submenu > a', function( event ) { |
| 908 | 1302 | if ( ! $adminmenu.data('wp-responsive') ) { |
| 909 | 1303 | return; |
| … |
… |
$document.ready( function() { |
| 916 | 1310 | self.trigger(); |
| 917 | 1311 | $document.on( 'wp-window-resized.wp-responsive', $.proxy( this.trigger, this ) ); |
| 918 | 1312 | |
| 919 | | // This needs to run later as UI Sortable may be initialized later on $(document).ready() |
| | 1313 | // This needs to run later as UI Sortable may be initialized later on $(document).ready(). |
| 920 | 1314 | $window.on( 'load.wp-responsive', function() { |
| 921 | 1315 | var width = navigator.userAgent.indexOf('AppleWebKit/') > -1 ? $window.width() : window.innerWidth; |
| 922 | 1316 | |
| … |
… |
$document.ready( function() { |
| 926 | 1320 | }); |
| 927 | 1321 | }, |
| 928 | 1322 | |
| | 1323 | /** |
| | 1324 | * @summary Changes properties of body and admin menu. |
| | 1325 | * |
| | 1326 | * Pins and unpins the menu and adds the auto-fold class to the body. |
| | 1327 | * Makes the admin menu responsive and disables the metabox sortables. |
| | 1328 | * |
| | 1329 | * @since 3.8.0 |
| | 1330 | * |
| | 1331 | * @returns {void} |
| | 1332 | */ |
| 929 | 1333 | activate: function() { |
| 930 | 1334 | setPinMenu(); |
| 931 | 1335 | |
| 932 | | if ( ! $body.hasClass( 'auto-fold' ) ) { |
| 933 | | $body.addClass( 'auto-fold' ); |
| | 1336 | if ( ! $body.hasClass( "auto-fold" ) ) { |
| | 1337 | $body.addClass( "auto-fold" ); |
| 934 | 1338 | } |
| 935 | 1339 | |
| 936 | | $adminmenu.data( 'wp-responsive', 1 ); |
| | 1340 | $adminmenu.data( "wp-responsive", 1 ); |
| 937 | 1341 | this.disableSortables(); |
| 938 | 1342 | }, |
| 939 | 1343 | |
| | 1344 | /** |
| | 1345 | * @summary Changes properties of admin menu and enables metabox sortables. |
| | 1346 | * |
| | 1347 | * Pin and unpin the menu. |
| | 1348 | * Removes the responsiveness of the admin menu and enables the metabox sortables. |
| | 1349 | * |
| | 1350 | * @since 3.8.0 |
| | 1351 | * |
| | 1352 | * @returns {void} |
| | 1353 | */ |
| 940 | 1354 | deactivate: function() { |
| 941 | 1355 | setPinMenu(); |
| 942 | 1356 | $adminmenu.removeData('wp-responsive'); |
| 943 | 1357 | this.enableSortables(); |
| 944 | 1358 | }, |
| 945 | 1359 | |
| | 1360 | /** |
| | 1361 | * @summary Sets the responsiveness and enables the overlay based on the viewport width. |
| | 1362 | * |
| | 1363 | * @since 3.8.0 |
| | 1364 | * |
| | 1365 | * @returns {void} |
| | 1366 | */ |
| 946 | 1367 | trigger: function() { |
| 947 | 1368 | var viewportWidth = getViewportWidth(); |
| 948 | 1369 | |
| … |
… |
$document.ready( function() { |
| 953 | 1374 | |
| 954 | 1375 | if ( viewportWidth <= 782 ) { |
| 955 | 1376 | if ( ! wpResponsiveActive ) { |
| 956 | | $document.trigger( 'wp-responsive-activate' ); |
| | 1377 | $document.trigger( "wp-responsive-activate" ); |
| 957 | 1378 | wpResponsiveActive = true; |
| 958 | 1379 | } |
| 959 | 1380 | } else { |
| 960 | 1381 | if ( wpResponsiveActive ) { |
| 961 | | $document.trigger( 'wp-responsive-deactivate' ); |
| | 1382 | $document.trigger( "wp-responsive-deactivate" ); |
| 962 | 1383 | wpResponsiveActive = false; |
| 963 | 1384 | } |
| 964 | 1385 | } |
| … |
… |
$document.ready( function() { |
| 970 | 1391 | } |
| 971 | 1392 | }, |
| 972 | 1393 | |
| | 1394 | /** |
| | 1395 | * @summary Inserts a responsive overlay and toggles the window. |
| | 1396 | * |
| | 1397 | * @since 3.8.0 |
| | 1398 | * |
| | 1399 | * @returns {void} |
| | 1400 | */ |
| 973 | 1401 | enableOverlay: function() { |
| 974 | 1402 | if ( $overlay.length === 0 ) { |
| 975 | 1403 | $overlay = $( '<div id="wp-responsive-overlay"></div>' ) |
| … |
… |
$document.ready( function() { |
| 986 | 1414 | }); |
| 987 | 1415 | }, |
| 988 | 1416 | |
| | 1417 | /** |
| | 1418 | * @summary Disables the responsive overlay and removes the overlay. |
| | 1419 | * |
| | 1420 | * @since 3.8.0 |
| | 1421 | * |
| | 1422 | * @returns {void} |
| | 1423 | */ |
| 989 | 1424 | disableOverlay: function() { |
| 990 | | $toolbarPopups.off( 'click.wp-responsive' ); |
| | 1425 | $toolbarPopups.off( "click.wp-responsive" ); |
| 991 | 1426 | $overlay.hide(); |
| 992 | 1427 | }, |
| 993 | 1428 | |
| | 1429 | /** |
| | 1430 | * @summary Disables sortables. |
| | 1431 | * |
| | 1432 | * @since 3.8.0 |
| | 1433 | * |
| | 1434 | * @returns {void} |
| | 1435 | */ |
| 994 | 1436 | disableSortables: function() { |
| 995 | 1437 | if ( $sortables.length ) { |
| 996 | 1438 | try { |
| 997 | | $sortables.sortable('disable'); |
| 998 | | } catch(e) {} |
| | 1439 | $sortables.sortable( "disable" ); |
| | 1440 | } catch ( e ) {} |
| 999 | 1441 | } |
| 1000 | 1442 | }, |
| 1001 | 1443 | |
| | 1444 | /** |
| | 1445 | * @summary Enables sortables. |
| | 1446 | * |
| | 1447 | * @since 3.8.0 |
| | 1448 | * |
| | 1449 | * @returns {void} |
| | 1450 | */ |
| 1002 | 1451 | enableSortables: function() { |
| 1003 | 1452 | if ( $sortables.length ) { |
| 1004 | 1453 | try { |
| 1005 | | $sortables.sortable('enable'); |
| 1006 | | } catch(e) {} |
| | 1454 | $sortables.sortable( "enable" ); |
| | 1455 | } catch ( e ) {} |
| 1007 | 1456 | } |
| 1008 | 1457 | } |
| 1009 | 1458 | }; |
| 1010 | 1459 | |
| 1011 | | // Add an ARIA role `button` to elements that behave like UI controls when JavaScript is on. |
| | 1460 | /** |
| | 1461 | * @summary Add an ARIA role `button` to elements that behave like UI controls when JavaScript is on. |
| | 1462 | * |
| | 1463 | * @since 4.5.0 |
| | 1464 | * |
| | 1465 | * @returns {void} |
| | 1466 | */ |
| 1012 | 1467 | function aria_button_if_js() { |
| 1013 | | $( '.aria-button-if-js' ).attr( 'role', 'button' ); |
| | 1468 | $( ".aria-button-if-js" ).attr( "role", "button" ); |
| 1014 | 1469 | } |
| 1015 | 1470 | |
| 1016 | 1471 | $( document ).ajaxComplete( function() { |
| … |
… |
$document.ready( function() { |
| 1037 | 1492 | } |
| 1038 | 1493 | |
| 1039 | 1494 | /** |
| 1040 | | * @summary Set the admin menu collapsed/expanded state. |
| | 1495 | * @summary Sets the admin menu collapsed/expanded state. |
| 1041 | 1496 | * |
| 1042 | 1497 | * Sets the global variable `menuState` and triggers a custom event passing |
| 1043 | 1498 | * the current menu state. |
| … |
… |
$document.ready( function() { |
| 1064 | 1519 | $document.on( 'wp-window-resized.set-menu-state', setMenuState ); |
| 1065 | 1520 | |
| 1066 | 1521 | /** |
| 1067 | | * @summary Set ARIA attributes on the collapse/expand menu button. |
| | 1522 | * @summary Sets ARIA attributes on the collapse/expand menu button. |
| 1068 | 1523 | * |
| 1069 | 1524 | * When the admin menu is open or folded, updates the `aria-expanded` and |
| 1070 | 1525 | * `aria-label` attributes of the button to give feedback to assistive |
| … |
… |
$document.ready( function() { |
| 1122 | 1577 | }); |
| 1123 | 1578 | }); |
| 1124 | 1579 | |
| 1125 | | // Fire a custom jQuery event at the end of window resize |
| | 1580 | // Fire a custom jQuery event at the end of window resize. |
| 1126 | 1581 | ( function() { |
| 1127 | 1582 | var timeout; |
| 1128 | 1583 | |
| | 1584 | /** |
| | 1585 | * @summary Triggers the WP window-resize event. |
| | 1586 | * |
| | 1587 | * @since 3.8.0 |
| | 1588 | * |
| | 1589 | * @returns {void} |
| | 1590 | */ |
| 1129 | 1591 | function triggerEvent() { |
| 1130 | | $document.trigger( 'wp-window-resized' ); |
| | 1592 | $document.trigger( "wp-window-resized" ); |
| 1131 | 1593 | } |
| 1132 | 1594 | |
| | 1595 | /** |
| | 1596 | * @summary Fires the trigger event again after 200 ms. |
| | 1597 | * |
| | 1598 | * @since 3.8.0 |
| | 1599 | * |
| | 1600 | * @returns {void} |
| | 1601 | */ |
| 1133 | 1602 | function fireOnce() { |
| 1134 | 1603 | window.clearTimeout( timeout ); |
| 1135 | 1604 | timeout = window.setTimeout( triggerEvent, 200 ); |