From d34a54f1e4c154dd18a4d088fff844bb9b70d692 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Fri, 26 Sep 2014 23:01:52 +0000 Subject: [PATCH] Fix tapping on the menu in iOS and Android, fixes #29365 for trunk git-svn-id: https://develop.svn.wordpress.org/trunk@29770 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/js/common.js | 118 ++++++++++++++++++++------------------ 1 file changed, 61 insertions(+), 57 deletions(-) diff --git a/src/wp-admin/js/common.js b/src/wp-admin/js/common.js index b61763af06..aeb5f67c62 100644 --- a/src/wp-admin/js/common.js +++ b/src/wp-admin/js/common.js @@ -175,7 +175,9 @@ $(document).ready( function() { lastClicked = false, menu = $('#adminmenu'), pageInput = $('input.current-page'), - currentPage = pageInput.val(); + currentPage = pageInput.val(), + isIOS = /iPhone|iPad|iPod/.test( navigator.userAgent ), + isAndroid = navigator.userAgent.indexOf( 'Android' ) !== -1; // when the menu is folded, make the fly-out submenu header clickable menu.on('click.wp-submenu-head', '.wp-submenu-head', function(e){ @@ -224,7 +226,7 @@ $(document).ready( function() { if ( 'ontouchstart' in window || /IEMobile\/[1-9]/.test(navigator.userAgent) ) { // touch screen device // iOS Safari works with touchstart, the rest work with click - mobileEvent = /Mobile\/.+Safari/.test(navigator.userAgent) ? 'touchstart' : 'click'; + 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) { @@ -282,73 +284,75 @@ $(document).ready( function() { }); } - menu.find('li.wp-has-submenu').hoverIntent({ - over: function() { - var b, h, o, f, m = $(this).find('.wp-submenu'), menutop, wintop, maxtop, top = parseInt( m.css('top'), 10 ); + if ( ! isIOS && ! isAndroid ) { + menu.find('li.wp-has-submenu').hoverIntent({ + over: function() { + var b, h, o, f, m = $(this).find('.wp-submenu'), menutop, wintop, maxtop, top = parseInt( m.css('top'), 10 ); - if ( isNaN(top) || top > -5 ) { // meaning the submenu is visible - return; - } + if ( isNaN(top) || top > -5 ) { // meaning the submenu is visible + return; + } + if ( menu.data('wp-responsive') ) { + // The menu is in responsive mode, bail + return; + } + + menutop = $(this).offset().top; + wintop = $(window).scrollTop(); + maxtop = menutop - wintop - 30; // max = make the top of the sub almost touch admin bar + + b = menutop + m.height() + 1; // Bottom offset of the menu + h = $('#wpwrap').height(); // Height of the entire page + o = 60 + b - h; + f = $(window).height() + wintop - 15; // The fold + + if ( f < (b - o) ) { + o = b - f; + } + + if ( o > maxtop ) { + o = maxtop; + } + + if ( o > 1 ) { + m.css('margin-top', '-'+o+'px'); + } else { + m.css('margin-top', ''); + } + + menu.find('li.menu-top').removeClass('opensub'); + $(this).addClass('opensub'); + }, + out: function(){ + if ( menu.data('wp-responsive') ) { + // The menu is in responsive mode, bail + return; + } + + $(this).removeClass('opensub').find('.wp-submenu').css('margin-top', ''); + }, + timeout: 200, + sensitivity: 7, + interval: 90 + }); + + menu.on('focus.adminmenu', '.wp-submenu a', function(e){ if ( menu.data('wp-responsive') ) { // The menu is in responsive mode, bail return; } - menutop = $(this).offset().top; - wintop = $(window).scrollTop(); - maxtop = menutop - wintop - 30; // max = make the top of the sub almost touch admin bar - - b = menutop + m.height() + 1; // Bottom offset of the menu - h = $('#wpwrap').height(); // Height of the entire page - o = 60 + b - h; - f = $(window).height() + wintop - 15; // The fold - - if ( f < (b - o) ) { - o = b - f; - } - - if ( o > maxtop ) { - o = maxtop; - } - - if ( o > 1 ) { - m.css('margin-top', '-'+o+'px'); - } else { - m.css('margin-top', ''); - } - - menu.find('li.menu-top').removeClass('opensub'); - $(this).addClass('opensub'); - }, - out: function(){ + $(e.target).closest('li.menu-top').addClass('opensub'); + }).on('blur.adminmenu', '.wp-submenu a', function(e){ if ( menu.data('wp-responsive') ) { // The menu is in responsive mode, bail return; } - $(this).removeClass('opensub').find('.wp-submenu').css('margin-top', ''); - }, - timeout: 200, - sensitivity: 7, - interval: 90 - }); - - menu.on('focus.adminmenu', '.wp-submenu a', function(e){ - if ( menu.data('wp-responsive') ) { - // The menu is in responsive mode, bail - return; - } - - $(e.target).closest('li.menu-top').addClass('opensub'); - }).on('blur.adminmenu', '.wp-submenu a', function(e){ - if ( menu.data('wp-responsive') ) { - // The menu is in responsive mode, bail - return; - } - - $(e.target).closest('li.menu-top').removeClass('opensub'); - }); + $(e.target).closest('li.menu-top').removeClass('opensub'); + }); + } // 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');