X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/af50974463450c98503e763a7836a50e260461a9..0459461f9ea42e0b090759ff6fe5f48360bef750:/wp-admin/js/common.js?ds=sidebyside diff --git a/wp-admin/js/common.js b/wp-admin/js/common.js index 01ce8945..9d7fa415 100644 --- a/wp-admin/js/common.js +++ b/wp-admin/js/common.js @@ -1,6 +1,10 @@ /* global setUserSetting, ajaxurl, commonL10n, alert, confirm, pagenow */ var showNotice, adminMenu, columns, validateForm, screenMeta; ( function( $, window, undefined ) { + var $document = $( document ), + $window = $( window ), + $body = $( document.body ); + // Removed in 3.3. // (perhaps) needed for back-compat adminMenu = { @@ -37,17 +41,19 @@ columns = { }, checked : function(column) { - $('.column-' + column).show(); + $('.column-' + column).removeClass( 'hidden' ); this.colSpanChange(+1); }, unchecked : function(column) { - $('.column-' + column).hide(); + $('.column-' + column).addClass( 'hidden' ); this.colSpanChange(-1); }, hidden : function() { - return $('.manage-column').filter(':hidden').map(function() { return this.id; }).get().join(','); + return $( '.manage-column[id]' ).filter( ':hidden' ).map(function() { + return this.id; + }).get().join( ',' ); }, useCheckboxesForHidden : function() { @@ -68,7 +74,7 @@ columns = { } }; -$(document).ready(function(){columns.init();}); +$document.ready(function(){columns.init();}); validateForm = function( form ) { return !$( form ) @@ -103,15 +109,14 @@ screenMeta = { init: function() { this.element = $('#screen-meta'); - this.toggles = $('.screen-meta-toggle a'); + this.toggles = $( '#screen-meta-links' ).find( '.show-settings' ); this.page = $('#wpcontent'); this.toggles.click( this.toggleEvent ); }, - toggleEvent: function( e ) { - var panel = $( this.href.replace(/.+#/, '#') ); - e.preventDefault(); + toggleEvent: function() { + var panel = $( '#' + $( this ).attr( 'aria-controls' ) ); if ( !panel.length ) return; @@ -122,27 +127,27 @@ screenMeta = { screenMeta.open( panel, $(this) ); }, - open: function( panel, link ) { + open: function( panel, button ) { - $('.screen-meta-toggle').not( link.parent() ).css('visibility', 'hidden'); + $( '#screen-meta-links' ).find( '.screen-meta-toggle' ).not( button.parent() ).css( 'visibility', 'hidden' ); panel.parent().show(); panel.slideDown( 'fast', function() { panel.focus(); - link.addClass('screen-meta-active').attr('aria-expanded', true); + button.addClass( 'screen-meta-active' ).attr( 'aria-expanded', true ); }); - $( document ).trigger( 'screen:options:open' ); + $document.trigger( 'screen:options:open' ); }, - close: function( panel, link ) { + close: function( panel, button ) { panel.slideUp( 'fast', function() { - link.removeClass('screen-meta-active').attr('aria-expanded', false); + button.removeClass( 'screen-meta-active' ).attr( 'aria-expanded', false ); $('.screen-meta-toggle').css('visibility', ''); panel.parent().hide(); }); - $( document ).trigger( 'screen:options:close' ); + $document.trigger( 'screen:options:close' ); } }; @@ -170,7 +175,7 @@ $('.contextual-help-tabs').delegate('a', 'click', function(e) { panel.addClass('active').show(); }); -$(document).ready( function() { +$document.ready( function() { var checks, first, last, checked, sliced, mobileEvent, transitionTimeout, focusedRowActions, lastClicked = false, pageInput = $('input.current-page'), @@ -178,9 +183,6 @@ $(document).ready( function() { isIOS = /iPhone|iPad|iPod/.test( navigator.userAgent ), isAndroid = navigator.userAgent.indexOf( 'Android' ) !== -1, isIE8 = $( document.documentElement ).hasClass( 'ie8' ), - $document = $( document ), - $window = $( window ), - $body = $( document.body ), $adminMenuWrap = $( '#adminmenuwrap' ), $wpwrap = $( '#wpwrap' ), $adminmenu = $( '#adminmenu' ), @@ -209,7 +211,7 @@ $(document).ready( function() { }); $('#collapse-menu').on('click.collapse-menu', function() { - var body = $( document.body ), respWidth, state; + var respWidth, state; // reset any compensation for submenus near the bottom of the screen $('#adminmenu div.wp-submenu').css('margin-top', ''); @@ -223,31 +225,54 @@ $(document).ready( function() { } if ( respWidth && respWidth < 960 ) { - if ( body.hasClass('auto-fold') ) { - body.removeClass('auto-fold').removeClass('folded'); + if ( $body.hasClass('auto-fold') ) { + $body.removeClass('auto-fold').removeClass('folded'); setUserSetting('unfold', 1); setUserSetting('mfold', 'o'); state = 'open'; } else { - body.addClass('auto-fold'); + $body.addClass('auto-fold'); setUserSetting('unfold', 0); state = 'folded'; } } else { - if ( body.hasClass('folded') ) { - body.removeClass('folded'); + if ( $body.hasClass('folded') ) { + $body.removeClass('folded'); setUserSetting('mfold', 'o'); state = 'open'; } else { - body.addClass('folded'); + $body.addClass('folded'); setUserSetting('mfold', 'f'); state = 'folded'; } } - $( document ).trigger( 'wp-collapse-menu', { state: state } ); + currentMenuItemHasPopup(); + $document.trigger( 'wp-collapse-menu', { state: state } ); }); + // Handle the `aria-haspopup` attribute on the current menu item when it has a sub-menu. + function currentMenuItemHasPopup() { + var respWidth, + $current = $( 'a.wp-has-current-submenu' ); + + if ( window.innerWidth ) { + respWidth = Math.max( window.innerWidth, document.documentElement.clientWidth ); + } else { + respWidth = 961; + } + + if ( $body.hasClass( 'folded' ) || ( $body.hasClass( 'auto-fold' ) && respWidth && respWidth <= 960 && respWidth > 782 ) ) { + // When folded or auto-folded and not responsive view, the current menu item does have a fly-out sub-menu. + $current.attr( 'aria-haspopup', 'true' ); + } else { + // When expanded or in responsive view, reset aria-haspopup. + $current.attr( 'aria-haspopup', 'false' ); + } + } + + $document.on( 'wp-window-resized wp-responsive-activate wp-responsive-deactivate', currentMenuItemHasPopup ); + /** * Ensure an admin submenu is within the visual viewport. * @@ -288,7 +313,7 @@ $(document).ready( function() { mobileEvent = isIOS ? 'touchstart' : 'click'; // close any open submenus when touch/click is not on the menu - $(document.body).on( mobileEvent+'.wp-mobile-hover', function(e) { + $body.on( mobileEvent+'.wp-mobile-hover', function(e) { if ( $adminmenu.data('wp-responsive') ) { return; } @@ -368,9 +393,37 @@ $(document).ready( function() { }); } - // Move .updated and .error alert boxes. Don't move boxes designed to be inline. - $('div.wrap h2:first').nextAll('div.updated, div.error').addClass('below-h2'); - $('div.updated, div.error').not('.below-h2, .inline').insertAfter( $('div.wrap h2:first') ); + /* + * The `.below-h2` class is here just for backwards compatibility with plugins + * that are (incorrectly) using it. Do not use. Use `.inline` instead. See #34570. + */ + $( 'div.updated, div.error, div.notice' ).not( '.inline, .below-h2' ).insertAfter( $( '.wrap h1, .wrap h2' ).first() ); + + // Make notices dismissible + function makeNoticesDismissible() { + $( '.notice.is-dismissible' ).each( function() { + var $el = $( this ), + $button = $( '' ), + btnText = commonL10n.dismiss || ''; + + // Ensure plain text + $button.find( '.screen-reader-text' ).text( btnText ); + $button.on( 'click.wp-dismiss-notice', function( event ) { + event.preventDefault(); + $el.fadeTo( 100, 0, function() { + $el.slideUp( 100, function() { + $el.remove(); + }); + }); + }); + + $el.append( $button ); + }); + } + + $document.on( 'wp-plugin-update-error', function() { + makeNoticesDismissible(); + }); // Init screen meta screenMeta.init(); @@ -380,7 +433,7 @@ $(document).ready( function() { if ( 'undefined' == e.shiftKey ) { return true; } if ( e.shiftKey ) { if ( !lastClicked ) { return true; } - checks = $( lastClicked ).closest( 'form' ).find( ':checkbox' ); + checks = $( lastClicked ).closest( 'form' ).find( ':checkbox' ).filter( ':visible:enabled' ); first = checks.index( lastClicked ); last = checks.index( this ); checked = $(this).prop('checked'); @@ -397,7 +450,7 @@ $(document).ready( function() { lastClicked = this; // toggle "check all" checkboxes - var unchecked = $(this).closest('tbody').find(':checkbox').filter(':visible').not(':checked'); + var unchecked = $(this).closest('tbody').find(':checkbox').filter(':visible:enabled').not(':checked'); $(this).closest('table').children('thead, tfoot').find(':checkbox').prop('checked', function() { return ( 0 === unchecked.length ); }); @@ -414,7 +467,7 @@ $(document).ready( function() { $table.children( 'tbody' ).filter(':visible') .children().children('.check-column').find(':checkbox') .prop('checked', function() { - if ( $(this).is(':hidden') ) { + if ( $(this).is(':hidden,:disabled') ) { return false; } @@ -441,16 +494,26 @@ $(document).ready( function() { }); // Show row actions on keyboard focus of its parent container element or any other elements contained within - $( 'td.post-title, td.title, td.comment, .bookmarks td.column-name, td.blogname, td.username, .dashboard-comment-wrap' ).focusin(function(){ - clearTimeout( transitionTimeout ); - focusedRowActions = $(this).find( '.row-actions' ); - focusedRowActions.addClass( 'visible' ); - }).focusout(function(){ - // Tabbing between post title and .row-actions links needs a brief pause, otherwise - // the .row-actions div gets hidden in transit in some browsers (ahem, Firefox). - transitionTimeout = setTimeout(function(){ - focusedRowActions.removeClass( 'visible' ); - }, 30); + $( '#wpbody-content' ).on({ + focusin: function() { + clearTimeout( transitionTimeout ); + focusedRowActions = $( this ).find( '.row-actions' ); + // transitionTimeout is necessary for Firefox, but Chrome won't remove the CSS class without a little help. + $( '.row-actions' ).not( this ).removeClass( 'visible' ); + focusedRowActions.addClass( 'visible' ); + }, + focusout: function() { + // Tabbing between post title and .row-actions links needs a brief pause, otherwise + // the .row-actions div gets hidden in transit in some browsers (ahem, Firefox). + transitionTimeout = setTimeout( function() { + focusedRowActions.removeClass( 'visible' ); + }, 30 ); + } + }, '.has-row-actions' ); + + // Toggle list table rows on small screens + $( 'tbody' ).on( 'click', '.toggle-row', function() { + $( this ).closest( 'tr' ).toggleClass( 'is-expanded' ); }); $('#default-password-nag-no').click( function() { @@ -464,6 +527,8 @@ $(document).ready( function() { var el = e.target, selStart, selEnd, val, scroll, sel; if ( e.keyCode == 27 ) { // escape key + // when pressing Escape: Opera 12 and 27 blur form fields, IE 8 clears them + e.preventDefault(); $(el).data('tab-out', true); return; } @@ -480,10 +545,6 @@ $(document).ready( function() { selEnd = el.selectionEnd; val = el.value; - try { - this.lastKey = 9; // not a standard DOM property, lastKey is to help stop Opera tab event. See blur handler below. - } catch(err) {} - if ( document.selection ) { el.focus(); sel = document.selection.createRange(); @@ -501,11 +562,6 @@ $(document).ready( function() { e.preventDefault(); }); - $('#newcontent').bind('blur.wpevent_InsertTab', function() { - if ( this.lastKey && 9 == this.lastKey ) - this.focus(); - }); - if ( pageInput.length ) { pageInput.closest('form').submit( function() { @@ -720,6 +776,10 @@ $(document).ready( function() { // Toggle sidebar when toggle is clicked $( '#wp-admin-bar-menu-toggle' ).on( 'click.wp-responsive', function( event ) { event.preventDefault(); + + // close any open toolbar submenus + $adminbar.find( '.hover' ).removeClass( 'hover' ); + $wpwrap.toggleClass( 'wp-responsive-open' ); if ( $wpwrap.hasClass( 'wp-responsive-open' ) ) { $(this).find('a').attr( 'aria-expanded', 'true' ); @@ -839,8 +899,10 @@ $(document).ready( function() { window.wpResponsive.init(); setPinMenu(); + currentMenuItemHasPopup(); + makeNoticesDismissible(); - $document.on( 'wp-window-resized.pin-menu postboxes-columnchange.pin-menu postbox-toggled.pin-menu wp-collapse-menu.pin-menu wp-scroll-start.pin-menu', setPinMenu ); + $document.on( 'wp-pin-menu wp-window-resized.pin-menu postboxes-columnchange.pin-menu postbox-toggled.pin-menu wp-collapse-menu.pin-menu wp-scroll-start.pin-menu', setPinMenu ); }); // Fire a custom jQuery event at the end of window resize @@ -848,7 +910,7 @@ $(document).ready( function() { var timeout; function triggerEvent() { - $(document).trigger( 'wp-window-resized' ); + $document.trigger( 'wp-window-resized' ); } function fireOnce() { @@ -856,7 +918,7 @@ $(document).ready( function() { timeout = window.setTimeout( triggerEvent, 200 ); } - $(window).on( 'resize.wp-fire-once', fireOnce ); + $window.on( 'resize.wp-fire-once', fireOnce ); }()); // Make Windows 8 devices play along nicely.