Skip to content
This repository has been archived by the owner on Feb 23, 2021. It is now read-only.

Commit

Permalink
Merge pull request #227 from gskema/dev
Browse files Browse the repository at this point in the history
[-] MO: Fix cttopmenu link handler in collapsed view
  • Loading branch information
gskema committed Jun 9, 2016
2 parents a2c5aad + 43e09b1 commit 94bedac
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions modules/cttopmenu/views/js/fo.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ $(function() {
e.stopPropagation();
});

// Detect when menu is collapsed
var buffer = null;
var $navbarHeader = $menu.find('.navbar-header');

// Initial detection of collapse top menu
detectCollapsedMenu();

// Detect collapsed menu every 250ms using debounce
$(window).on('resize', function() {
clearTimeout(buffer);
buffer = setTimeout(detectCollapsedMenu, 250);
Expand All @@ -36,15 +38,19 @@ $(function() {
}
});

// @TODO Refactor or remove on hover functionality
// @TODO Refactor responsive collapsed hover, also multiline (overflown) menu
// Option: show dropdowns on mouse enter
// @TODO This functionality is experimental and may contain bugs. Bootstrap does not support hover dropdowns.
if (useHover) {
bindOnHoverMenu();
}

// Binds all the necessary events handlers for the menu dropdowns to work with hover events
function bindOnHoverMenu() {
var $linksToggle = $links.filter('.dropdown-toggle');
var $dropdowns = $menu.find('.dropdown');

// On hover over dropdown links, we must open them, unless in mobile (collapsed view)
$links.on('mouseenter', function() {

// In collapsed view, use the default behaviour
if (menuIsCollapsed) {
return true;
Expand All @@ -62,13 +68,20 @@ $(function() {

});

// On leaving any links, make sure the dropdown (if any) is closed
$dropdowns.on('mouseleave', function() {
!menuIsCollapsed && $(this).removeClass('open');
});

// @TODO On click, default behaviour
$linksToggle.on('click', function() {
window.location = $(this).attr('href');
// Make sure that clicking a dropdown link opens that link instead of toggling the dropdown
$linksToggle.on('click', function(e) {
if (menuIsCollapsed) {
return;
}

// Prevent Bootstrap event handler, which closes the dropdown.
// Default browser handler will fire (link will be opened)
e.stopImmediatePropagation();
});
}

Expand Down

0 comments on commit 94bedac

Please sign in to comment.