nightTab/js/menu.js

80 lines
1.8 KiB
JavaScript
Raw Normal View History

var menu = (function() {
2019-01-04 17:24:05 +01:00
var _bind = function() {
var allMenuNavButton = helper.eA(".menu-nav-button");
2019-01-14 19:22:39 +01:00
var menuClose = helper.e(".menu-close");
2019-01-04 17:24:05 +01:00
allMenuNavButton.forEach(function(arrayItem, index) {
arrayItem.addEventListener("click", function() {
_tab(this);
}, false);
});
2019-01-14 19:22:39 +01:00
menuClose.addEventListener("click", function() {
close();
shade.destroy();
}, false);
2019-01-04 17:24:05 +01:00
};
var _tab = function(button) {
var allMenuNavButton = helper.eA(".menu-nav-button");
2019-01-04 20:40:49 +01:00
var allMenuContentArea = helper.eA(".menu-content-area");
2019-01-04 17:24:05 +01:00
var target = helper.e(button.dataset.target);
allMenuNavButton.forEach(function(arrayItem, index) {
helper.removeClass(arrayItem, "active");
});
2019-01-04 20:40:49 +01:00
allMenuContentArea.forEach(function(arrayItem, index) {
helper.addClass(arrayItem, "is-hidden");
2019-01-04 17:24:05 +01:00
});
helper.addClass(button, "active");
2019-01-04 20:40:49 +01:00
helper.removeClass(target, "is-hidden");
2019-01-04 17:24:05 +01:00
};
var close = function() {
state.get().menu.active = false;
render();
};
var open = function() {
state.get().menu.active = true;
render();
};
var toggle = function() {
if (state.get().menu.active) {
state.get().menu.active = false;
} else {
state.get().menu.active = true;
};
render();
};
var render = function() {
var html = helper.e("html");
if (state.get().menu.active) {
helper.addClass(html, "is-menu-open");
helper.e(".menu-nav-button.active").focus();
shade.render({
action: function() {
close();
render();
}
});
} else {
helper.removeClass(html, "is-menu-open");
};
};
var init = function() {
2019-01-04 17:24:05 +01:00
_bind();
close();
};
return {
init: init,
close: close,
open: open,
toggle: toggle,
render: render
};
})();