32 |
// | Harald Radi <harald.radi@nme.at> | |
// | Harald Radi <harald.radi@nme.at> | |
33 |
// +-----------------------------------------------------------------------+ |
// +-----------------------------------------------------------------------+ |
34 |
// |
// |
35 |
// Id: TreeMenu.js,v 1.13 2003/02/19 18:30:46 richard Exp |
// Id: TreeMenu.js,v 1.18 2003/12/20 13:33:09 richard Exp |
36 |
// $Id$ |
// $Id$ |
37 |
|
|
38 |
|
/** |
39 |
|
* Function to create copies of objects which are |
40 |
|
* normally passed around by references (Arrays for example) |
41 |
|
*/ |
42 |
|
function arrayCopy(input) |
43 |
|
{ |
44 |
|
var output = new Array(input.length); |
45 |
|
|
46 |
|
for (i in input) { |
47 |
|
if (typeof(input[i]) == 'array') { |
48 |
|
output[i] = arrayCopy(input[i]); |
49 |
|
} else { |
50 |
|
output[i] = input[i]; |
51 |
|
} |
52 |
|
} |
53 |
|
|
54 |
|
return output; |
55 |
|
} |
56 |
|
|
57 |
/** |
/** |
58 |
* TreeMenu class |
* TreeMenu class |
67 |
this.usePersistence = usePersistence; |
this.usePersistence = usePersistence; |
68 |
this.noTopLevelImages = noTopLevelImages; |
this.noTopLevelImages = noTopLevelImages; |
69 |
this.n = new Array(); |
this.n = new Array(); |
70 |
|
this.output = ''; |
71 |
|
|
72 |
this.nodeRefs = new Array(); |
this.nodeRefs = new Array(); |
73 |
this.branches = new Array(); |
this.branches = new Array(); |
74 |
this.branchStatus = new Array(); |
this.branchStatus = new Array(); |
134 |
var expanded = arguments[3] ? arguments[3] : false; |
var expanded = arguments[3] ? arguments[3] : false; |
135 |
var visibility = arguments[4] ? arguments[4] : 'inline'; |
var visibility = arguments[4] ? arguments[4] : 'inline'; |
136 |
var parentLayerID = arguments[5] ? arguments[5] : null; |
var parentLayerID = arguments[5] ? arguments[5] : null; |
137 |
|
|
138 |
var currentlevel = level.length; |
var currentlevel = level.length; |
139 |
|
|
140 |
for (var i=0; i<nodes.length; i++) { |
for (var i=0; i<nodes.length; i++) { |
141 |
|
|
142 |
level[currentlevel] = i+1; |
level[currentlevel] = i+1; |
143 |
layerID = this.myname + '_' + 'node_' + this.implode('_', level); |
layerID = this.myname + '_' + 'node_' + this.implode('_', level); |
144 |
|
|
145 |
/** |
/** |
146 |
* Store this object in the nodeRefs array |
* Store this object in the nodeRefs array |
147 |
*/ |
*/ |
180 |
* Make sure visibility is correct based on parent status |
* Make sure visibility is correct based on parent status |
181 |
*/ |
*/ |
182 |
visibility = this.checkParentVisibility(layerID) ? visibility : 'none'; |
visibility = this.checkParentVisibility(layerID) ? visibility : 'none'; |
183 |
|
|
184 |
/** |
/** |
185 |
* Setup branch status and build an indexed array |
* Setup branch status and build an indexed array |
186 |
* of branch layer ids |
* of branch layer ids |
201 |
/** |
/** |
202 |
* Branch images |
* Branch images |
203 |
*/ |
*/ |
204 |
var gifname = nodes[i].n.length && this.doesMenu() && nodes[i].isDynamic ? (expanded ? 'minus' : 'plus') : 'branch'; |
var gifname = nodes[i].n.length && this.doesMenu() && nodes[i].isDynamic ? (expanded ? 'minus' : 'plus') : 'branch'; |
205 |
var iconimg = nodes[i].icon ? this.stringFormat('<img src="{0}/{1}" width="20" height="20" align="top" id="icon_{2}">', this.iconpath, nodes[i].icon, layerID) : ''; |
var iconName = expanded && nodes[i].expandedIcon ? nodes[i].expandedIcon : nodes[i].icon; |
206 |
|
var iconimg = nodes[i].icon ? this.stringFormat('<img src="{0}/{1}" width="20" height="20" align="top" id="icon_{2}">', this.iconpath, iconName, layerID) : ''; |
207 |
|
|
208 |
/** |
/** |
209 |
* Add event handlers |
* Add event handlers |
223 |
var imgTag = this.stringFormat('<img src="{0}/{1}{2}.gif" width="20" height="20" align="top" border="0" name="img_{3}" {4}>', this.iconpath, gifname, modifier, layerID, onMDown); |
var imgTag = this.stringFormat('<img src="{0}/{1}{2}.gif" width="20" height="20" align="top" border="0" name="img_{3}" {4}>', this.iconpath, gifname, modifier, layerID, onMDown); |
224 |
var linkTarget= nodes[i].linkTarget ? nodes[i].linkTarget : this.linkTarget; |
var linkTarget= nodes[i].linkTarget ? nodes[i].linkTarget : this.linkTarget; |
225 |
var linkStart = nodes[i].link ? this.stringFormat('<a href="{0}" target="{1}">', nodes[i].link, linkTarget) : ''; |
var linkStart = nodes[i].link ? this.stringFormat('<a href="{0}" target="{1}">', nodes[i].link, linkTarget) : ''; |
226 |
|
|
227 |
var linkEnd = nodes[i].link ? '</a>' : ''; |
var linkEnd = nodes[i].link ? '</a>' : ''; |
228 |
|
|
229 |
output = this.stringFormat('{0}<nobr>{1}{2}{3}{4}<span {5}>{6}</span>{7}</nobr><br></div>', |
this.output += this.stringFormat('{0}<nobr>{1}{2}{3}{4}<span {5}>{6}</span>{7}</nobr><br></div>', |
230 |
layerTag, |
layerTag, |
231 |
prepend, |
prepend, |
232 |
parentLayerID == null && (nodes.length == 1 || this.noTopLevelImages) ? '' : imgTag, |
parentLayerID == null && (nodes.length == 1 || this.noTopLevelImages) ? '' : imgTag, |
235 |
eventHandlers, |
eventHandlers, |
236 |
nodes[i].title, |
nodes[i].title, |
237 |
linkEnd); |
linkEnd); |
|
|
|
|
/** |
|
|
* Write out the HTML. Uses document.write for speed over layers and |
|
|
* innerHTML. This however means no dynamic adding/removing nodes on |
|
|
* the client side. This could be conditional I guess if dynamic |
|
|
* adding/removing is required. |
|
|
*/ |
|
|
document.write(output + "\r\n"); |
|
238 |
|
|
239 |
/** |
/** |
240 |
* Traverse sub nodes ? |
* Traverse sub nodes ? |
254 |
} else { |
} else { |
255 |
var newPrepend = prepend + this.stringFormat('<img src="{0}/linebottom.gif" width="20" height="20" align="top">', this.iconpath); |
var newPrepend = prepend + this.stringFormat('<img src="{0}/linebottom.gif" width="20" height="20" align="top">', this.iconpath); |
256 |
} |
} |
257 |
|
|
258 |
this.drawMenu(nodes[i].n, |
this.drawMenu(nodes[i].n, |
259 |
level, |
arrayCopy(level), |
260 |
newPrepend, |
newPrepend, |
261 |
nodes[i].expanded, |
nodes[i].expanded, |
262 |
expanded ? 'inline' : 'none', |
expanded ? 'inline' : 'none', |
266 |
} |
} |
267 |
|
|
268 |
/** |
/** |
269 |
|
* Writes the output generated by drawMenu() to the page |
270 |
|
*/ |
271 |
|
TreeMenu.prototype.writeOutput = function () |
272 |
|
{ |
273 |
|
document.write(this.output); |
274 |
|
} |
275 |
|
|
276 |
|
/** |
277 |
* Toggles a branches visible status. Called from resetBranches() |
* Toggles a branches visible status. Called from resetBranches() |
278 |
* and also when a +/- graphic is clicked. |
* and also when a +/- graphic is clicked. |
279 |
*/ |
*/ |
282 |
var currentDisplay = this.getLayer(layerID).style.display; |
var currentDisplay = this.getLayer(layerID).style.display; |
283 |
var newDisplay = (this.branchStatus[layerID] && currentDisplay == 'inline') ? 'none' : 'inline'; |
var newDisplay = (this.branchStatus[layerID] && currentDisplay == 'inline') ? 'none' : 'inline'; |
284 |
var fireEvents = arguments[2] != null ? arguments[2] : true; |
var fireEvents = arguments[2] != null ? arguments[2] : true; |
285 |
|
|
286 |
for (var i=0; i<this.layerRelations[layerID].length; i++) { |
for (var i=0; i<this.layerRelations[layerID].length; i++) { |
287 |
|
|
288 |
if (this.branchStatus[this.layerRelations[layerID][i]]) { |
if (this.branchStatus[this.layerRelations[layerID][i]]) { |
289 |
this.toggleBranch(this.layerRelations[layerID][i], false); |
this.toggleBranch(this.layerRelations[layerID][i], false); |
290 |
} |
} |
355 |
var imgSrc = document.images['icon_' + layerID].src; |
var imgSrc = document.images['icon_' + layerID].src; |
356 |
|
|
357 |
if (this.nodeRefs[layerID].icon && this.nodeRefs[layerID].expandedIcon) { |
if (this.nodeRefs[layerID].icon && this.nodeRefs[layerID].expandedIcon) { |
|
//alert(imgSrc.indexOf(this.nodeRefs[layerID].expandedIcon)); |
|
358 |
var newSrc = (imgSrc.indexOf(this.nodeRefs[layerID].expandedIcon) == -1 ? this.nodeRefs[layerID].expandedIcon : this.nodeRefs[layerID].icon); |
var newSrc = (imgSrc.indexOf(this.nodeRefs[layerID].expandedIcon) == -1 ? this.nodeRefs[layerID].expandedIcon : this.nodeRefs[layerID].icon); |
359 |
|
|
360 |
document.images['icon_' + layerID].src = this.iconpath + '/' + newSrc; |
document.images['icon_' + layerID].src = this.iconpath + '/' + newSrc; |
367 |
*/ |
*/ |
368 |
TreeMenu.prototype.doesMenu = function () |
TreeMenu.prototype.doesMenu = function () |
369 |
{ |
{ |
370 |
return (is_ie4up || is_nav6up || is_gecko); |
return (is_ie4up || is_nav6up || is_gecko || is_opera7); |
371 |
} |
} |
372 |
|
|
373 |
/** |
/** |
375 |
*/ |
*/ |
376 |
TreeMenu.prototype.doesPersistence = function () |
TreeMenu.prototype.doesPersistence = function () |
377 |
{ |
{ |
378 |
return (is_ie4up || is_gecko || is_nav6up); |
return (is_ie4up || is_gecko || is_nav6up || is_opera7); |
379 |
} |
} |
380 |
|
|
381 |
/** |
/** |
459 |
if (!this.doesPersistence()) { |
if (!this.doesPersistence()) { |
460 |
return false; |
return false; |
461 |
} |
} |
462 |
|
|
463 |
this.loadCookie(); |
this.loadCookie(); |
464 |
|
|
465 |
for (var i=0; i<this.branches.length; i++) { |
for (var i=0; i<this.branches.length; i++) { |
682 |
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1)); |
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1)); |
683 |
var is_ie4 = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) ); |
var is_ie4 = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) ); |
684 |
var is_ie4up = (is_ie && (is_major >= 4)); |
var is_ie4up = (is_ie && (is_major >= 4)); |
685 |
|
|
686 |
|
var is_opera = (agt.indexOf("opera") != -1); |
687 |
|
var is_opera7 = is_opera && (agt.indexOf("opera 7") != -1); |
688 |
|
|
689 |
|
// Patch from Harald Fielker |
690 |
|
if (agt.indexOf('konqueror') != -1) { |
691 |
|
var is_nav = false; |
692 |
|
var is_nav6up = false; |
693 |
|
var is_gecko = false; |
694 |
|
var is_ie = true; |
695 |
|
var is_ie4 = true; |
696 |
|
var is_ie4up = true; |
697 |
|
} |
698 |
//--> end hide JavaScript |
//--> end hide JavaScript |