<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[22262] trunk: Make the admin menu and toolbar work well on mobile devices, props georgestephanis, see #20614</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/22262">22262</a></dd>
<dt>Author</dt> <dd>azaozz</dd>
<dt>Date</dt> <dd>2012-10-19 18:31:21 +0000 (Fri, 19 Oct 2012)</dd>
</dl>

<h3>Log Message</h3>
<pre>Make the admin menu and toolbar work well on mobile devices, props georgestephanis, see <a href="http://core.trac.wordpress.org/ticket/20614">#20614</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminjscommonjs">trunk/wp-admin/js/common.js</a></li>
<li><a href="#trunkwpincludesjsadminbarjs">trunk/wp-includes/js/admin-bar.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminjscommonjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/js/common.js (22261 => 22262)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/js/common.js        2012-10-18 13:06:39 UTC (rev 22261)
+++ trunk/wp-admin/js/common.js        2012-10-19 18:31:21 UTC (rev 22262)
</span><span class="lines">@@ -195,50 +195,68 @@
</span><span class="cx">                 }
</span><span class="cx">         });
</span><span class="cx"> 
</span><del>-        $('li.wp-has-submenu', menu).hoverIntent({
-                over: function(e){
-                        var b, h, o, f, m = $(this).find('.wp-submenu'), menutop, wintop, maxtop, top = parseInt( m.css('top'), 10 );
</del><ins>+        if ( 'ontouchstart' in window || /IEMobile\/[1-9]/.test(navigator.userAgent) ) { // touch screen device
+                // close any open submenus when touch/click is not on the menu
+                $(document.body).on('click.wp-mobile-hover', function(e) {
+                        if ( !$(e.target).closest('#adminmenu').length )
+                                menu.find('li.wp-has-submenu.opensub').removeClass('opensub');
+                });
</ins><span class="cx"> 
</span><del>-                        if ( isNaN(top) || top &gt; -5 ) // meaning the submenu is visible
-                                return;
</del><ins>+                menu.find('li.wp-has-submenu').on('click.wp-mobile-hover', function(e) {
+                        var el = $(this);
</ins><span class="cx"> 
</span><del>-                        menutop = $(this).offset().top;
-                        wintop = $(window).scrollTop();
-                        maxtop = menutop - wintop - 30; // max = make the top of the sub almost touch admin bar
</del><ins>+                        if ( !el.hasClass('opensub') ) {
+                                e.preventDefault();
+                                menu.find('li.wp-has-submenu.opensub').removeClass('opensub');
+                                el.addClass('opensub');
+                        }
+                });
+        } else {
+                menu.find('li.wp-has-submenu').hoverIntent({
+                        over: function(e){
+                                var b, h, o, f, m = $(this).find('.wp-submenu'), menutop, wintop, maxtop, top = parseInt( m.css('top'), 10 );
</ins><span class="cx"> 
</span><del>-                        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
</del><ins>+                                if ( isNaN(top) || top &gt; -5 ) // meaning the submenu is visible
+                                        return;
</ins><span class="cx"> 
</span><del>-                        if ( f &lt; (b - o) )
-                                o = b - f;
</del><ins>+                                menutop = $(this).offset().top;
+                                wintop = $(window).scrollTop();
+                                maxtop = menutop - wintop - 30; // max = make the top of the sub almost touch admin bar
</ins><span class="cx"> 
</span><del>-                        if ( o &gt; maxtop )
-                                o = maxtop;
</del><ins>+                                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
</ins><span class="cx"> 
</span><del>-                        if ( o &gt; 1 )
-                                m.css('margin-top', '-'+o+'px');
-                        else
-                                m.css('margin-top', '');
</del><ins>+                                if ( f &lt; (b - o) )
+                                        o = b - f;
</ins><span class="cx"> 
</span><del>-                        menu.find('li.menu-top').removeClass('opensub');
-                        $(this).addClass('opensub');
-                },
-                out: function(){
-                        $(this).removeClass('opensub').find('.wp-submenu').css('margin-top', '');
-                },
-                timeout: 200,
-                sensitivity: 7,
-                interval: 90
-        });
</del><ins>+                                if ( o &gt; maxtop )
+                                        o = maxtop;
</ins><span class="cx"> 
</span><del>-        menu.on('focus.adminmenu', '.wp-submenu a', function(e){
-                $(e.target).closest('li.menu-top').addClass('opensub');
-        }).on('blur.adminmenu', '.wp-submenu a', function(e){
-                $(e.target).closest('li.menu-top').removeClass('opensub');
-        });
</del><ins>+                                if ( o &gt; 1 )
+                                        m.css('margin-top', '-'+o+'px');
+                                else
+                                        m.css('margin-top', '');
</ins><span class="cx"> 
</span><ins>+                                menu.find('li.menu-top').removeClass('opensub');
+                                $(this).addClass('opensub');
+                        },
+                        out: function(){
+                                $(this).removeClass('opensub').find('.wp-submenu').css('margin-top', '');
+                        },
+                        timeout: 200,
+                        sensitivity: 7,
+                        interval: 90
+                });
+                
+                menu.on('focus.adminmenu', '.wp-submenu a', function(e){
+                        $(e.target).closest('li.menu-top').addClass('opensub');
+                }).on('blur.adminmenu', '.wp-submenu a', function(e){
+                        $(e.target).closest('li.menu-top').removeClass('opensub');
+                });
+        }
+
</ins><span class="cx">         // Move .updated and .error alert boxes. Don't move boxes designed to be inline.
</span><span class="cx">         $('div.wrap h2:first').nextAll('div.updated, div.error').addClass('below-h2');
</span><span class="cx">         $('div.updated, div.error').not('.below-h2, .inline').insertAfter( $('div.wrap h2:first') );
</span></span></pre></div>
<a id="trunkwpincludesjsadminbarjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/admin-bar.js (22261 => 22262)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/admin-bar.js        2012-10-18 13:06:39 UTC (rev 22261)
+++ trunk/wp-includes/js/admin-bar.js        2012-10-19 18:31:21 UTC (rev 22262)
</span><span class="lines">@@ -4,24 +4,46 @@
</span><span class="cx">                 (function(a){a.fn.hoverIntent=function(l,j){var m={sensitivity:7,interval:100,timeout:0};m=a.extend(m,j?{over:l,out:j}:l);var o,n,h,d;var e=function(f){o=f.pageX;n=f.pageY};var c=function(g,f){f.hoverIntent_t=clearTimeout(f.hoverIntent_t);if((Math.abs(h-o)+Math.abs(d-n))&lt;m.sensitivity){a(f).unbind(&quot;mousemove&quot;,e);f.hoverIntent_s=1;return m.over.apply(f,[g])}else{h=o;d=n;f.hoverIntent_t=setTimeout(function(){c(g,f)},m.interval)}};var i=function(g,f){f.hoverIntent_t=clearTimeout(f.hoverIntent_t);f.hoverIntent_s=0;return m.out.apply(f,[g])};var b=function(q){var f=this;var g=(q.type==&quot;mouseover&quot;?q.fromElement:q.toElement)||q.relatedTarget;while(g&amp;&amp;g!=this){try{g=g.parentNode}catch(q){g=this}}if(g==this){if(a.browser.mozilla){if(q.type==&quot;mouseout&quot;){f.mtout=setTimeout(function(){k(q,f)},30)}else{if(f.mtout){f.mtout=clearTimeout(f.mtout)}}}return}else{if(f.mtout){f.mtout=clearTimeout(f.mtout)}k(q,f)}};var k=function
 (p,f){var g=jQuery.extend({},p);if(f.hoverIntent_t){f.hoverIntent_t=clearTimeout(f.hoverIntent_t)}if(p.type==&quot;mouseover&quot;){h=g.pageX;d=g.pageY;a(f).bind(&quot;mousemove&quot;,e);if(f.hoverIntent_s!=1){f.hoverIntent_t=setTimeout(function(){c(g,f)},m.interval)}}else{a(f).unbind(&quot;mousemove&quot;,e);if(f.hoverIntent_s==1){f.hoverIntent_t=setTimeout(function(){i(g,f)},m.timeout)}}};return this.mouseover(b).mouseout(b)}})(jQuery);
</span><span class="cx"> 
</span><span class="cx">         jQuery(document).ready(function($){
</span><del>-                var refresh = function(i, el){ // force the browser to refresh the tabbing index
</del><ins>+                var adminbar = $('#wpadminbar'), refresh;
+
+                refresh = function(i, el){ // force the browser to refresh the tabbing index
</ins><span class="cx">                         var node = $(el), tab = node.attr('tabindex');
</span><span class="cx">                         if ( tab )
</span><span class="cx">                                 node.attr('tabindex', '0').attr('tabindex', tab);
</span><span class="cx">                 };
</span><span class="cx"> 
</span><del>-                $('#wpadminbar').removeClass('nojq').removeClass('nojs').find('li.menupop').hoverIntent({
-                        over: function(e){
-                                $(this).addClass('hover');
-                        },
-                        out: function(e){
-                                $(this).removeClass('hover');
-                        },
-                        timeout: 180,
-                        sensitivity: 7,
-                        interval: 100
-                });
</del><ins>+                adminbar.removeClass('nojq').removeClass('nojs');
+                
+                if ( 'ontouchstart' in window || /IEMobile\/[1-9]/.test(navigator.userAgent) ) { // touch screen device
+                        // close any open drop-downs when the click/touch is not on the toolbar
+                        $(document.body).on('click.wp-mobile-hover', function(e) {
+                                if ( !$(e.target).closest('#wpadminbar').length )
+                                        adminbar.find('li.menupop.hover').removeClass('hover');
+                        });
</ins><span class="cx"> 
</span><ins>+                        adminbar.find('li.menupop').on('click.wp-mobile-hover', function(e) {
+                                var el = $(this);
+
+                                if ( !el.hasClass('hover') ) {
+                                        e.preventDefault();
+                                        adminbar.find('li.menupop.hover').removeClass('hover');
+                                        el.addClass('hover');
+                                }
+                        });
+                } else {
+                        adminbar.find('li.menupop').hoverIntent({
+                                over: function(e){
+                                        $(this).addClass('hover');
+                                },
+                                out: function(e){
+                                        $(this).removeClass('hover');
+                                },
+                                timeout: 180,
+                                sensitivity: 7,
+                                interval: 100
+                        });
+                }
+
</ins><span class="cx">                 $('#wp-admin-bar-get-shortlink').click(function(e){
</span><span class="cx">                         e.preventDefault();
</span><span class="cx">                         $(this).addClass('selected').children('.shortlink-input').blur(function(){
</span><span class="lines">@@ -84,9 +106,9 @@
</span><span class="cx"> } else {
</span><span class="cx">         (function(d, w) {
</span><span class="cx">                 var addEvent = function( obj, type, fn ) {
</span><del>-                        if (obj.addEventListener)
</del><ins>+                        if ( obj.addEventListener )
</ins><span class="cx">                                 obj.addEventListener(type, fn, false);
</span><del>-                        else if (obj.attachEvent)
</del><ins>+                        else if ( obj.attachEvent )
</ins><span class="cx">                                 obj.attachEvent('on' + type, function() { return fn.call(obj, window.event);});
</span><span class="cx">                 },
</span><span class="cx"> 
</span><span class="lines">@@ -98,9 +120,10 @@
</span><span class="cx">                  */
</span><span class="cx">                 getTOID = function(el) {
</span><span class="cx">                         var i = q.length;
</span><del>-                        while( i-- )
</del><ins>+                        while ( i-- ) {
</ins><span class="cx">                                 if ( q[i] &amp;&amp; el == q[i][1] )
</span><span class="cx">                                         return q[i][0];
</span><ins>+                        }
</ins><span class="cx">                         return false;
</span><span class="cx">                 },
</span><span class="cx"> 
</span><span class="lines">@@ -110,7 +133,7 @@
</span><span class="cx">                                 ancestorLength = 0;
</span><span class="cx"> 
</span><span class="cx">                         while ( t &amp;&amp; t != aB &amp;&amp; t != d ) {
</span><del>-                                if( 'LI' == t.nodeName.toUpperCase() ) {
</del><ins>+                                if ( 'LI' == t.nodeName.toUpperCase() ) {
</ins><span class="cx">                                         ancestors[ ancestors.length ] = t;
</span><span class="cx">                                         id = getTOID(t);
</span><span class="cx">                                         if ( id )
</span><span class="lines">@@ -151,7 +174,7 @@
</span><span class="cx"> 
</span><span class="cx">                 removeHoverClass = function(t) {
</span><span class="cx">                         while ( t &amp;&amp; t != aB &amp;&amp; t != d ) {
</span><del>-                                if( 'LI' == t.nodeName.toUpperCase() ) {
</del><ins>+                                if ( 'LI' == t.nodeName.toUpperCase() ) {
</ins><span class="cx">                                         (function(t) {
</span><span class="cx">                                                 var to = setTimeout(function() {
</span><span class="cx">                                                         t.className = t.className ? t.className.replace(hc, '') : '';
</span></span></pre>
</div>
</div>

</body>
</html>