2 lines
11 KiB
JavaScript
2 lines
11 KiB
JavaScript
|
(function(e){var t=[],n=[],r=activeItem=null,i=e('<div class="menu-div outerbox" style="position:absolute;top:0;left:0;display:none;"><div class="shadowbox1"></div><div class="shadowbox2"></div><div class="shadowbox3"></div></div>')[0],s=e('<ul class="menu-ul innerbox"></ul>')[0],o=e('<li style="position:relative;"><div class="menu-item"></div></li>')[0],u=e('<img class="menu-item-arrow" />')[0],a=e('<div id="root-menu-div" style="position:absolute;top:0;left:0;"></div>'),f={showDelay:200,hideDelay:200,hoverOpenDelay:0,offsetTop:0,offsetLeft:0,minWidth:0,onOpen:null,onClose:null,onClick:null,arrowSrc:null,addExpando:false,copyClassAttr:false};e(function(){a.appendTo("body")});e.extend({MenuCollection:function(e){this.menus=[];this.init(e)}});e.extend(e.MenuCollection,{prototype:{init:function(e){if(e&&e.length){for(var t=0;t<e.length;t++){this.addMenu(e[t]);e[t].menuCollection=this}}},addMenu:function(t){if(t instanceof e.Menu)this.menus.push(t);t.menuCollection=this;var n=this;e(t.target).hover(function(){if(t.visible)return;for(var e=0;e<n.menus.length;e++){if(n.menus[e].visible){n.menus[e].hide();t.show();return}}},function(){})}}});e.extend({Menu:function(t,n,r){this.menuItems=[];this.subMenus=[];this.visible=false;this.active=false;this.parentMenuItem=null;this.settings=e.extend({},f,r);this.target=t;this.$eDIV=null;this.$eUL=null;this.timer=null;this.menuCollection=null;this.openTimer=null;this.init();if(n&&n.constructor==Array)this.addItems(n)}});e.extend(e.Menu,{checkMouse:function(t){var r=t.target;if(n.length&&r==n[0].target)return;while(r.parentNode&&r.parentNode!=a[0])r=r.parentNode;if(!e(n).filter(function(){return this.$eDIV[0]==r}).length){e.Menu.closeAll()}},checkKey:function(t){switch(t.keyCode){case 13:if(activeItem)activeItem.click(t,activeItem.$eLI[0]);break;case 27:e.Menu.closeAll();break;case 37:if(!r)r=n[0];var i=r;if(i&&i.parentMenuItem){var s=i.parentMenuItem;s.$eLI.unbind("mouseout").unbind("mouseover");i.hide();s.hoverIn(true);setTimeout(function(){s.bindHover()})}else if(i&&i.menuCollection){var o,u=i.menuCollection.menus;if((o=e.inArray(i,u))>-1){if(--o<0)o=u.length-1;e.Menu.closeAll();u[o].show();u[o].setActive();if(u[o].menuItems.length)u[o].menuItems[0].hoverIn(true)}}break;case 38:if(r)r.selectNextItem(-1);break;case 39:if(!r)r=n[0];var a,i=r,f=activeItem?activeItem.subMenu:null;if(i){if(f&&f.menuItems.length){f.show();f.menuItems[0].hoverIn()}else if(i=i.inMenuCollection()){var o,u=i.menuCollection.menus;if((o=e.inArray(i,u))>-1){if(++o>=u.length)o=0;e.Menu.closeAll();u[o].show();u[o].setActive();if(u[o].menuItems.length)u[o].menuItems[0].hoverIn(true)}}}break;case 40:if(!r){if(n.length&&n[0].menuItems.length)n[0].menuItems[0].hoverIn()}else r.selectNextItem();break}if(t.keyCode>36&&t.keyCode<41)return false},closeAll:function(){while(n.length)n[0].hide()},setDefaults:function(t){e.extend(f,t)},prototype:{init:function(){var n=this;if(!this.target)return;else if(this.target instanceof e.MenuItem){this.parentMenuItem=this.target;this.target.addSubMenu(this);this.target=this.target.$eLI}t.push(this);this.$eDIV=e(i.cloneNode(1));this.$eUL=e(s.cloneNode(1));this.$eDIV[0].appendChild(this.$eUL[0]);a[0].appendChild(this.$eDIV[0]);if(!this.parentMenuItem){e(this.target).click(function(e){n.onClick(e)}).hover(function(e){n.setActive();if(n.settings.hoverOpenDelay){n.openTimer=setTimeout(function(){if(!n.visible)n.onClick(e)},n.settings.hoverOpenDelay)}},function(){if(!n.visible)e(this).removeClass("activetarget");if(n.openTimer)clearTimeout(n.openTimer)})}else{this.$eDIV.hover(function(){n.setActive()},function(){})}},setActive:function(){if(!this.parentMenuItem)e(this.target).addClass("activetarget");else this.active=true},addItem:function(t){if(t instanceof e.MenuItem){if(e.inArray(t,this.menuItems)==-1){this.$eUL.append(t.$eLI);this.menuItems.push(t);t.parentMenu=this;if(t.subMenu)this.subMenus.push(t.subMenu)}}else{this.addItem(new e.MenuItem(t,this.settings))}},addItems:function(e){for(var t=0;t<e.length;t++){this.addItem(e[t])}},removeItem:function(t){var n=e.inArray(t,this.menuItems);if(
|