66 lines
2.1 KiB
JavaScript
66 lines
2.1 KiB
JavaScript
|
/**
|
||
|
* Created by Aleksey Chichenkov <a.chichenkov@initi.ru> on 9/19/18.
|
||
|
*/
|
||
|
window.onload = function () {
|
||
|
create();
|
||
|
};
|
||
|
|
||
|
function create() {
|
||
|
var hop = location.href.split("/").pop().split(".");
|
||
|
hop.pop();
|
||
|
var current_manager = hop[hop.length - 1];
|
||
|
var parent = hop[hop.length - 2];
|
||
|
|
||
|
var dropdown = document.querySelectorAll('.dropdown');
|
||
|
var dropdownArray = Array.prototype.slice.call(dropdown, 0);
|
||
|
dropdownArray.forEach(function (el) {
|
||
|
var button = el.querySelector('a.menu-title');
|
||
|
var menu = el.querySelector('.dropdown-menu');
|
||
|
|
||
|
if (!menu) return;
|
||
|
|
||
|
var arrow = button.querySelector('i.icon-arrow');
|
||
|
var item = menu.getAttribute("id");
|
||
|
|
||
|
var show = true;
|
||
|
var cur_parent = menu.parentNode.children[1] && menu.parentNode.children[1].getAttribute("id");
|
||
|
if (cur_parent) {
|
||
|
show = cur_parent != parent;
|
||
|
}
|
||
|
|
||
|
if (show && item == current_manager || parent && item == parent) {
|
||
|
menu.classList.add('show');
|
||
|
menu.classList.remove('hide');
|
||
|
arrow.classList.add('open');
|
||
|
arrow.classList.remove('close');
|
||
|
event.preventDefault();
|
||
|
}
|
||
|
|
||
|
button.onclick = function (event) {
|
||
|
var item = event.target.parentNode.children[1] && event.target.parentNode.children[1].getAttribute("id");
|
||
|
|
||
|
var current_page = item && item == current_manager;
|
||
|
|
||
|
if (!menu.hasClass('show')) {
|
||
|
menu.classList.add('show');
|
||
|
menu.classList.remove('hide');
|
||
|
arrow.classList.add('open');
|
||
|
arrow.classList.remove('close');
|
||
|
}
|
||
|
else {
|
||
|
menu.classList.remove('show');
|
||
|
menu.classList.add('hide');
|
||
|
arrow.classList.remove('open');
|
||
|
arrow.classList.add('close');
|
||
|
}
|
||
|
|
||
|
current_page && event.preventDefault();
|
||
|
};
|
||
|
});
|
||
|
|
||
|
Element.prototype.hasClass = function (className) {
|
||
|
return this.className && new RegExp("(^|\\s)" + className + "(\\s|$)").test(this.className);
|
||
|
};
|
||
|
|
||
|
}
|