Created
February 13, 2018 11:05
-
-
Save sveetch/6bfceebfa395f1bfcebbad0ef1a7dffd to your computer and use it in GitHub Desktop.
Hack on Foundation 6.4.x responsive navigation drilldown to open item for current page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function($) { | |
/* | |
* Initialize Foundation | |
*/ | |
$(document).foundation(); | |
/* | |
* Trick to automatically open drilldown menu directly on the current page panel. | |
* This is recursive, due to drilldown mechanics, it needs to open all sub menu | |
* to reach item. | |
* | |
* This requires: | |
* | |
* - Root menu (the 'ul' containing items to recurse) to have an id; | |
* - Toggle button container ('nav') to define menu id in 'data-responsive-auto_open' attribute; | |
* - Each 'li' to cross to reach current page item must have a 'active' class and a 'id'; | |
*/ | |
$('[data-responsive-toggle]').on('toggled.zf.responsiveToggle', function (e) { | |
// Find defined menu to scan if any | |
var target_menu = $(e.target).attr('data-responsive-auto_open'), | |
$menu = (target_menu) ? $('#'+target_menu) : null; | |
if($menu){ | |
// Cross every 'li' and open it to reach current page item | |
$menu.find('li.active').each(function(i){ | |
$('#'+ $(this).attr('id') +' > a').trigger('click.zf.drilldown'); | |
}); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment