Hi, I have it modified through css so nice_menus has the children from the parent menu also listed horizontally. Would there be a possibility to set the active-trail elements visible at page load and disappear on hover of primary elements that do not not have the class active-trail? After mouse out of the menu the active-trail elements would be set to visible again.

I actually have made this work by modifying the suckerrfish js file, but not in a very efficient way. I need some help with is if possible. I should only require 2, maybe 4, extra lines of jquery.

Kind regards,

Marius

Comments

mariusooms’s picture

This is what I'm adding currently in my own js file and it seems to work, but I wonder if there is a better way and if this should be by default for horizontal children? Also my javascripting is very noobiesh, so I'm positive this code could probably be rewritten to two lines :)

$(document).ready(function() {

  // Set active-trail visible on page load
  $('ul.nice-menu li.active-trail ul').show();
  $('ul.nice-menu li.active-trail ul').css('visibility', 'visible');
  
  // Bind the menu to mouseleave to set active-trail visible when done navigating
  $('ul.nice-menu').bind("mouseleave", function(){
    var $active = $('ul.nice-menu li.active-trail ul');

    // Set the timer to the value specified in the admin settings
    $active.animate({ opacity: 0 }, 800, function() {
      $('ul.nice-menu li.active-trail ul').animate({ opacity: 1.0 }, 0);
      $('ul.nice-menu li.active-trail ul').css('visibility', 'visible');
      $('ul.nice-menu li.active-trail ul').show();
    });

  });

});
jenpasch’s picture

Did you add the above .js to the nice_menus.js? Would you mind explaining what you did? This indeed seems like a very useful feature for the downdown/horizontal menu style.
many thanks!
jen

mariusooms’s picture

Hi Jen,

Though not perfect it works for me somewhat. I have a theme javascript file with all my jquery functions. E.g. you can just create a global.js file in your theme folder and add it through your info file:

scripts[] = global.js

This loads the javascript file in your header.

As far as the code goes, this is my current code:

$(document).ready(function() {

  // Set active-trail visible on page load
  // This only sets the secondary list of the active trail to visible
  $('ul.nice-menu li.active-trail ul').show();
  $('ul.nice-menu li.active-trail ul').css('visibility', 'visible');
 
  // Bind the menu to mouseleave to set active-trail visible when done navigating
  // Suckerfish will hide all secondary lists for you when hovering the main menu
  // So we want to repeat the initial behavior when done navigating
  $('ul.nice-menu').bind("mouseleave", function(){
    var $active = $('ul.nice-menu li.active-trail ul');

    // Set the timer to the value specified in the admin settings
    // This prevents overlap of the secondary menu items
    // The trick to make it work is that we set the active trail to visible inside the function
    $active.animate({ opacity: 1.0 }, 800, function() {
      $('ul.nice-menu li.active-trail ul').css('visibility', 'visible');
      $('ul.nice-menu li.active-trail ul').show();
    });

  });

});

I'm terrible at explaining this behavior. This article, http://www.learningjquery.com/2007/03/accordion-madness , should help you understand the basic jquery to show and hide behavior of menus.

As I said, it is not perfect, but it kinda works. Sometime the mouseevent is not binded properly when hovering in and out multiple times within the 800ms period.

I hope this vagly helps,

Marius

jenpasch’s picture

Thanks ever so much. Did you get the "active-trail" class through "Menu Trails" or hacking nice menus?

mariusooms’s picture

It is part of the suckerfish code which is included in the 6.x-2.x-dev branch.

add1sun’s picture

For this to get into NM we need an actual patch that can be applied to the nice_menus.js file.

aubjr_drupal’s picture

I used the code above in comment #3 in a site I built with Nice Menus and a secondary horizontal menu and for the most part it worked great. However, I came across a small bug. The secondary menu was not restored if I moused out of the ul.nice-menu (the primary menu in this case) from the li.active-trail element. The secondary menu, which is set to visibility:visible and display: block when you mouse over li.active-trail (as it should be), disappeared upon mouseout/mouseleave.

The visibility and display CSS value attached to $active appears to toggled back to hidden/none in suckerfish.js (in the Nice Menus module's js directory), line 104-105.

I don't have a solution yet, but I'm looking for one. I can set the delay higher than 600 and hope that the scripts fire in the order that allows it to reappear right after it's hidden by suckerfish.js, but it's not ideal.

Jonasvh’s picture

Just do it with CSS
You must only override the elemen.style.
See example of my css

#block-nice-menus-1 .active-trail ul {
display: block !important;
visibility: visible !important;
}

leozzz’s picture

i found a simply solution.

jQuery('ul.nice-menu li.active-trail').unbind();

add it to nice_menu.js

just unbind the active-trail, then the hover/mouseleave bugs will not happen again

final:
jQuery(document).ready(function() {

// Set active-trail visible on page load
// This only sets the secondary list of the active trail to visible
jQuery('ul.nice-menu li.active-trail ul').show();
jQuery('ul.nice-menu li.active-trail ul').css('visibility', 'visible');

// Bind the menu to mouseleave to set active-trail visible when done navigating
// Suckerfish will hide all secondary lists for you when hovering the main menu
// So we want to repeat the initial behavior when done navigating

jQuery('ul.nice-menu li.active-trail').unbind('mouseout');

jQuery('ul.nice-menu').bind("mouseleave", function(){
var jQueryactive = jQuery('ul.nice-menu li.active-trail ul');

// Set the timer to the value specified in the admin settings
// This prevents overlap of the secondary menu items
// The trick to make it work is that we set the active trail to visible inside the function
jQueryactive.animate({ opacity: 1.0 }, 10, function() {
jQuery('ul.nice-menu li.active-trail ul').css('visibility', 'visible');
jQuery('ul.nice-menu li.active-trail ul').show();
});

});

});

johnnydarkko’s picture

I implemented #9, but I was having an issue with the drop-down menu text overlapping because the active-trail menu would animate immediately animate back if the mouse ever leaves the ul. I used the trick from http://stackoverflow.com/questions/1273566/how-do-i-check-if-the-mouse-i... to add a delay. Hope this helps!

$(document).ready(function() {
	// Set active-trail visible on page load
	// This only sets the secondary list of the active trail to visible
	$('ul.nice-menu li.active-trail ul').show();
	$('ul.nice-menu li.active-trail ul').css('visibility', 'visible');

	// Bind the menu to mouseleave to set active-trail visible when done navigating
	// Suckerfish will hide all secondary lists for you when hovering the main menu
	// So we want to repeat the initial behavior when done navigating
	$('ul.nice-menu li.active-trail').unbind('mouseout');
	$('ul.nice-menu').bind('mouseenter', function(){
		clearTimeout($(this).data('timeoutId'));
		}).bind('mouseleave', function() {
			var timeoutId = setTimeout(function(){
			var $active = $('ul.nice-menu li.active-trail ul');
	
			// Set the timer to the value specified in the admin settings
			// This prevents overlap of the secondary menu items
			// The trick to make it work is that we set the active trail to visible inside the function
			$active.animate({
				opacity : 1.0
			}, 0, function() {
				$('ul.nice-menu li.active-trail ul').css('visibility', 'visible');
				$('ul.nice-menu li.active-trail ul').show();
			});
		}, 800);
		$(this).data('timeoutId',timeoutId);
	});
});
astonvictor’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

I'm closing it because the issue was created a long time ago without any further steps.

if you still need it then raise a new one.
thanks