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