WordPress core中的菜单在哪里附加了悬停意图
以下两个文件分别将hoverIntent作为工具栏和菜单的单击处理程序进行附加。
Admin Bar
Theadmin-bar.js 文件在的第13行的顶部栏上设置悬停意图admin-bar.js.
Admin Menu
Thecommon.js 文件在的第185行的侧栏菜单上设置悬停意图common.js.
如何从工具栏和菜单中删除HoverIntent WordPress在document ready上为工具栏和菜单附加了HoverIntent处理程序,因此如果我们要重新绑定这些点击处理程序,我们需要确保在WordPress完成JS业务后再这样做。
确保脚本在正确的时间加载的最简单方法是在管理和设置中启动一个排队admin-bar 和common 脚本作为从属项。
在管理头设置中排队所需的依赖项
将回调附加到
admin_head 并启动一个包含两个必需依赖项的队列。
add_action( \'admin_head\', \'disable_admin_hoverintent\' );
function disable_admin_hoverintent() {
    wp_enqueue_script( 
        // Script handle
        \'disable-admin-hoverintent\', 
        // Script URL
        get_bloginfo( \'stylesheet_directory\' ).\'/disableadminhi.js\', 
        // Script dependancies
        array( \'admin-bar\', \'common\' ) 
    );
}
 创建自定义Javascript文件在主题文件夹中创建一个文件,并将其命名为与上面队列中的文件相匹配,在我的示例中,我使用了名称
disableadminhi.js, 但如果您不想将队列放在主题文件夹中,欢迎您调整该队列和/或将其重新放置到其他位置。
的Javascriptdisableadminhi.js
jQuery(document).ready(function($){
    $(\'#wpadminbar\').find(\'li.menupop\').hover( function(){
        $(this).toggleClass(\'hover\');
    });
    // Bring menu into scope(defined by common.js in wordpress)
    var menu;
    // Copy of the function from common.js, just without hoverIntent
    $(\'li.wp-has-submenu\', menu).hover(
        function(e){
            var b, h, o, f, m = $(this).find(\'.wp-submenu\'), menutop, wintop, maxtop;
            if ( !$(document.body).hasClass(\'folded\') && $(this).hasClass(\'wp-menu-open\') )
                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({\'marginTop\':\'-\'+o+\'px\'});
            else if ( m.css(\'marginTop\') )
                m.css({\'marginTop\':\'\'});
            m.addClass(\'sub-open\');
        },
        function(){
            $(this).find(\'.wp-submenu\').removeClass(\'sub-open\');
        }
    );
});
 享受更快的导航希望有帮助:)