Skip to main content
Small tweaks (see edit)
Source Link
t31os
  • 18.7k
  • 3
  • 56
  • 68

WordPress loads a bunch of JS and the hoverintent scripts on document ready, it attaches athe hoverintent handler tohandlers for the bar and menu at that pointon document ready, so if we're going to rebind thethose click handlers we need to make sure we do so after WordPress has done it's JS business.

The easiest way to ensure that happensour script loads at the right time is to fire an enqueue in the admin and set thesetting admin-bar and common scripts as dependancies, this ensures our script is included after WordPress has included the two scripts in question.

Attach a callback to admin_head and fire an enqueue with 2the two required dependancies.

add_action( 'admin_head', 'disable_HoverIntent_on_AdminMenu''disable_admin_hoverintent' );

function disable_HoverIntent_on_AdminMenudisable_admin_hoverintent() {
    wp_enqueue_script( 
        // Script handle
        'disable-adminhoverintentadmin-'hoverintent', 
        // Script URL
        get_bloginfo( 'stylesheet_directory' ).'/disableadminhi.js', 
        // Script dependancies
        array( 'admin-bar', 'common' ) 
    );
}

WordPress loads a bunch of JS and the hoverintent scripts on document ready, it attaches a hoverintent handler to the bar and menu at that point, so if we're going to rebind the click handlers we need to make sure we do after WordPress has done it's JS business.

The easiest way to ensure that happens is to fire an enqueue in the admin and set the admin-bar and common scripts as dependancies, this ensures our script is included after WordPress has included the two scripts in question.

Attach a callback to admin_head and fire an enqueue with 2 dependancies.

add_action( 'admin_head', 'disable_HoverIntent_on_AdminMenu' );

function disable_HoverIntent_on_AdminMenu() {
    wp_enqueue_script( 'disable-adminhoverintent-', get_bloginfo( 'stylesheet_directory' ).'/disableadminhi.js', array( 'admin-bar', 'common' ) );
}

WordPress attaches the hoverintent handlers for the bar and menu on document ready, so if we're going to rebind those click handlers we need to make sure we do so after WordPress has done it's JS business.

The easiest way to ensure our script loads at the right time is to fire an enqueue in the admin and setting admin-bar and common scripts as dependancies.

Attach a callback to admin_head and fire an enqueue with the two required dependancies.

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' ) 
    );
}
Answer completed, new code, revised answer
Source Link
t31os
  • 18.7k
  • 3
  • 56
  • 68

The admin-bar.js file###Where is responsible for setting upHover Intent attached to the menus in WordPress core?

The following 2 files go about attaching hoverIntent functionality onas click handlers for the admin bar hereand menu respectively.

Admin Bar
The admin-bar.js file sets up Hover Intent on the top bar here on line 13 of admin-bar.js.

Admin Menu
The common.js file sets up Hover Intent on the side bar menu on line 185 of common.js.

###How to remove HoverIntent from both the bar and menu

WordPress loads a bunch of JS and the hoverintent scripts on Line 13document ready, it attaches a hoverintent handler to the bar and menu at that point, so if we're going to rebind the click handlers we need to make sure we do after WordPress has done it's JS business.

The easiest way to ensure that happens is to fire an enqueue in the admin and set the admin-bar and common scripts as dependancies, this ensures our script is included after WordPress has included the two scripts in question.

###Enqueue in admin head setting required dependancies

Attach a callback to admin_head and fire an enqueue with 2 dependancies.

add_action( 'admin_head', 'disable_HoverIntent_on_AdminMenu' );

function $disable_HoverIntent_on_AdminMenu('#wpadminbar') {
    wp_enqueue_script( 'disable-adminhoverintent-', get_bloginfo( 'stylesheet_directory' ).removeClass'/disableadminhi.js', array('nojq' 'admin-bar', 'common' ) );
}

###Create the custom Javascript file

Create a file in your theme's folder and name it to match the file in the above enqueue, in my example i've used the name disableadminhi.js, but you're welcome to adjust that and/or repoint the enqueue to somewhere else if you don't want to place it in the theme's folder.

Javascript for disableadminhi.js

jQuery(document).removeClassready('nojs'function($){
    $('#wpadminbar').find('li.menupop').hoverIntenthover( function(){
        over: function$(ethis){.toggleClass('hover');
    });
    // Bring menu into $scope(this)defined by common.addClass('hover'js in wordpress);
    var menu;
   } // Copy of the function from common.js, just without hoverIntent
    $('li.wp-has-submenu', menu).hover(
   out:     function(e){
            var b, h, o, f, m = $(this).removeClassfind('hover''.wp-submenu');, menutop, wintop, maxtop;

        },
    if ( !$(document.body).hasClass('folded') && timeout:$(this).hasClass('wp-menu-open') 180,)
        sensitivity: 7,       return;

        interval: 100   menutop = $(this).offset().top;
    }        wintop = $(window).scrollTop();

We can of course load up some of our own JS after the admin menu script is included and over-ride the hover functionality, like so..

            maxtop = menutop - wintop - 30; // Hookmax into= make the footer,top andof hookthe insub latealmost touch admin bar
add_action
            b = menutop + m.height() 'admin_footer',+ 'disable_HoverIntent_on_AdminMenu',1; 99999// Bottom offset of the menu
            h = $('#wpwrap').height(); // Height of the entire page
            o = 60 + b - h;
function disable_HoverIntent_on_AdminMenu           f = $(window).height() {+ wintop - 15; // The fold

    ?        if ( f < (b - o) )
                o = b - f;

            if ( o > maxtop )
    <script type="text/javascript">           o = maxtop;

    jQuery        if (document o > 1 )
                m.ready(functioncss($){'marginTop':'-'+o+'px'});
        $    else if ('#wpadminbar') m.findcss('li.menupop''marginTop').bind('hover',function( ){
            $    m.css(this{'marginTop':''});

            m.toggleClassaddClass('hover''sub-open');
        },
        function();{
    }        $(this).find('.wp-submenu').removeClass('sub-open');
    </script>    }
    <?php);
});

That so far just covers the admin bar, i'm going to move on and see if i can track down where it's set for the admin menu on the left to, i'll update this answer once i've figured that, i'm also going to wrap this stuff into an enqueue and i'll update my answer as appropriate once i've got the details figured out..###Enjoy faster navigation!

Answer pending update - watch this space Hope that helps.. :)

The admin-bar.js file is responsible for setting up the hoverIntent functionality on the admin bar here on Line 13.

    $('#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
    });

We can of course load up some of our own JS after the admin menu script is included and over-ride the hover functionality, like so..

// Hook into the footer, and hook in late
add_action( 'admin_footer', 'disable_HoverIntent_on_AdminMenu', 99999 );

function disable_HoverIntent_on_AdminMenu() {
    ?>
    <script type="text/javascript">
    jQuery(document).ready(function($){
        $('#wpadminbar').find('li.menupop').bind('hover',function(){
            $(this).toggleClass('hover');
        });
    });
    </script>
    <?php
}

That so far just covers the admin bar, i'm going to move on and see if i can track down where it's set for the admin menu on the left to, i'll update this answer once i've figured that, i'm also going to wrap this stuff into an enqueue and i'll update my answer as appropriate once i've got the details figured out..

Answer pending update - watch this space

###Where is Hover Intent attached to the menus in WordPress core?

The following 2 files go about attaching hoverIntent as click handlers for the bar and menu respectively.

Admin Bar
The admin-bar.js file sets up Hover Intent on the top bar here on line 13 of admin-bar.js.

Admin Menu
The common.js file sets up Hover Intent on the side bar menu on line 185 of common.js.

###How to remove HoverIntent from both the bar and menu

WordPress loads a bunch of JS and the hoverintent scripts on document ready, it attaches a hoverintent handler to the bar and menu at that point, so if we're going to rebind the click handlers we need to make sure we do after WordPress has done it's JS business.

The easiest way to ensure that happens is to fire an enqueue in the admin and set the admin-bar and common scripts as dependancies, this ensures our script is included after WordPress has included the two scripts in question.

###Enqueue in admin head setting required dependancies

Attach a callback to admin_head and fire an enqueue with 2 dependancies.

add_action( 'admin_head', 'disable_HoverIntent_on_AdminMenu' );

function disable_HoverIntent_on_AdminMenu() {
    wp_enqueue_script( 'disable-adminhoverintent-', get_bloginfo( 'stylesheet_directory' ).'/disableadminhi.js', array( 'admin-bar', 'common' ) );
}

###Create the custom Javascript file

Create a file in your theme's folder and name it to match the file in the above enqueue, in my example i've used the name disableadminhi.js, but you're welcome to adjust that and/or repoint the enqueue to somewhere else if you don't want to place it in the theme's folder.

Javascript for disableadminhi.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');
        }
    );
});

###Enjoy faster navigation!

Hope that helps.. :)

Update, see answer
Source Link
t31os
  • 18.7k
  • 3
  • 56
  • 68

Personally i don't mind the hoverIntent script, always found that instant hover effect annoying when you're just passing over a link, but i can understand if you prefer to be able to move around quickly.

The admin-bar.js file is responsible for setting up the hoverIntent functionality on the admin menubar here on Line 13.

    $('#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
    });

We can of course load up some of our own JS after the admin menu script is included and over-ride the hover functionality, like so..

// Hook into the footer, and hook in late
add_action( 'admin_footer', 'disable_HoverIntent_on_AdminMenu', 99999 );

function disable_HoverIntent_on_AdminMenu() {
    ?>
    <script type="text/javascript">
        jQuery(document).ready(function($){
            $('#wpadminbar').find('li.menupop').hover( 
                function(e){
                    $(this).addClassbind('hover');
                },
                function(e){
                    $(this).removeClasstoggleClass('hover');
                }
            );
        });
    </script>
    <?php
}

I've tested thisThat so far just covers the admin bar, i'm going to move on 3.3 and it doessee if i can track down where it's set for the trick in my installationadmin menu on the left to, so let me know if you have problems making it work.

Of coursei'll update this answer once i've figured that, you couldi'm also plonk that codegoing to wrap this stuff into a JS file, then call wp_enqueue_script instead, with the admin menu javascript setan enqueue and i'll update my answer as a dependancy ensuring it always get's loaded afterappropriate once i've got the admin menu(it won't work if it fires to early)details figured out..

Hope that helps.. :)Answer pending update - watch this space

Personally i don't mind the hoverIntent script, always found that instant hover effect annoying when you're just passing over a link, but i can understand if you prefer to be able to move around quickly.

The admin-bar.js file is responsible for setting up the hoverIntent functionality on the admin menu here on Line 13.

    $('#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
    });

We can of course load up some of our own JS after the admin menu script is included and over-ride the hover functionality, like so..

// Hook into the footer, and hook in late
add_action( 'admin_footer', 'disable_HoverIntent_on_AdminMenu', 99999 );

function disable_HoverIntent_on_AdminMenu() {
    ?>
    <script type="text/javascript">
        jQuery(document).ready(function($){
            $('#wpadminbar').find('li.menupop').hover( 
                function(e){
                    $(this).addClass('hover');
                },
                function(e){
                    $(this).removeClass('hover');
                }
            );
        });
    </script>
    <?php
}

I've tested this on 3.3 and it does the trick in my installation, so let me know if you have problems making it work.

Of course, you could also plonk that code into a JS file, then call wp_enqueue_script instead, with the admin menu javascript set as a dependancy ensuring it always get's loaded after the admin menu(it won't work if it fires to early).

Hope that helps.. :)

The admin-bar.js file is responsible for setting up the hoverIntent functionality on the admin bar here on Line 13.

    $('#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
    });

We can of course load up some of our own JS after the admin menu script is included and over-ride the hover functionality, like so..

// Hook into the footer, and hook in late
add_action( 'admin_footer', 'disable_HoverIntent_on_AdminMenu', 99999 );

function disable_HoverIntent_on_AdminMenu() {
    ?>
    <script type="text/javascript">
    jQuery(document).ready(function($){
        $('#wpadminbar').find('li.menupop').bind('hover',function(){
            $(this).toggleClass('hover');
        });
    });
    </script>
    <?php
}

That so far just covers the admin bar, i'm going to move on and see if i can track down where it's set for the admin menu on the left to, i'll update this answer once i've figured that, i'm also going to wrap this stuff into an enqueue and i'll update my answer as appropriate once i've got the details figured out..

Answer pending update - watch this space

Source Link
t31os
  • 18.7k
  • 3
  • 56
  • 68
Loading