Make WordPress Core

Changeset 35313


Ignore:
Timestamp:
10/21/2015 03:40:38 AM (9 years ago)
Author:
wonderboymusic
Message:

Administration: the current admin menu item should have an aria-haspopup attribute when the menu is folded.

Unify the jQuery selector caching for window, document, and body.

Props afercia.
Fixes #32578.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/common.js

    r35239 r35313  
    22var showNotice, adminMenu, columns, validateForm, screenMeta;
    33( function( $, window, undefined ) {
     4    var $document = $( document ),
     5        $window = $( window ),
     6        $body = $( document.body );
     7
    48// Removed in 3.3.
    59// (perhaps) needed for back-compat
     
    7175};
    7276
    73 $(document).ready(function(){columns.init();});
     77$document.ready(function(){columns.init();});
    7478
    7579validateForm = function( form ) {
     
    134138        });
    135139
    136         $( document ).trigger( 'screen:options:open' );
     140        $document.trigger( 'screen:options:open' );
    137141    },
    138142
     
    144148        });
    145149
    146         $( document ).trigger( 'screen:options:close' );
     150        $document.trigger( 'screen:options:close' );
    147151    }
    148152};
     
    172176});
    173177
    174 $(document).ready( function() {
     178$document.ready( function() {
    175179    var checks, first, last, checked, sliced, mobileEvent, transitionTimeout, focusedRowActions,
    176180        lastClicked = false,
     
    180184        isAndroid = navigator.userAgent.indexOf( 'Android' ) !== -1,
    181185        isIE8 = $( document.documentElement ).hasClass( 'ie8' ),
    182         $document = $( document ),
    183         $window = $( window ),
    184         $body = $( document.body ),
    185186        $adminMenuWrap = $( '#adminmenuwrap' ),
    186187        $wpwrap = $( '#wpwrap' ),
     
    211212
    212213    $('#collapse-menu').on('click.collapse-menu', function() {
    213         var body = $( document.body ), respWidth, state;
     214        var respWidth, state;
    214215
    215216        // reset any compensation for submenus near the bottom of the screen
     
    225226
    226227        if ( respWidth && respWidth < 960 ) {
    227             if ( body.hasClass('auto-fold') ) {
    228                 body.removeClass('auto-fold').removeClass('folded');
     228            if ( $body.hasClass('auto-fold') ) {
     229                $body.removeClass('auto-fold').removeClass('folded');
    229230                setUserSetting('unfold', 1);
    230231                setUserSetting('mfold', 'o');
    231232                state = 'open';
    232233            } else {
    233                 body.addClass('auto-fold');
     234                $body.addClass('auto-fold');
    234235                setUserSetting('unfold', 0);
    235236                state = 'folded';
    236237            }
    237238        } else {
    238             if ( body.hasClass('folded') ) {
    239                 body.removeClass('folded');
     239            if ( $body.hasClass('folded') ) {
     240                $body.removeClass('folded');
    240241                setUserSetting('mfold', 'o');
    241242                state = 'open';
    242243            } else {
    243                 body.addClass('folded');
     244                $body.addClass('folded');
    244245                setUserSetting('mfold', 'f');
    245246                state = 'folded';
     
    247248        }
    248249
    249         $( document ).trigger( 'wp-collapse-menu', { state: state } );
     250        currentMenuItemHasPopup();
     251        $document.trigger( 'wp-collapse-menu', { state: state } );
    250252    });
     253
     254    // Handle the `aria-haspopup` attribute on the current menu item when it has a sub-menu.
     255    function currentMenuItemHasPopup() {
     256        var respWidth,
     257            $current = $( 'a.wp-has-current-submenu' );
     258
     259        if ( window.innerWidth ) {
     260            respWidth = Math.max( window.innerWidth, document.documentElement.clientWidth );
     261        } else {
     262            respWidth = 961;
     263        }
     264
     265        if ( $body.hasClass( 'folded' ) || ( $body.hasClass( 'auto-fold' ) && respWidth && respWidth <= 960 && respWidth > 782 ) ) {
     266            // When folded or auto-folded and not responsive view, the current menu item does have a fly-out sub-menu.
     267            $current.attr( 'aria-haspopup', 'true' );
     268        } else {
     269            // When expanded or in responsive view, reset aria-haspopup.
     270            $current.attr( 'aria-haspopup', 'false' );
     271        }
     272    };
     273
     274    $document.on( 'wp-window-resized wp-responsive-activate wp-responsive-deactivate', currentMenuItemHasPopup );
    251275
    252276    /**
     
    290314
    291315        // close any open submenus when touch/click is not on the menu
    292         $(document.body).on( mobileEvent+'.wp-mobile-hover', function(e) {
     316        $body.on( mobileEvent+'.wp-mobile-hover', function(e) {
    293317            if ( $adminmenu.data('wp-responsive') ) {
    294318                return;
     
    867891    window.wpResponsive.init();
    868892    setPinMenu();
     893    currentMenuItemHasPopup();
    869894
    870895    $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 );
     
    876901
    877902    function triggerEvent() {
    878         $(document).trigger( 'wp-window-resized' );
     903        $document.trigger( 'wp-window-resized' );
    879904    }
    880905
     
    884909    }
    885910
    886     $(window).on( 'resize.wp-fire-once', fireOnce );
     911    $window.on( 'resize.wp-fire-once', fireOnce );
    887912}());
    888913
Note: See TracChangeset for help on using the changeset viewer.