1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-07-25 07:51:12 +02:00

add on demand mode loading to cm.

This commit is contained in:
Kushagra Gour
2016-07-14 03:48:12 +05:30
parent ad3c605649
commit 5cfea4d0ca
5 changed files with 136 additions and 14 deletions

30
src/dropdown.js Normal file
View File

@@ -0,0 +1,30 @@
// Dropdown.js
(function($all) {
var openDropdown;
// Closes all dropdowns except the passed one.
function closeOpenDropdown(except) {
if (openDropdown && (!except || except !== openDropdown)) {
openDropdown.classList.remove('open');
openDropdown = null;
}
}
function init() {
var dropdowns = [].slice.call($all('[dropdown]'));
dropdowns.forEach(function (dropdown) {
dropdown.addEventListener('click', function (e) {
closeOpenDropdown(e.currentTarget);
e.currentTarget.classList.toggle('open');
openDropdown = e.currentTarget;
e.stopPropagation();
});
});
document.addEventListener('click', function () {
closeOpenDropdown();
});
}
init();
})($all);