'use strict';
!function ($) {
var Nest = {
Feather: function (menu) {
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'zf';
menu.attr('role', 'menubar');
var items = menu.find('li').attr({ 'role': 'menuitem' }),
subMenuClass = 'is-' + type + '-submenu',
subItemClass = subMenuClass + '-item',
hasSubClass = 'is-' + type + '-submenu-parent';
items.each(function () {
var $item = $(this),
$sub = $item.children('ul');
if ($sub.length) {
$item.addClass(hasSubClass).attr({
'aria-haspopup': true,
'aria-label': $item.children('a:first').text()
});
// Note: Drilldowns behave differently in how they hide, and so need
// additional attributes. We should look if this possibly over-generalized
// utility (Nest) is appropriate when we rework menus in 6.4
if (type === 'drilldown') {
$item.attr({ 'aria-expanded': false });
}
$sub.addClass('submenu ' + subMenuClass).attr({
'data-submenu': '',
'role': 'menu'
});
if (type === 'drilldown') {
$sub.attr({ 'aria-hidden': true });
}
}
if ($item.parent('[data-submenu]').length) {
$item.addClass('is-submenu-item ' + subItemClass);
}
});
return;
},
Burn: function (menu, type) {
var //items = menu.find('li'),
subMenuClass = 'is-' + type + '-submenu',
subItemClass = subMenuClass + '-item',
hasSubClass = 'is-' + type + '-submenu-parent';
menu.find('>li, .menu, .menu > li').removeClass(subMenuClass + ' ' + subItemClass + ' ' + hasSubClass + ' is-submenu-item submenu is-active').removeAttr('data-submenu').css('display', '');
// console.log( menu.find('.' + subMenuClass + ', .' + subItemClass + ', .has-submenu, .is-submenu-item, .submenu, [data-submenu]')
// .removeClass(subMenuClass + ' ' + subItemClass + ' has-submenu is-submenu-item submenu')
// .removeAttr('data-submenu'));
// items.each(function(){
// var $item = $(this),
// $sub = $item.children('ul');
// if($item.parent('[data-submenu]').length){
// $item.removeClass('is-submenu-item ' + subItemClass);
// }
// if($sub.length){
// $item.removeClass('has-submenu');
// $sub.removeClass('submenu ' + subMenuClass).removeAttr('data-submenu');
// }
// });
}
};
Foundation.Nest = Nest;
}(jQuery);
|