a52a1c17d0241c030b77dc39b2d4c3a465ffcd81
[Packages/TYPO3.CMS.git] / t3lib / jsfunc.menu.js
1 /***************************************************************
2 *
3 * JavaScript menu
4 *
5 * $Id$
6 *
7 *
8 *
9 * Copyright notice
10 *
11 * (c) 1998-2003 Kasper Skaarhoj
12 * All rights reserved
13 *
14 * This script is part of the TYPO3 t3lib/ library provided by
15 * Kasper Skaarhoj <kasper@typo3.com> together with TYPO3
16 *
17 * Released under GNU/GPL (see license file in tslib/)
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 *
23 * This copyright notice MUST APPEAR in all copies of this script
24 ***************************************************************/
25
26
27 function JSmenuItem (owner, id, nextItem, parent, openID, title, url, target) {
28 this.owner = owner;
29 this.id = id;
30 this.nextItem = nextItem;
31 this.child = 0;
32 this.openID = openID;
33 this.parent = parent;
34 this.title = title;
35 this.url = url;
36 this.target = target;
37 }
38 function JSmenu (levels,formname) {
39 this.name = name,
40 this.levels = levels;
41 this.formname = formname;
42
43 this.openID = 0;
44
45 this.entry = new JSmenuItem (this);
46 this.count = 0;
47 this.defTopTitle = new Array();
48 this.add = JSmenuAddItem; // Tilføjer Item
49 this.writeOut = JSmenuWrite;
50 this.act = JSactivate;
51 }
52 function JSmenuAddItem (parent,prevItem,openID,title,url,target) {
53 this.count++;
54 var entryID = this.count;
55 this.entry[entryID] = new JSmenuItem (this, entryID, 0, parent, openID, unescape(title), unescape(url), target);
56 if (prevItem) {
57 this.entry[prevItem].nextItem = entryID;
58 } else if(parent) {
59 this.entry[parent].child = entryID;
60 }
61 return entryID;
62 }
63 function JSmenuWrite(theEntryID,openID,theLevel) {
64 var level=theLevel;
65 if (level<=this.levels) {
66 var entryID = theEntryID;
67 var firstEntryID = theEntryID;
68 var selectorBox = document[this.formname]["selector"+level];
69 var index=0;
70 selectorBox.length=0;
71 selectorBox.length++;
72 selectorBox.options[index].text = this.defTopTitle[theLevel] ? this.defTopTitle[theLevel] : " ";
73 selectorBox.options[index].value = 0;
74 index++;
75 var indexSet=0;
76 if (entryID && this.entry[entryID]) {
77 var ids = "";
78 while(entryID) {
79 ids+="-"+entryID;
80 selectorBox.length++;
81 selectorBox.options[index].text = this.entry[entryID].title;
82 selectorBox.options[index].value = entryID;
83 if (openID==entryID) {
84 var indexSet = 1;
85 selectorBox.selectedIndex = index;
86 if (level<this.levels) {
87 this.writeOut(this.entry[entryID].child, this.entry[entryID].openID,level+1);
88 }
89 }
90 index++;
91 entryID=this.entry[entryID].nextItem;
92 }
93 if (!indexSet) {
94 selectorBox.selectedIndex=0;
95 this.writeOut(this.entry[firstEntryID].child, this.entry[firstEntryID].openID,level+1);
96 }
97 } else if (level<this.levels) {
98 this.writeOut(0, 0,level+1);
99 }
100 }
101 }
102 function JSactivate(level) {
103 var selectorBox = document[this.formname]["selector"+level];
104 var entryID = selectorBox.options[selectorBox.selectedIndex].value;
105 if (this.entry[entryID]) {
106 this.writeOut(this.entry[entryID].child,this.entry[entryID].openID,level+1);
107 if (this.entry[this.entry[entryID].parent]) {
108 this.entry[this.entry[entryID].parent].openID = entryID;
109 }
110 if (this.entry[entryID].url) {
111 if (document.getElementsByTagName("base")[0].href != "") {
112 this.entry[entryID].url = document.getElementsByTagName("base")[0].href + this.entry[entryID].url;
113 }
114 if (!this.entry[entryID].target || this.entry[entryID].target=="_self") {
115 document.location = this.entry[entryID].url;
116 } else if (this.entry[entryID].target=="_top") {
117 top.document.location = this.entry[entryID].url;
118 } else {
119 var test = eval ("parent."+this.entry[entryID].target);
120 if (!test) {
121 test = eval ("top."+this.entry[entryID].target);
122 }
123 if (test && test.document) {
124 test.document.location = this.entry[entryID].url;
125 } else {
126 window.open(this.entry[entryID].url,this.entry[entryID].target,"status=yes,menubar=yes,resizable=yes,location=yes,directories=yes,scrollbars=yes,toolbar=yes");
127 }
128 }
129 }
130 }
131 }