47 lines
837 B
JavaScript
Executable File
47 lines
837 B
JavaScript
Executable File
function menu (menu) {
|
|
|
|
this.element = menu;
|
|
this.active = null;
|
|
|
|
var menuman = this;
|
|
|
|
this.focusOn = function (elemo) {
|
|
|
|
if (this.active) this.active.removeClassName('active');
|
|
this.active = elemo;
|
|
if (!elemo) return;
|
|
elemo.addClassName('active');
|
|
}
|
|
|
|
function onhover () {
|
|
|
|
if (!menuman.active) return;
|
|
menuman.focusOn(this);
|
|
}
|
|
|
|
function onclick (e) {
|
|
|
|
e.stopPropagation();
|
|
var hello = this;
|
|
if (this.hasClassName('active')) hello = null;
|
|
menuman.focusOn(hello);
|
|
}
|
|
|
|
function docOnclick () {
|
|
|
|
menuman.focusOn(null);
|
|
}
|
|
|
|
|
|
var elem = menu.getChildElementsByTagName('li');
|
|
for (var u = 0; u < elem.length; u++) {
|
|
elem[u].addEventListener('click', onclick, false);
|
|
elem[u].addEventListener('mouseover', onhover, false);
|
|
}
|
|
|
|
document.addEventListener('click', docOnclick, false);
|
|
}
|
|
|
|
|
|
|