XF 2.1 Expand navigation menus on hover

bzcomputers

Well-known member
Was trying to reuse some code which allows navigation menus to expand on hover (no need to click to view sub-menu).

The code in it's current form doesn't work on XenForo 2.1, I think I'm just missing something basic. Figured someone here would see it quicker than me.

Code:
<script>
jQuery(".p-navE1").hover(
  function () {
    jQuery(this).find( '.menu-content' ).show();
  },
  function () {
    jQuery(this).find( '.menu-content' ).hide();
  }
);
</script>
 
I use this temp

JavaScript:
<xf:js>
$( ".p-nav-list>li>.p-navEl").hover(function() {
    // nav
    if ($(this).attr('data-has-children') && $(this).not('.is-menuOpen')){
        // has children
        $(this).find( ".p-navEl-splitTrigger[aria-expanded='false']:not(.is-menuOpen)" ).trigger( "click" );
        $(this).find( ".p-navEl-linkHolder[aria-expanded='false']:not(.is-menuOpen)" ).trigger( "click" );
    }
});
</xf:js>
 
I have done what I found here:

Works exactly as in WordPress!
 
Would be good if someone optimized it
JavaScript:
$( ".p-nav-list>li" ).hover(function() {
    that = $(this).find('.p-navEl');
    if (that.attr('data-has-children') && that.not('.is-menuOpen')){
        // has children
        that.find( ".p-navEl-splitTrigger[aria-expanded='false']:not(.is-menuOpen)" ).trigger( "click" );
        that.find( ".p-navEl-linkHolder[aria-expanded='false']:not(.is-menuOpen)" ).trigger( "click" );
    }
    $( ".menu.is-active").mouseleave(function() {
        $( ".menuOutsideClicker").trigger( "click" );
        $( this).mouseleave(function() {
            $( ".menuOutsideClicker").trigger( "click" );
        });
    });
});
 
Back
Top Bottom