From 98b92462612fc2577381ece0ba1f86a943265876 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Fri, 6 Dec 2013 20:49:46 +0000 Subject: [PATCH] Responsive menu: fix calculation of the responsive trigger width from JS. It is affected by a vertical scrollbar width in some browsers. See #26458. git-svn-id: https://develop.svn.wordpress.org/trunk@26743 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/js/common.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/wp-admin/js/common.js b/src/wp-admin/js/common.js index 09d6aa17fd..01a3c7de02 100644 --- a/src/wp-admin/js/common.js +++ b/src/wp-admin/js/common.js @@ -184,12 +184,13 @@ $(document).ready( function() { // reset any compensation for submenus near the bottom of the screen $('#adminmenu div.wp-submenu').css('margin-top', ''); - // WebKit excludes the width of the vertical scrollbar when applying the CSS "@media screen and (max-width: ...)" - // and matches $(window).width(). - // Firefox and IE > 8 include the scrollbar width, so after the jQuery normalization - // $(window).width() is 884px but window.innerWidth is 900px. - // (using window.innerWidth also excludes IE < 9) - respWidth = navigator.userAgent.indexOf('AppleWebKit/') > -1 ? $(window).width() : window.innerWidth; + if ( window.innerWidth ) { + // window.innerWidth is affected by zooming on phones + respWidth = Math.max( window.innerWidth, document.documentElement.clientWidth ); + } else { + // Exclude IE < 9, it doesn't support @media CSS rules + return; + } if ( respWidth && respWidth < 900 ) { if ( body.hasClass('auto-fold') ) { @@ -603,7 +604,15 @@ $(document).ready( function() { }, trigger: function() { - var width = navigator.userAgent.indexOf('AppleWebKit/') > -1 ? $window.width() : window.innerWidth; + var width; + + if ( window.innerWidth ) { + // window.innerWidth is affected by zooming on phones + width = Math.max( window.innerWidth, document.documentElement.clientWidth ); + } else { + // Exclude IE < 9, it doesn't support @media CSS rules + return; + } if ( width <= 782 ) { if ( ! wpResponsiveActive ) {