Make WordPress Core

Changeset 29770


Ignore:
Timestamp:
09/26/2014 11:01:52 PM (11 years ago)
Author:
azaozz
Message:

Fix tapping on the menu in iOS and Android, fixes #29365 for trunk

File:
1 edited

Legend:

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

    r29518 r29770  
    176176        menu = $('#adminmenu'),
    177177        pageInput = $('input.current-page'),
    178         currentPage = pageInput.val();
     178        currentPage = pageInput.val(),
     179        isIOS = /iPhone|iPad|iPod/.test( navigator.userAgent ),
     180        isAndroid = navigator.userAgent.indexOf( 'Android' ) !== -1;
    179181
    180182    // when the menu is folded, make the fly-out submenu header clickable
     
    225227    if ( 'ontouchstart' in window || /IEMobile\/[1-9]/.test(navigator.userAgent) ) { // touch screen device
    226228        // iOS Safari works with touchstart, the rest work with click
    227         mobileEvent = /Mobile\/.+Safari/.test(navigator.userAgent) ? 'touchstart' : 'click';
     229        mobileEvent = isIOS ? 'touchstart' : 'click';
    228230
    229231        // close any open submenus when touch/click is not on the menu
     
    283285    }
    284286
    285     menu.find('li.wp-has-submenu').hoverIntent({
    286         over: function() {
    287             var b, h, o, f, m = $(this).find('.wp-submenu'), menutop, wintop, maxtop, top = parseInt( m.css('top'), 10 );
    288 
    289             if ( isNaN(top) || top > -5 ) { // meaning the submenu is visible
    290                 return;
    291             }
    292 
     287    if ( ! isIOS && ! isAndroid ) {
     288        menu.find('li.wp-has-submenu').hoverIntent({
     289            over: function() {
     290                var b, h, o, f, m = $(this).find('.wp-submenu'), menutop, wintop, maxtop, top = parseInt( m.css('top'), 10 );
     291
     292                if ( isNaN(top) || top > -5 ) { // meaning the submenu is visible
     293                    return;
     294                }
     295
     296                if ( menu.data('wp-responsive') ) {
     297                    // The menu is in responsive mode, bail
     298                    return;
     299                }
     300
     301                menutop = $(this).offset().top;
     302                wintop = $(window).scrollTop();
     303                maxtop = menutop - wintop - 30; // max = make the top of the sub almost touch admin bar
     304
     305                b = menutop + m.height() + 1; // Bottom offset of the menu
     306                h = $('#wpwrap').height(); // Height of the entire page
     307                o = 60 + b - h;
     308                f = $(window).height() + wintop - 15; // The fold
     309
     310                if ( f < (b - o) ) {
     311                    o = b - f;
     312                }
     313
     314                if ( o > maxtop ) {
     315                    o = maxtop;
     316                }
     317
     318                if ( o > 1 ) {
     319                    m.css('margin-top', '-'+o+'px');
     320                } else {
     321                    m.css('margin-top', '');
     322                }
     323
     324                menu.find('li.menu-top').removeClass('opensub');
     325                $(this).addClass('opensub');
     326            },
     327            out: function(){
     328                if ( menu.data('wp-responsive') ) {
     329                    // The menu is in responsive mode, bail
     330                    return;
     331                }
     332
     333                $(this).removeClass('opensub').find('.wp-submenu').css('margin-top', '');
     334            },
     335            timeout: 200,
     336            sensitivity: 7,
     337            interval: 90
     338        });
     339
     340        menu.on('focus.adminmenu', '.wp-submenu a', function(e){
    293341            if ( menu.data('wp-responsive') ) {
    294342                // The menu is in responsive mode, bail
     
    296344            }
    297345
    298             menutop = $(this).offset().top;
    299             wintop = $(window).scrollTop();
    300             maxtop = menutop - wintop - 30; // max = make the top of the sub almost touch admin bar
    301 
    302             b = menutop + m.height() + 1; // Bottom offset of the menu
    303             h = $('#wpwrap').height(); // Height of the entire page
    304             o = 60 + b - h;
    305             f = $(window).height() + wintop - 15; // The fold
    306 
    307             if ( f < (b - o) ) {
    308                 o = b - f;
    309             }
    310 
    311             if ( o > maxtop ) {
    312                 o = maxtop;
    313             }
    314 
    315             if ( o > 1 ) {
    316                 m.css('margin-top', '-'+o+'px');
    317             } else {
    318                 m.css('margin-top', '');
    319             }
    320 
    321             menu.find('li.menu-top').removeClass('opensub');
    322             $(this).addClass('opensub');
    323         },
    324         out: function(){
     346            $(e.target).closest('li.menu-top').addClass('opensub');
     347        }).on('blur.adminmenu', '.wp-submenu a', function(e){
    325348            if ( menu.data('wp-responsive') ) {
    326349                // The menu is in responsive mode, bail
     
    328351            }
    329352
    330             $(this).removeClass('opensub').find('.wp-submenu').css('margin-top', '');
    331         },
    332         timeout: 200,
    333         sensitivity: 7,
    334         interval: 90
    335     });
    336 
    337     menu.on('focus.adminmenu', '.wp-submenu a', function(e){
    338         if ( menu.data('wp-responsive') ) {
    339             // The menu is in responsive mode, bail
    340             return;
    341         }
    342 
    343         $(e.target).closest('li.menu-top').addClass('opensub');
    344     }).on('blur.adminmenu', '.wp-submenu a', function(e){
    345         if ( menu.data('wp-responsive') ) {
    346             // The menu is in responsive mode, bail
    347             return;
    348         }
    349 
    350         $(e.target).closest('li.menu-top').removeClass('opensub');
    351     });
     353            $(e.target).closest('li.menu-top').removeClass('opensub');
     354        });
     355    }
    352356
    353357    // Move .updated and .error alert boxes. Don't move boxes designed to be inline.
Note: See TracChangeset for help on using the changeset viewer.