/** * viceurovnove menu, ktere pouziva vice slideru jako jednotlive urovne * */ var SliderMenu = function(baseMenu, currentMenus, allMenus) { this.baseMenu = baseMenu; this.currentMenus = currentMenus; this.currentItems = []; this.allMenus = allMenus; this.delay = 1000; this.timer = null; this.currentMenu = null; //to kde je mys this.envelope = null; this.idPrefixMenu = "slider_"; this.idPrefixItem = "item_"; } SliderMenu.prototype.showCurrent = function(quick) { var i; this.baseMenu.hideChildren(this.currentMenus); this.baseMenu.highlight(null); this.baseMenu.setOverflow("visible"); for(i in this.currentMenus) { this.currentMenus[i].setOverflow("visible"); this.currentMenus[i].highlight(null); this.currentMenus[i].show(quick); this.currentMenus[i].lock(); } var j, idItem, elem; for(i in this.currentItems) { idItem = this.idPrefixItem + this.currentItems[i]; elem = fLib.getElementById(idItem); for(j in this.currentMenus) { if(this.currentMenus[j].hasElement(elem)) { this.currentMenus[j].highlight(elem); } } } } SliderMenu.prototype.show = function(elem, menu, parent) { clearTimeout(this.timer); parent.addElement(elem); parent.highlight(elem); this.currentMenu = parent; this.currentMenu.hideChildren([menu]); parent.setOverflow("visible"); if(menu) { menu.highlight(null); menu.show(); menu.showParent(); } } SliderMenu.prototype.hide = function(elem, menu) { clearTimeout(this.timer); if(this.currentMenu) { this.currentMenu.hideChildren([menu]); } var self = this; this.timer = setTimeout(function() { self.showCurrent(); }, this.delay); } SliderMenu.prototype.setItemEvents = function(menu, menuElem, parent) { var self = this; fLib.addEvent("mouseover", function(e) { fLib.stopPropagation(e); self.show(menuElem, menu, parent); }, menuElem); fLib.addEvent("mouseout", function(e) { fLib.stopPropagation(e); self.hide(menuElem, menu); }, menuElem); } SliderMenu.prototype.registerStructure = function(structure, current, parentMenu) { var tmp, i, lis, j, id, elem; var ret = []; for(i in structure) { tmp = null; if(structure[i].subitems.length > 0) { idMenu = this.idPrefixMenu + structure[i].id; tmp = new MenuSliderItem(idMenu, true, true, false); tmp.autoinit = false; tmp.register(parentMenu); this.allMenus.push(tmp); if(fLib.arIndexOf(current, structure[i].id) != -1) { this.currentMenus.push(tmp); } this.registerStructure(structure[i].subitems, current, tmp); } idItem = this.idPrefixItem + structure[i].id; elem = fLib.getElementById(idItem); parentMenu.addElement(elem); this.setItemEvents(tmp, elem, parentMenu); } return ret; } SliderMenu.prototype.build = function(structure, current, baseID) { this.baseMenu = new MenuSliderItem(baseID, false, false, false); this.baseMenu.autoinit = false; this.allMenus = [this.baseMenu]; this.currentMenus = [this.baseMenu]; this.registerStructure(structure, current, this.baseMenu); this.envelope = document.createElement("div"); this.currentItems = current; var self = this; fLib.addEvent("load", function() { for(i in self.allMenus) { self.allMenus[i].init(); } //nastaveni visky menu prvku var h = 0; for(i in self.currentMenus) { h = h + self.currentMenus[i].getOffsetHeight(); } var firstMenu = self.baseMenu.getElem(); firstMenu.parentNode.insertBefore(self.envelope, firstMenu); self.envelope.appendChild(firstMenu); self.envelope.style.height = h + "px"; self.showCurrent(true); }, window); } //------------------------------------------------------------------------------ var MenuSliderItem = function() { Slider.apply(this, arguments); this.children = new Array(); this.parent = null; this.highlighClass = "current"; this.elements = new Array(); this.itemIDs = []; } MenuSliderItem.prototype.register = function(parent) { this.parent = parent; this.parent.addChild(this); } MenuSliderItem.prototype.addChild = function(child) { this.children.push(child); } MenuSliderItem.prototype.hideChildren = function(noHide) { var i; for(i in this.children) { this.children[i].hideChildren([]); if(fLib.arIndexOf(noHide, this.children[i]) == -1) { this.children[i].doHide(noHide.length > 0); } } } MenuSliderItem.prototype.showParent = function() { if(this.parent) { this.parent.show(); this.parent.showParent(); } } MenuSliderItem.prototype.doHide = function(quick) { Slider.prototype.doHide.call(this, quick); for(i in this.children) { this.children[i].doHide(quick); } this.setOverflow("hidden"); } MenuSliderItem.prototype.toString = function() { return "Slider menu: " + this.id; } MenuSliderItem.prototype.addElement = function(elem) { if(!this.hasElement(elem)) { this.elements.push(elem); } } MenuSliderItem.prototype.hasElement = function(elem) { return fLib.arIndexOf(this.elements, elem) != -1; } MenuSliderItem.prototype.highlight = function(elem) { var i; for(i in this.elements) { if(this.elements[i] == elem) { this.elements[i].className = this.highlighClass; } else { this.elements[i].className = ""; } } } fLib.mix(Slider, MenuSliderItem);