// DOCUMENTATION ////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Toto je nabidkova lista s polozkami ve forme obrazku. Zvyraznuje aktualni polozku a polzoku pdo mysi. // Pro pouziti je potreba: // - zalozit menu: var Menu = new TMenu("Menu", ...); // - pridat do menu polozky: Menu.Add(...); // - mit obrazky, jejich nazvy jsou odvozene od jmena polozky // - mit v dokumentu elementy, kam se obrazky vlozi, jejich nazvy jsou odvozene od jmena polozky // - v OnLoad dokumentu zavolat Menu.Run(); // - ridit vybraznou polozku pomoci Menu.Select() nebo Menu.Synchronize() // FUNCTIONS ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function SameURL(urlA, urlB) { // porovnani koncu stringu var len = Math.min(urlA.length, urlB.length); return (len > 0) && (urlA.slice(urlA.length - len) == urlB.slice(urlB.length - len)); }; // CLASS TMenu //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // PUBLIC CLASS MEMBERS function TMenu(name, target, elementPrefix, elementSuffix, imagePrefix, imageSuffix) { // public metody this.Add = TMenu_Add; this.Run = TMenu_Run; this.Synchronize = TMenu_Synchronize; this.Select = TMenu_Select; this.Hilight = TMenu_Hilight; // private metody this.find = TMenu_find; // inicializace poli this.name = name; this.target = target; this.elementPrefix = elementPrefix; this.elementSuffix = elementSuffix; this.imagePrefix = imagePrefix; this.imageSuffix = imageSuffix; this.items = new Array(); this.itemSelected = null; this.itemHilighted = null; }; function TMenu_Add(name, caption, url, target) { // pridani polozky do seznamu index = this.items.length; this.items[index] = new TMenuItem(this, name, caption, url, target); }; function TMenu_Run() { // pro vsechny polozky menu for (var i = 0; i < this.items.length; i++) this.items[i].build(); }; function TMenu_Synchronize() { // urceni dokumentu v cilovem okne var frame = window.frames[this.target]; var url = frame ? frame.document.URL :""; // vyhledani polozky menu se stejnou URL var selectItem = null; for (var i = 0; (i < this.items.length) && !selectItem; i++) selectItem = SameURL(this.items[i].url, url) ? this.items[i] : null; // vybrani odpovidajici polozky this.Select(selectItem ? selectItem.name : ""); }; function TMenu_Select(selected) { // nastaveni vybrane polozky var prevSelected = this.itemSelected; this.itemSelected = this.find(selected); if (this.itemSelected != prevSelected) { if (prevSelected) prevSelected.update(); if (this.itemSelected) this.itemSelected.update(); }; }; function TMenu_Hilight(hilighted) { // nastaveni podbarvene polozky var prevHilighted = this.itemHilighted; this.itemHilighted = this.find(hilighted); if (this.itemHilighted != prevHilighted) { if (prevHilighted) prevHilighted.update(); if (this.itemHilighted) this.itemHilighted.update(); }; }; // PRIVATE CLASS MEMBERS function TMenu_find(name) { // prednastaveni navratove hodnoty var result = null; // vyhledani id for (var i = 0; !result && (i < this.items.length); i++) result = (name == this.items[i].name) ? this.items[i] : null; // navratova hodnota return result; }; // EVENT HANDLERS function TMenu_mouseOverHandler() { eval(this.getAttribute("mouseOverHandler")); }; function TMenu_mouseOutHandler() { eval(this.getAttribute("mouseOutHandler")); }; function TMenu_loadHandler() { alert("Je to tady"); // eval(this.getAttribute("loadHandler")); }; // CLASS TMenuItem //////////////////////////////////////////////////////////////////////////////////////////////////////////// // PUBLIC CLASS MEMBERS function TMenuItem(menu, name, caption, url) { // public metody this.Width = TMenuItem_Width; this.Height = TMenuItem_Height; // private metody this.build = TMenuItem_build; this.update = TMenuItem_update; // inicializace poli this.menu = menu; this.name = name; this.caption = caption; this.imageN = new Image; this.imageN.src = this.menu.imagePrefix + name + "N" + this.menu.imageSuffix; this.imageA = new Image; this.imageA.src = this.menu.imagePrefix + name + "A" + this.menu.imageSuffix; this.url = url; this.elemAnchor = null; this.elemImage = null; }; function TMenuItem_Width() { // velikost by mela byut shodna return Math.max(this.imageN.width, this.imageA.width); }; function TMenuItem_Height() { // velikost by mela byt shodna return Math.max(this.imageN.height, this.imageA.height); }; // PRIVATE CLASS MEMBERS function TMenuItem_build() { // nalezeni odpovidajiciho umisteni var elemParent = document.getElementById(this.menu.elementPrefix + this.name + this.menu.elementSuffix); if (elemParent) { // vytvoreni odkazu this.elemAnchor = document.createElement("A"); this.elemAnchor.href = this.url; this.elemAnchor.target = this.menu.target; this.elemAnchor.onmouseover = TMenu_mouseOverHandler; this.elemAnchor.setAttribute("mouseOverHandler", this.menu.name + ".Hilight('" + this.name + "')"); this.elemAnchor.onmouseout = TMenu_mouseOutHandler; this.elemAnchor.setAttribute("mouseOutHandler", this.menu.name + ".Hilight('')"); // vytvoreni obrazku this.elemImage = document.createElement("IMG"); // this.elemImage.src = this.imageN.src; this.elemImage.width = this.Width(); this.elemImage.height = this.Height(); this.elemImage.alt = this.caption; // vlozeni elementu this.elemAnchor.appendChild(this.elemImage); elemParent.appendChild(this.elemAnchor); }; // nastaveni obrazku dle aktivity this.update(); }; function TMenuItem_update() { // prepinani obrazku dle aktivity if (this.elemImage) if ((this.menu.itemSelected == this) || (this.menu.itemHilighted == this)) this.elemImage.src = this.imageA.src else this.elemImage.src = this.imageN.src; };