add show list methods
This commit is contained in:
parent
3478e04a63
commit
bbb8ca5fdf
13 changed files with 929 additions and 95 deletions
65
templates/initi/static/scripts/dd-menu.js
Normal file
65
templates/initi/static/scripts/dd-menu.js
Normal file
|
@ -0,0 +1,65 @@
|
|||
/**
|
||||
* 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);
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue