Ticket #20614: 20614-5.patch

File 20614-5.patch, 8.0 KB (added by azaozz, 7 months ago)

Having stopPropagation() when "touching" menu parents works well but is not ideal in case another script uses touch events in the menu or toolbar

  • wp-admin/js/common.js

     
    195195                } 
    196196        }); 
    197197 
    198         $('li.wp-has-submenu', menu).hoverIntent({ 
    199                 over: function(e){ 
    200                         var b, h, o, f, m = $(this).find('.wp-submenu'), menutop, wintop, maxtop, top = parseInt( m.css('top'), 10 ); 
     198        if ( 'ontouchstart' in window ) { // touch screen device 
     199                // close any open submenus when touch/click is not on the menu 
     200                $(document.body).on('touchstart.wp-mobile-hover', function(e) { 
     201                        if ( !$(e.target).closest('#adminmenu').length ) 
     202                                menu.find('li.wp-has-submenu.opensub').removeClass('opensub'); 
     203                }); 
    201204 
    202                         if ( isNaN(top) || top > -5 ) // meaning the submenu is visible 
    203                                 return; 
     205                menu.find('li.wp-has-submenu').on('touchstart.wp-mobile-hover', function(e) { 
     206                        var el = $(this); 
    204207 
    205                         menutop = $(this).offset().top; 
    206                         wintop = $(window).scrollTop(); 
    207                         maxtop = menutop - wintop - 30; // max = make the top of the sub almost touch admin bar 
     208                        if ( !el.hasClass('opensub') ) { 
     209                                e.preventDefault(); 
     210                                menu.find('li.wp-has-submenu.opensub').removeClass('opensub'); 
     211                                el.addClass('opensub'); 
     212                        } 
     213                }); 
     214        } else { 
     215                menu.find('li.wp-has-submenu').hoverIntent({ 
     216                        over: function(e){ 
     217                                var b, h, o, f, m = $(this).find('.wp-submenu'), menutop, wintop, maxtop, top = parseInt( m.css('top'), 10 ); 
    208218 
    209                         b = menutop + m.height() + 1; // Bottom offset of the menu 
    210                         h = $('#wpwrap').height(); // Height of the entire page 
    211                         o = 60 + b - h; 
    212                         f = $(window).height() + wintop - 15; // The fold 
     219                                if ( isNaN(top) || top > -5 ) // meaning the submenu is visible 
     220                                        return; 
    213221 
    214                         if ( f < (b - o) ) 
    215                                 o = b - f; 
     222                                menutop = $(this).offset().top; 
     223                                wintop = $(window).scrollTop(); 
     224                                maxtop = menutop - wintop - 30; // max = make the top of the sub almost touch admin bar 
    216225 
    217                         if ( o > maxtop ) 
    218                                 o = maxtop; 
     226                                b = menutop + m.height() + 1; // Bottom offset of the menu 
     227                                h = $('#wpwrap').height(); // Height of the entire page 
     228                                o = 60 + b - h; 
     229                                f = $(window).height() + wintop - 15; // The fold 
    219230 
    220                         if ( o > 1 ) 
    221                                 m.css('margin-top', '-'+o+'px'); 
    222                         else 
    223                                 m.css('margin-top', ''); 
     231                                if ( f < (b - o) ) 
     232                                        o = b - f; 
    224233 
    225                         menu.find('li.menu-top').removeClass('opensub'); 
    226                         $(this).addClass('opensub'); 
    227                 }, 
    228                 out: function(){ 
    229                         $(this).removeClass('opensub').find('.wp-submenu').css('margin-top', ''); 
    230                 }, 
    231                 timeout: 200, 
    232                 sensitivity: 7, 
    233                 interval: 90 
    234         }); 
     234                                if ( o > maxtop ) 
     235                                        o = maxtop; 
    235236 
    236         menu.on('focus.adminmenu', '.wp-submenu a', function(e){ 
    237                 $(e.target).closest('li.menu-top').addClass('opensub'); 
    238         }).on('blur.adminmenu', '.wp-submenu a', function(e){ 
    239                 $(e.target).closest('li.menu-top').removeClass('opensub'); 
    240         }); 
     237                                if ( o > 1 ) 
     238                                        m.css('margin-top', '-'+o+'px'); 
     239                                else 
     240                                        m.css('margin-top', ''); 
    241241 
     242                                menu.find('li.menu-top').removeClass('opensub'); 
     243                                $(this).addClass('opensub'); 
     244                        }, 
     245                        out: function(){ 
     246                                $(this).removeClass('opensub').find('.wp-submenu').css('margin-top', ''); 
     247                        }, 
     248                        timeout: 200, 
     249                        sensitivity: 7, 
     250                        interval: 90 
     251                }); 
     252                 
     253                menu.on('focus.adminmenu', '.wp-submenu a', function(e){ 
     254                        $(e.target).closest('li.menu-top').addClass('opensub'); 
     255                }).on('blur.adminmenu', '.wp-submenu a', function(e){ 
     256                        $(e.target).closest('li.menu-top').removeClass('opensub'); 
     257                }); 
     258        } 
     259 
    242260        // Move .updated and .error alert boxes. Don't move boxes designed to be inline. 
    243261        $('div.wrap h2:first').nextAll('div.updated, div.error').addClass('below-h2'); 
    244262        $('div.updated, div.error').not('.below-h2, .inline').insertAfter( $('div.wrap h2:first') ); 
  • wp-includes/js/admin-bar.js

     
    44                (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))<m.sensitivity){a(f).unbind("mousemove",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=="mouseover"?q.fromElement:q.toElement)||q.relatedTarget;while(g&&g!=this){try{g=g.parentNode}catch(q){g=this}}if(g==this){if(a.browser.mozilla){if(q.type=="mouseout"){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=="mouseover"){h=g.pageX;d=g.pageY;a(f).bind("mousemove",e);if(f.hoverIntent_s!=1){f.hoverIntent_t=setTimeout(function(){c(g,f)},m.interval)}}else{a(f).unbind("mousemove",e);if(f.hoverIntent_s==1){f.hoverIntent_t=setTimeout(function(){i(g,f)},m.timeout)}}};return this.mouseover(b).mouseout(b)}})(jQuery); 
    55 
    66        jQuery(document).ready(function($){ 
    7                 var refresh = function(i, el){ // force the browser to refresh the tabbing index 
     7                var adminbar = $('#wpadminbar'), refresh = function(i, el){ // force the browser to refresh the tabbing index 
    88                        var node = $(el), tab = node.attr('tabindex'); 
    99                        if ( tab ) 
    1010                                node.attr('tabindex', '0').attr('tabindex', tab); 
    1111                }; 
    1212 
    13                 $('#wpadminbar').removeClass('nojq').removeClass('nojs').find('li.menupop').hoverIntent({ 
    14                         over: function(e){ 
    15                                 $(this).addClass('hover'); 
    16                         }, 
    17                         out: function(e){ 
    18                                 $(this).removeClass('hover'); 
    19                         }, 
    20                         timeout: 180, 
    21                         sensitivity: 7, 
    22                         interval: 100 
    23                 }); 
     13                adminbar.removeClass('nojq').removeClass('nojs'); 
     14                 
     15                if ( 'ontouchstart' in window ) { // touch screen device 
     16                        // close any open drop-downs when the click/touch is not on the toolbar 
     17                        $(document.body).on('touchstart.wp-mobile-hover', function(e) { 
     18                                if ( !$(e.target).closest('#wpadminbar').length ) 
     19                                        adminbar.find('li.menupop.hover').removeClass('hover'); 
     20                        }); 
    2421 
     22                        adminbar.find('li.menupop').on('touchstart.wp-mobile-hover', function(e) { 
     23                                var el = $(this); 
     24 
     25                                if ( !el.hasClass('hover') ) { 
     26                                        e.preventDefault(); 
     27                                        adminbar.find('li.menupop.hover').removeClass('hover'); 
     28                                        el.addClass('hover'); 
     29                                } 
     30                        }); 
     31                } else { 
     32                        adminbar.find('li.menupop').hoverIntent({ 
     33                                over: function(e){ 
     34                                        $(this).addClass('hover'); 
     35                                }, 
     36                                out: function(e){ 
     37                                        $(this).removeClass('hover'); 
     38                                }, 
     39                                timeout: 180, 
     40                                sensitivity: 7, 
     41                                interval: 100 
     42                        }); 
     43                } 
     44 
    2545                $('#wp-admin-bar-get-shortlink').click(function(e){ 
    2646                        e.preventDefault(); 
    2747                        $(this).addClass('selected').children('.shortlink-input').blur(function(){ 
     
    84104} else { 
    85105        (function(d, w) { 
    86106                var addEvent = function( obj, type, fn ) { 
    87                         if (obj.addEventListener) 
     107                        if ( obj.addEventListener ) 
    88108                                obj.addEventListener(type, fn, false); 
    89                         else if (obj.attachEvent) 
     109                        else if ( obj.attachEvent ) 
    90110                                obj.attachEvent('on' + type, function() { return fn.call(obj, window.event);}); 
    91111                }, 
    92112 
     
    98118                 */ 
    99119                getTOID = function(el) { 
    100120                        var i = q.length; 
    101                         while( i-- ) 
     121                        while ( i-- ) { 
    102122                                if ( q[i] && el == q[i][1] ) 
    103123                                        return q[i][0]; 
     124                        } 
    104125                        return false; 
    105126                }, 
    106127 
     
    110131                                ancestorLength = 0; 
    111132 
    112133                        while ( t && t != aB && t != d ) { 
    113                                 if( 'LI' == t.nodeName.toUpperCase() ) { 
     134                                if ( 'LI' == t.nodeName.toUpperCase() ) { 
    114135                                        ancestors[ ancestors.length ] = t; 
    115136                                        id = getTOID(t); 
    116137                                        if ( id ) 
     
    151172 
    152173                removeHoverClass = function(t) { 
    153174                        while ( t && t != aB && t != d ) { 
    154                                 if( 'LI' == t.nodeName.toUpperCase() ) { 
     175                                if ( 'LI' == t.nodeName.toUpperCase() ) { 
    155176                                        (function(t) { 
    156177                                                var to = setTimeout(function() { 
    157178                                                        t.className = t.className ? t.className.replace(hc, '') : '';