var DropMenu = new Class({ Implements: [Options], menu: null, initialize: function(menu,options){ if (options) { this.setOptions(options); } var children = $(menu).getChildren(); new DropMenu_SubMenu(children,0,options); } }); var DropMenu_SubMenu = new Class({ Implements: [Options], menu: null, depth: 0, initialize: function(el,depth,options) { if (depth) this.depth = depth; var prev_el = ''; var prev_a = ''; el.each( function(item,index) { var fChild, list; fChild = item.getFirst(); list = fChild.getNext('ul'); if (list) { item.mel = list; list.pel = item; list.pel.addEvents({ 'mouseover': function(){ if (document.getSize().x > 768) { this.mel.addClass('show'); item.setProperty('aria-expanded',true); } }, 'mouseout': function(){ if (document.getSize().x > 768) { this.mel.removeClass('show'); item.setProperty('aria-expanded',false); } }, }); list.pel.getElement('a').addEvents({ 'focus': function() { ap = this.getParent('li'); if (document.getSize().x > 768) { if (prev_el) { prev_el.removeClass('show'); } if (prev_a) { prev_a.removeProperty('data-click'); } prev_el = ap.mel; } }, 'click': function() { klik = this.getProperty('data-click'); if (!klik) { if (document.getSize().x <768) { if (prev_el) { prev_el.removeClass('show'); } if (prev_a) { prev_a.removeProperty('data-click'); } } this.setProperty('data-click', true); ap = this.getParent('li'); prev_a = this; prev_el = ap.mel; if (!ap.mel.hasClass('show')) { ap.mel.addClass('show'); return false; } if (document.getSize().x < 768) { return false; } prev_el = ap.mel; } else { return true; } } }); var children = list.getChildren(); new DropMenu_SubMenu(children,depth+1,options); } else { item.getElement('a').addEvents({ 'focus': function() { if (prev_a) { prev_a.removeProperty('data-click'); } if (prev_el) { prev_el.removeClass('show'); } prev_a = ''; prev_el = ''; } }); } }); } });