ftiens4cm.js 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190
  1. //****************************************************************
  2. // Keep this copyright notice:
  3. // This copy of the script is the property of the owner of the
  4. // particular web site you were visiting.
  5. // Do not download the script's files from there.
  6. // For a free download and full instructions go to:
  7. // http://www.treeview.net
  8. //****************************************************************
  9. // Log of changes:
  10. //
  11. // 08 Jun 04 - Very small change to one error message
  12. // 21 Mar 04 - Support for folder.addChildren allows for much bigger trees
  13. // 12 May 03 - Support for Safari Beta 3
  14. // 01 Mar 03 - VERSION 4.3 - Support for checkboxes
  15. // 21 Feb 03 - Added support for Opera 7
  16. // 22 Sep 02 - Added maySelect member for node-by-node control
  17. // of selection and highlight
  18. // 21 Sep 02 - Cookie values are now separated by cookieCutter
  19. // 12 Sep 02 - VERSION 4.2 - Can highlight Selected Nodes and
  20. // can preserve state through external (DB) IDs
  21. // 29 Aug 02 - Fine tune 'supportDeferral' for IE4 and IE Mac
  22. // 25 Aug 02 - Fixes: STARTALLOPEN, and multi-page frameless
  23. // 09 Aug 02 - Fix repeated folder on Mozilla 1.x
  24. // 31 Jul 02 - VERSION 4.1 - Dramatic speed increase for trees
  25. // with hundreds or thousands of nodes; changes to the control
  26. // flags of the gLnk function
  27. // 18 Jul 02 - Changes in pre-load images function
  28. // 13 Jun 02 - Add ICONPATH var to allow for gif subdir
  29. // 20 Apr 02 - Improve support for frame-less layout
  30. // 07 Apr 02 - Minor changes to support server-side dynamic feeding
  31. // (example: FavoritesManagerASP)
  32. // Definition of class Folder
  33. // *****************************************************************
  34. function Folder(folderDescription, hreference) //constructor
  35. {
  36. //constant data
  37. this.desc = folderDescription;
  38. this.hreference = hreference;
  39. this.id = -1;
  40. this.navObj = 0;
  41. this.iconImg = 0;
  42. this.nodeImg = 0;
  43. this.isLastNode = 0;
  44. this.iconSrc = ICONPATH + "ftv2folderopen.gif";
  45. this.iconSrcClosed = ICONPATH + "ftv2folderclosed.gif";
  46. this.children = new Array;
  47. this.nChildren = 0;
  48. this.level = 0;
  49. this.leftSideCoded = "";
  50. this.isLastNode=false;
  51. this.parentObj = null;
  52. this.maySelect=true;
  53. this.prependHTML = ""
  54. //dynamic data
  55. this.isOpen = false
  56. this.isLastOpenedFolder = false
  57. this.isRendered = 0
  58. //methods
  59. this.initialize = initializeFolder
  60. this.setState = setStateFolder
  61. this.addChild = addChild
  62. this.addChildren = addChildren
  63. this.createIndex = createEntryIndex
  64. this.escondeBlock = escondeBlock
  65. this.esconde = escondeFolder
  66. this.folderMstr = folderMstr
  67. this.renderOb = drawFolder
  68. this.totalHeight = totalHeight
  69. this.subEntries = folderSubEntries
  70. this.linkHTML = linkFolderHTML
  71. this.blockStartHTML = blockStartHTML
  72. this.blockEndHTML = blockEndHTML
  73. this.nodeImageSrc = nodeImageSrc
  74. this.iconImageSrc = iconImageSrc
  75. this.getID = getID
  76. this.forceOpeningOfAncestorFolders = forceOpeningOfAncestorFolders
  77. }
  78. function initializeFolder(level, lastNode, leftSide)
  79. {
  80. var j=0
  81. var i=0
  82. nc = this.nChildren
  83. this.createIndex()
  84. this.level = level
  85. this.leftSideCoded = leftSide
  86. if (browserVersion == 0 || STARTALLOPEN==1)
  87. this.isOpen=true;
  88. if (level>0)
  89. if (lastNode) //the last child in the children array
  90. leftSide = leftSide + "0"
  91. else
  92. leftSide = leftSide + "1"
  93. this.isLastNode = lastNode
  94. if (nc > 0)
  95. {
  96. level = level + 1
  97. for (i=0 ; i < this.nChildren; i++)
  98. {
  99. if (typeof this.children[i].initialize == 'undefined') //document node was specified using the addChildren function
  100. {
  101. if (typeof this.children[i][0] == 'undefined' || typeof this.children[i] == 'string')
  102. {
  103. this.children[i] = ["item incorrectly defined", ""];
  104. }
  105. //Basic initialization of the Item object
  106. //These members or methods are needed even before the Item is rendered
  107. this.children[i].initialize=initializeItem;
  108. this.children[i].createIndex=createEntryIndex;
  109. if (typeof this.children[i].maySelect == 'undefined')
  110. this.children[i].maySelect=true
  111. this.children[i].forceOpeningOfAncestorFolders = forceOpeningOfAncestorFolders
  112. }
  113. if (i == this.nChildren-1)
  114. this.children[i].initialize(level, 1, leftSide)
  115. else
  116. this.children[i].initialize(level, 0, leftSide)
  117. }
  118. }
  119. }
  120. function drawFolder(insertAtObj)
  121. {
  122. var nodeName = ""
  123. var auxEv = ""
  124. var docW = ""
  125. var i=0
  126. finalizeCreationOfChildDocs(this)
  127. var leftSide = leftSideHTML(this.leftSideCoded)
  128. if (browserVersion > 0)
  129. auxEv = "<a href='javascript:clickOnNode(\""+this.getID()+"\")'>"
  130. else
  131. auxEv = "<a>"
  132. nodeName = this.nodeImageSrc()
  133. if (this.level>0)
  134. if (this.isLastNode) //the last child in the children array
  135. leftSide = leftSide + "<td valign=top>" + auxEv + "<img name='nodeIcon" + this.id + "' id='nodeIcon" + this.id + "' src='" + nodeName + "' width=16 height=22 border=0></a></td>"
  136. else
  137. leftSide = leftSide + "<td valign=top background=" + ICONPATH + "ftv2vertline.gif>" + auxEv + "<img name='nodeIcon" + this.id + "' id='nodeIcon" + this.id + "' src='" + nodeName + "' width=16 height=22 border=0></a></td>"
  138. this.isRendered = 1
  139. if (browserVersion == 2) {
  140. if (!doc.yPos)
  141. doc.yPos=20
  142. }
  143. docW = this.blockStartHTML("folder");
  144. docW = docW + "<tr>" + leftSide + "<td valign=top>";
  145. if (USEICONS)
  146. {
  147. docW = docW + this.linkHTML(false)
  148. docW = docW + "<img id='folderIcon" + this.id + "' name='folderIcon" + this.id + "' src='" + this.iconImageSrc() + "' border=0></a>"
  149. }
  150. else
  151. {
  152. if (this.prependHTML == "")
  153. docW = docW + "<img src=" + ICONPATH + "ftv2blank.gif height=2 width=2>"
  154. }
  155. if (WRAPTEXT)
  156. docW = docW + "</td>"+this.prependHTML+"<td valign=middle width=100%>"
  157. else
  158. docW = docW + "</td>"+this.prependHTML+"<td valign=middle nowrap width=100%>"
  159. if (USETEXTLINKS)
  160. {
  161. docW = docW + this.linkHTML(true)
  162. docW = docW + this.desc + "</a>"
  163. }
  164. else
  165. docW = docW + this.desc
  166. docW = docW + "</td>"
  167. docW = docW + this.blockEndHTML()
  168. if (insertAtObj == null)
  169. {
  170. if (supportsDeferral) {
  171. doc.write("<div id=domRoot></div>") //transition between regular flow HTML, and node-insert DOM DHTML
  172. insertAtObj = getElById("domRoot")
  173. insertAtObj.insertAdjacentHTML("beforeEnd", docW)
  174. }
  175. else
  176. doc.write(docW)
  177. }
  178. else
  179. {
  180. insertAtObj.insertAdjacentHTML("afterEnd", docW)
  181. }
  182. if (browserVersion == 2)
  183. {
  184. this.navObj = doc.layers["folder"+this.id]
  185. if (USEICONS)
  186. this.iconImg = this.navObj.document.images["folderIcon"+this.id]
  187. this.nodeImg = this.navObj.document.images["nodeIcon"+this.id]
  188. doc.yPos=doc.yPos+this.navObj.clip.height
  189. }
  190. else if (browserVersion != 0)
  191. {
  192. this.navObj = getElById("folder"+this.id)
  193. if (USEICONS)
  194. this.iconImg = getElById("folderIcon"+this.id)
  195. this.nodeImg = getElById("nodeIcon"+this.id)
  196. }
  197. }
  198. function setStateFolder(isOpen)
  199. {
  200. var subEntries
  201. var totalHeight
  202. var fIt = 0
  203. var i=0
  204. var currentOpen
  205. if (isOpen == this.isOpen)
  206. return
  207. if (browserVersion == 2)
  208. {
  209. totalHeight = 0
  210. for (i=0; i < this.nChildren; i++)
  211. totalHeight = totalHeight + this.children[i].navObj.clip.height
  212. subEntries = this.subEntries()
  213. if (this.isOpen)
  214. totalHeight = 0 - totalHeight
  215. for (fIt = this.id + subEntries + 1; fIt < nEntries; fIt++)
  216. indexOfEntries[fIt].navObj.moveBy(0, totalHeight)
  217. }
  218. this.isOpen = isOpen;
  219. if (this.getID()!=foldersTree.getID() && PRESERVESTATE && !this.isOpen) //closing
  220. {
  221. currentOpen = GetCookie("clickedFolder")
  222. if (currentOpen != null) {
  223. currentOpen = currentOpen.replace(this.getID()+cookieCutter, "")
  224. SetCookie("clickedFolder", currentOpen)
  225. }
  226. }
  227. if (!this.isOpen && this.isLastOpenedfolder)
  228. {
  229. lastOpenedFolder = null;
  230. this.isLastOpenedfolder = false;
  231. }
  232. propagateChangesInState(this)
  233. }
  234. function propagateChangesInState(folder)
  235. {
  236. var i=0
  237. //Change icon
  238. if (folder.nChildren > 0 && folder.level>0) //otherwise the one given at render stays
  239. folder.nodeImg.src = folder.nodeImageSrc()
  240. //Change node
  241. if (USEICONS)
  242. folder.iconImg.src = folder.iconImageSrc()
  243. //Propagate changes
  244. for (i=folder.nChildren-1; i>=0; i--) {
  245. if (folder.isOpen)
  246. folder.children[i].folderMstr(folder.navObj)
  247. else
  248. folder.children[i].esconde()
  249. }
  250. }
  251. function escondeFolder()
  252. {
  253. this.escondeBlock()
  254. this.setState(0)
  255. }
  256. function linkFolderHTML(isTextLink)
  257. {
  258. var docW = "";
  259. if (this.hreference)
  260. {
  261. if (USEFRAMES)
  262. docW = docW + "<a href='" + this.hreference + "' TARGET=\"basefrm\" "
  263. else
  264. docW = docW + "<a href='" + this.hreference + "' TARGET=_top "
  265. if (isTextLink) {
  266. docW += "id=\"itemTextLink"+this.id+"\" ";
  267. }
  268. if (browserVersion > 0)
  269. docW = docW + "onClick='javascript:clickOnFolder(\""+this.getID()+"\")'"
  270. docW = docW + ">"
  271. }
  272. else
  273. docW = docW + "<a>"
  274. return docW;
  275. }
  276. function addChild(childNode)
  277. {
  278. this.children[this.nChildren] = childNode
  279. childNode.parentObj = this
  280. this.nChildren++
  281. return childNode
  282. }
  283. //The list can contain either a Folder object or a sub list with the arguments for Item
  284. function addChildren(listOfChildren)
  285. {
  286. this.children = listOfChildren
  287. this.nChildren = listOfChildren.length
  288. for (i=0; i<this.nChildren; i++)
  289. this.children[i].parentObj = this
  290. }
  291. function folderSubEntries()
  292. {
  293. var i = 0
  294. var se = this.nChildren
  295. for (i=0; i < this.nChildren; i++){
  296. if (this.children[i].children) //is a folder
  297. se = se + this.children[i].subEntries()
  298. }
  299. return se
  300. }
  301. function nodeImageSrc() {
  302. var srcStr = "";
  303. if (this.isLastNode) //the last child in the children array
  304. {
  305. if (this.nChildren == 0)
  306. srcStr = ICONPATH + "ftv2lastnode.gif"
  307. else
  308. if (this.isOpen)
  309. srcStr = ICONPATH + "ftv2mlastnode.gif"
  310. else
  311. srcStr = ICONPATH + "ftv2plastnode.gif"
  312. }
  313. else
  314. {
  315. if (this.nChildren == 0)
  316. srcStr = ICONPATH + "ftv2node.gif"
  317. else
  318. if (this.isOpen)
  319. srcStr = ICONPATH + "ftv2mnode.gif"
  320. else
  321. srcStr = ICONPATH + "ftv2pnode.gif"
  322. }
  323. return srcStr;
  324. }
  325. function iconImageSrc() {
  326. if (this.isOpen)
  327. return(this.iconSrc)
  328. else
  329. return(this.iconSrcClosed)
  330. }
  331. // Definition of class Item (a document or link inside a Folder)
  332. // *************************************************************
  333. function Item(itemDescription) // Constructor
  334. {
  335. // constant data
  336. this.desc = itemDescription
  337. this.level = 0
  338. this.isLastNode = false
  339. this.leftSideCoded = ""
  340. this.parentObj = null
  341. this.maySelect=true
  342. this.initialize = initializeItem;
  343. this.createIndex = createEntryIndex;
  344. this.forceOpeningOfAncestorFolders = forceOpeningOfAncestorFolders;
  345. finalizeCreationOfItem(this)
  346. }
  347. //Assignments that can be delayed when the item is created with folder.addChildren
  348. //The assignments that cannot be delayed are done in addChildren and in initializeFolder
  349. //Additionaly, some assignments are also done in finalizeCreationOfChildDocs itself
  350. function finalizeCreationOfItem(itemArray)
  351. {
  352. itemArray.navObj = 0 //initialized in render()
  353. itemArray.iconImg = 0 //initialized in render()
  354. itemArray.iconSrc = ICONPATH + "ftv2doc.gif"
  355. itemArray.isRendered = 0
  356. itemArray.nChildren = 0
  357. itemArray.prependHTML = ""
  358. // methods
  359. itemArray.escondeBlock = escondeBlock
  360. itemArray.esconde = escondeBlock
  361. itemArray.folderMstr = folderMstr
  362. itemArray.renderOb = drawItem
  363. itemArray.totalHeight = totalHeight
  364. itemArray.blockStartHTML = blockStartHTML
  365. itemArray.blockEndHTML = blockEndHTML
  366. itemArray.getID = getID
  367. }
  368. function initializeItem(level, lastNode, leftSide)
  369. {
  370. this.createIndex()
  371. this.level = level
  372. this.leftSideCoded = leftSide
  373. this.isLastNode = lastNode
  374. }
  375. function drawItem(insertAtObj)
  376. {
  377. var leftSide = leftSideHTML(this.leftSideCoded)
  378. var docW = ""
  379. var fullLink = "href=\""+this.link+"\" target=\""+this.target+"\" onClick=\"clickOnLink('"+this.getID()+"\', '"+this.link+"','"+this.target+"');return false;\"";
  380. this.isRendered = 1
  381. if (this.level>0)
  382. if (this.isLastNode) //the last 'brother' in the children array
  383. {
  384. leftSide = leftSide + "<td valign=top><img src='" + ICONPATH + "ftv2lastnode.gif' width=16 height=22></td>"
  385. }
  386. else
  387. {
  388. leftSide = leftSide + "<td valign=top background=" + ICONPATH + "ftv2vertline.gif><img src='" + ICONPATH + "ftv2node.gif' width=16 height=22></td>"
  389. }
  390. docW = docW + this.blockStartHTML("item")
  391. docW = docW + "<tr>" + leftSide + "<td valign=top>"
  392. if (USEICONS)
  393. docW = docW + "<a " + fullLink + " id=\"itemIconLink"+this.id+"\">" + "<img id='itemIcon"+this.id+"' " + "src='"+this.iconSrc+"' border=0>" + "</a>"
  394. else
  395. if (this.prependHTML == "")
  396. docW = docW + "<img src=" + ICONPATH + "ftv2blank.gif height=2 width=3>"
  397. if (WRAPTEXT)
  398. docW = docW + "</td>"+this.prependHTML+"<td valign=middle width=100%>"
  399. else
  400. docW = docW + "</td>"+this.prependHTML+"<td valign=middle nowrap width=100%>"
  401. if (USETEXTLINKS)
  402. docW = docW + "<a " + fullLink + " id=\"itemTextLink"+this.id+"\">" + this.desc + "</a>"
  403. else
  404. docW = docW + this.desc
  405. docW = docW + "</td>"
  406. docW = docW + this.blockEndHTML()
  407. if (insertAtObj == null)
  408. {
  409. doc.write(docW)
  410. }
  411. else
  412. {
  413. insertAtObj.insertAdjacentHTML("afterEnd", docW)
  414. }
  415. if (browserVersion == 2) {
  416. this.navObj = doc.layers["item"+this.id]
  417. if (USEICONS)
  418. this.iconImg = this.navObj.document.images["itemIcon"+this.id]
  419. doc.yPos=doc.yPos+this.navObj.clip.height
  420. } else if (browserVersion != 0) {
  421. this.navObj = getElById("item"+this.id)
  422. if (USEICONS)
  423. this.iconImg = getElById("itemIcon"+this.id)
  424. }
  425. }
  426. // Methods common to both objects (pseudo-inheritance)
  427. // ********************************************************
  428. function forceOpeningOfAncestorFolders() {
  429. if (this.parentObj == null || this.parentObj.isOpen)
  430. return
  431. else {
  432. this.parentObj.forceOpeningOfAncestorFolders()
  433. clickOnNodeObj(this.parentObj)
  434. }
  435. }
  436. function escondeBlock()
  437. {
  438. if (browserVersion == 1 || browserVersion == 3) {
  439. if (this.navObj.style.display == "none")
  440. return
  441. this.navObj.style.display = "none"
  442. } else {
  443. if (this.navObj.visibility == "hidden")
  444. return
  445. this.navObj.visibility = "hidden"
  446. }
  447. }
  448. function folderMstr(domObj)
  449. {
  450. if (browserVersion == 1 || browserVersion == 3) {
  451. if (t==-1)
  452. return
  453. var str = new String(doc.links[t])
  454. if (str.slice(14,16) != "em")
  455. return
  456. }
  457. if (!this.isRendered)
  458. this.renderOb(domObj)
  459. else
  460. if (browserVersion == 1 || browserVersion == 3)
  461. this.navObj.style.display = "block"
  462. else
  463. this.navObj.visibility = "show"
  464. }
  465. function blockStartHTML(idprefix) {
  466. var idParam = "id='" + idprefix + this.id + "'"
  467. var docW = ""
  468. if (browserVersion == 2)
  469. docW = "<layer "+ idParam + " top=" + doc.yPos + " visibility=show>"
  470. else if (browserVersion != 0)
  471. docW = "<div " + idParam + " style='display:block; position:block;'>"
  472. docW = docW + "<table border=0 cellspacing=0 cellpadding=0 width=100% >"
  473. return docW
  474. }
  475. function blockEndHTML() {
  476. var docW = ""
  477. docW = "</table>"
  478. if (browserVersion == 2)
  479. docW = docW + "</layer>"
  480. else if (browserVersion != 0)
  481. docW = docW + "</div>"
  482. return docW
  483. }
  484. function createEntryIndex()
  485. {
  486. this.id = nEntries
  487. indexOfEntries[nEntries] = this
  488. nEntries++
  489. }
  490. // total height of subEntries open
  491. function totalHeight() //used with browserVersion == 2
  492. {
  493. var h = this.navObj.clip.height
  494. var i = 0
  495. if (this.isOpen) //is a folder and _is_ open
  496. for (i=0 ; i < this.nChildren; i++)
  497. h = h + this.children[i].totalHeight()
  498. return h
  499. }
  500. function leftSideHTML(leftSideCoded) {
  501. var i;
  502. var retStr = "";
  503. for (i=0; i<leftSideCoded.length; i++)
  504. {
  505. if (leftSideCoded.charAt(i) == "1")
  506. {
  507. retStr = retStr + "<td valign=top background=" + ICONPATH + "ftv2vertline.gif><img src='" + ICONPATH + "ftv2vertline.gif' width=16 height=22></td>"
  508. }
  509. if (leftSideCoded.charAt(i) == "0")
  510. {
  511. retStr = retStr + "<td valign=top><img src='" + ICONPATH + "ftv2blank.gif' width=16 height=22></td>"
  512. }
  513. }
  514. return retStr
  515. }
  516. function getID()
  517. {
  518. //define a .xID in all nodes (folders and items) if you want to PERVESTATE that
  519. //work when the tree changes. The value eXternal value must be unique for each
  520. //node and must node change when other nodes are added or removed
  521. //The value may be numeric or string, but cannot have the same char used in cookieCutter
  522. if (typeof this.xID != "undefined")
  523. return this.xID
  524. else
  525. return this.id
  526. }
  527. // Events
  528. // *********************************************************
  529. function clickOnFolder(folderId)
  530. {
  531. var clicked = findObj(folderId)
  532. if (typeof clicked=='undefined' || clicked==null)
  533. {
  534. //alert("Treeview was not able to find the node object corresponding to ID=" + folderId + ". If the configuration file sets a.xID values, it must set them for ALL nodes, including the foldersTree root.")
  535. return;
  536. }
  537. if (!clicked.isOpen) {
  538. clickOnNodeObj(clicked)
  539. }
  540. if (lastOpenedFolder != null && lastOpenedFolder != folderId)
  541. clickOnNode(lastOpenedFolder); //sets lastOpenedFolder to null
  542. if (clicked.nChildren==0) {
  543. lastOpenedFolder = folderId;
  544. clicked.isLastOpenedfolder = true
  545. }
  546. if (isLinked(clicked.hreference)) {
  547. highlightObjLink(clicked);
  548. }
  549. }
  550. function clickOnNode(folderId)
  551. {
  552. fOb = findObj(folderId);
  553. if (typeof fOb=='undefined' || fOb==null)
  554. {
  555. //alert("Treeview was not able to find the node object corresponding to ID=" + folderId + ". If the configuration file sets a.xID, it must set foldersTree.xID as well.")
  556. return;
  557. }
  558. clickOnNodeObj(fOb);
  559. }
  560. function clickOnNodeObj(folderObj)
  561. {
  562. var state = 0
  563. var currentOpen
  564. state = folderObj.isOpen
  565. folderObj.setState(!state) //open<->close
  566. if (folderObj.id!=foldersTree.id && PRESERVESTATE)
  567. {
  568. currentOpen = GetCookie("clickedFolder")
  569. if (currentOpen == null)
  570. currentOpen = ""
  571. if (!folderObj.isOpen) //closing
  572. {
  573. currentOpen = currentOpen.replace(folderObj.getID()+cookieCutter, "")
  574. SetCookie("clickedFolder", currentOpen)
  575. }
  576. else
  577. SetCookie("clickedFolder", currentOpen+folderObj.getID()+cookieCutter)
  578. }
  579. }
  580. function clickOnLink(clickedId, target, windowName) {
  581. highlightObjLink(findObj(clickedId));
  582. if (isLinked(target)) {
  583. window.open(target,windowName);
  584. }
  585. }
  586. function ld ()
  587. {
  588. return document.links.length-1
  589. }
  590. // Auxiliary Functions
  591. // *******************
  592. function finalizeCreationOfChildDocs(folderObj) {
  593. for(i=0; i < folderObj.nChildren; i++) {
  594. child = folderObj.children[i]
  595. if (typeof child[0] != 'undefined')
  596. {
  597. // Amazingly, arrays can have members, so a = ["a", "b"]; a.desc="asdas" works
  598. // If a doc was inserted as an array, we can transform it into an itemObj by adding
  599. // the missing members and functions
  600. child.desc = child[0]
  601. setItemLink(child, GLOBALTARGET, child[1])
  602. finalizeCreationOfItem(child)
  603. }
  604. }
  605. }
  606. function findObj(id)
  607. {
  608. var i=0;
  609. var nodeObj;
  610. if (typeof foldersTree.xID != "undefined") {
  611. nodeObj = indexOfEntries[i];
  612. for(i=0;i<nEntries&&indexOfEntries[i].xID!=id;i++) //may need optimization
  613. ;
  614. id = i
  615. }
  616. if (id >= nEntries)
  617. return null; //example: node removed in DB
  618. else
  619. return indexOfEntries[id];
  620. }
  621. function isLinked(hrefText) {
  622. var result = true;
  623. result = (result && hrefText !=null);
  624. result = (result && hrefText != '');
  625. result = (result && hrefText.indexOf('undefined') < 0);
  626. result = (result && hrefText.indexOf('parent.op') < 0);
  627. return result;
  628. }
  629. // Do highlighting by changing background and foreg. colors of folder or doc text
  630. function highlightObjLink(nodeObj) {
  631. if (!HIGHLIGHT || nodeObj==null || nodeObj.maySelect==false) {//node deleted in DB
  632. return;
  633. }
  634. if (browserVersion == 1 || browserVersion == 3) {
  635. var clickedDOMObj = getElById('itemTextLink'+nodeObj.id);
  636. if (clickedDOMObj != null) {
  637. if (lastClicked != null) {
  638. var prevClickedDOMObj = getElById('itemTextLink'+lastClicked.id);
  639. prevClickedDOMObj.style.color=lastClickedColor;
  640. prevClickedDOMObj.style.backgroundColor=lastClickedBgColor;
  641. }
  642. lastClickedColor = clickedDOMObj.style.color;
  643. lastClickedBgColor = clickedDOMObj.style.backgroundColor;
  644. clickedDOMObj.style.color=HIGHLIGHT_COLOR;
  645. clickedDOMObj.style.backgroundColor=HIGHLIGHT_BG;
  646. }
  647. }
  648. lastClicked = nodeObj;
  649. if (PRESERVESTATE)
  650. SetCookie('highlightedTreeviewLink', nodeObj.getID());
  651. }
  652. function insFld(parentFolder, childFolder)
  653. {
  654. return parentFolder.addChild(childFolder)
  655. }
  656. function insDoc(parentFolder, document)
  657. {
  658. return parentFolder.addChild(document)
  659. }
  660. function gFld(description, hreference)
  661. {
  662. folder = new Folder(description, hreference);
  663. return folder;
  664. }
  665. function gLnk(optionFlags, description, linkData)
  666. {
  667. if (optionFlags>=0) { //is numeric (old style) or empty (error)
  668. //Target changed from numeric to string in Aug 2002, and support for numeric style was entirely dropped in Mar 2004
  669. //alert("Change your Treeview configuration file to use the new style of target argument in gLnk");
  670. return;
  671. }
  672. newItem = new Item(description);
  673. setItemLink(newItem, optionFlags, linkData);
  674. return newItem;
  675. }
  676. function setItemLink(item, optionFlags, linkData) {
  677. var targetFlag = "";
  678. var target = "";
  679. var protocolFlag = "";
  680. var protocol = "";
  681. targetFlag = optionFlags.charAt(0)
  682. if (targetFlag=="B")
  683. target = "_blank"
  684. if (targetFlag=="P")
  685. target = "_parent"
  686. if (targetFlag=="R")
  687. target = "basefrm"
  688. if (targetFlag=="S")
  689. target = "_self"
  690. if (targetFlag=="T")
  691. target = "_top"
  692. if (optionFlags.length > 1) {
  693. protocolFlag = optionFlags.charAt(1)
  694. if (protocolFlag=="h")
  695. protocol = "http://"
  696. if (protocolFlag=="s")
  697. protocol = "https://"
  698. if (protocolFlag=="f")
  699. protocol = "ftp://"
  700. if (protocolFlag=="m")
  701. protocol = "mailto:"
  702. }
  703. item.link = protocol+linkData;
  704. item.target = target
  705. }
  706. //Function created for backwards compatibility purposes
  707. //Function contents voided in March 2004
  708. function oldGLnk(target, description, linkData)
  709. {
  710. }
  711. function preLoadIcons() {
  712. var auxImg
  713. auxImg = new Image();
  714. auxImg.src = ICONPATH + "ftv2vertline.gif";
  715. auxImg.src = ICONPATH + "ftv2mlastnode.gif";
  716. auxImg.src = ICONPATH + "ftv2mnode.gif";
  717. auxImg.src = ICONPATH + "ftv2plastnode.gif";
  718. auxImg.src = ICONPATH + "ftv2pnode.gif";
  719. auxImg.src = ICONPATH + "ftv2blank.gif";
  720. auxImg.src = ICONPATH + "ftv2lastnode.gif";
  721. auxImg.src = ICONPATH + "ftv2node.gif";
  722. auxImg.src = ICONPATH + "ftv2folderclosed.gif";
  723. auxImg.src = ICONPATH + "ftv2folderopen.gif";
  724. auxImg.src = ICONPATH + "ftv2doc.gif";
  725. }
  726. //Open some folders for initial layout, if necessary
  727. function setInitialLayout() {
  728. if (browserVersion > 0 && !STARTALLOPEN)
  729. clickOnNodeObj(foldersTree);
  730. if (!STARTALLOPEN && (browserVersion > 0) && PRESERVESTATE)
  731. PersistentFolderOpening();
  732. }
  733. //Used with NS4 and STARTALLOPEN
  734. function renderAllTree(nodeObj, parent) {
  735. var i=0;
  736. nodeObj.renderOb(parent)
  737. if (supportsDeferral)
  738. for (i=nodeObj.nChildren-1; i>=0; i--)
  739. renderAllTree(nodeObj.children[i], nodeObj.navObj)
  740. else
  741. for (i=0 ; i < nodeObj.nChildren; i++)
  742. renderAllTree(nodeObj.children[i], null)
  743. }
  744. function hideWholeTree(nodeObj, hideThisOne, nodeObjMove) {
  745. var i=0;
  746. var heightContained=0;
  747. var childrenMove=nodeObjMove;
  748. if (hideThisOne)
  749. nodeObj.escondeBlock()
  750. if (browserVersion == 2)
  751. nodeObj.navObj.moveBy(0, 0-nodeObjMove)
  752. for (i=0 ; i < nodeObj.nChildren; i++) {
  753. heightContainedInChild = hideWholeTree(nodeObj.children[i], true, childrenMove)
  754. if (browserVersion == 2) {
  755. heightContained = heightContained + heightContainedInChild + nodeObj.children[i].navObj.clip.height
  756. childrenMove = childrenMove + heightContainedInChild
  757. }
  758. }
  759. return heightContained;
  760. }
  761. // Simulating inserAdjacentHTML on NS6
  762. // Code by thor@jscript.dk
  763. // ******************************************
  764. if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement){
  765. HTMLElement.prototype.insertAdjacentElement = function (where,parsedNode)
  766. {
  767. switch (where){
  768. case 'beforeBegin':
  769. this.parentNode.insertBefore(parsedNode,this)
  770. break;
  771. case 'afterBegin':
  772. this.insertBefore(parsedNode,this.firstChild);
  773. break;
  774. case 'beforeEnd':
  775. this.appendChild(parsedNode);
  776. break;
  777. case 'afterEnd':
  778. if (this.nextSibling)
  779. this.parentNode.insertBefore(parsedNode,this.nextSibling);
  780. else this.parentNode.appendChild(parsedNode);
  781. break;
  782. }
  783. }
  784. HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr)
  785. {
  786. var r = this.ownerDocument.createRange();
  787. r.setStartBefore(this);
  788. var parsedHTML = r.createContextualFragment(htmlStr);
  789. this.insertAdjacentElement(where,parsedHTML)
  790. }
  791. }
  792. function getElById(idVal) {
  793. if (document.getElementById != null)
  794. return document.getElementById(idVal)
  795. if (document.all != null)
  796. return document.all[idVal]
  797. //alert("Problem getting element by id")
  798. return null
  799. }
  800. // Functions for cookies
  801. // Note: THESE FUNCTIONS ARE OPTIONAL. No cookies are used unless
  802. // the PRESERVESTATE variable is set to 1 (default 0)
  803. // The separator currently in use is ^ (chr 94)
  804. // ***********************************************************
  805. function PersistentFolderOpening()
  806. {
  807. var stateInCookie;
  808. var fldStr=""
  809. var fldArr
  810. var fldPos=0
  811. var id
  812. var nodeObj
  813. stateInCookie = GetCookie("clickedFolder");
  814. SetCookie('clickedFolder', "") //at the end of function it will be back, minus null cases
  815. if(stateInCookie!=null)
  816. {
  817. fldArr = stateInCookie.split(cookieCutter)
  818. for (fldPos=0; fldPos<fldArr.length; fldPos++)
  819. {
  820. fldStr=fldArr[fldPos]
  821. if (fldStr != "") {
  822. nodeObj = findObj(fldStr)
  823. if (nodeObj!=null) //may have been deleted
  824. if (nodeObj.setState) {
  825. nodeObj.forceOpeningOfAncestorFolders()
  826. clickOnNodeObj(nodeObj);
  827. }
  828. else{
  829. //alert("Internal id is not pointing to a folder anymore.\nConsider giving an ID to the tree and external IDs to the individual nodes.")
  830. }
  831. }
  832. }
  833. }
  834. }
  835. function storeAllNodesInClickCookie(treeNodeObj)
  836. {
  837. var currentOpen
  838. var i = 0
  839. if (typeof treeNodeObj.setState != "undefined") //is folder
  840. {
  841. currentOpen = GetCookie("clickedFolder")
  842. if (currentOpen == null)
  843. currentOpen = ""
  844. if (treeNodeObj.getID() != foldersTree.getID())
  845. SetCookie("clickedFolder", currentOpen+treeNodeObj.getID()+cookieCutter)
  846. for (i=0; i < treeNodeObj.nChildren; i++)
  847. storeAllNodesInClickCookie(treeNodeObj.children[i])
  848. }
  849. }
  850. function CookieBranding(name) {
  851. if (typeof foldersTree.treeID != "undefined")
  852. return name+foldersTree.treeID //needed for multi-tree sites. make sure treeId does not contain cookieCutter
  853. else
  854. return name
  855. }
  856. function GetCookie(name)
  857. {
  858. name = CookieBranding(name)
  859. var arg = name + "=";
  860. var alen = arg.length;
  861. var clen = document.cookie.length;
  862. var i = 0;
  863. while (i < clen) {
  864. var j = i + alen;
  865. if (document.cookie.substring(i, j) == arg)
  866. return getCookieVal (j);
  867. i = document.cookie.indexOf(" ", i) + 1;
  868. if (i == 0) break;
  869. }
  870. return null;
  871. }
  872. function getCookieVal(offset) {
  873. var endstr = document.cookie.indexOf (";", offset);
  874. if (endstr == -1)
  875. endstr = document.cookie.length;
  876. return unescape(document.cookie.substring(offset, endstr));
  877. }
  878. function SetCookie(name, value)
  879. {
  880. var argv = SetCookie.arguments;
  881. var argc = SetCookie.arguments.length;
  882. var expires = (argc > 2) ? argv[2] : null;
  883. //var path = (argc > 3) ? argv[3] : null;
  884. var domain = (argc > 4) ? argv[4] : null;
  885. var secure = (argc > 5) ? argv[5] : false;
  886. var path = "/"; //allows the tree to remain open across pages with diff names & paths
  887. name = CookieBranding(name)
  888. document.cookie = name + "=" + escape (value) +
  889. ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
  890. ((path == null) ? "" : ("; path=" + path)) +
  891. ((domain == null) ? "" : ("; domain=" + domain)) +
  892. ((secure == true) ? "; secure" : "");
  893. }
  894. function ExpireCookie (name)
  895. {
  896. var exp = new Date();
  897. exp.setTime (exp.getTime() - 1);
  898. var cval = GetCookie (name);
  899. name = CookieBranding(name)
  900. document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
  901. }
  902. //Open All
  903. function expandTree(folderObj)
  904. {
  905. var childObj;
  906. var i;
  907. if (!folderObj.isOpen)
  908. clickOnNodeObj(folderObj)
  909. //Call this function for all folder children
  910. for (i=0 ; i < folderObj.nChildren; i++) {
  911. childObj = folderObj.children[i]
  912. if (typeof childObj.setState != "undefined") {//is folder
  913. expandTree(childObj)
  914. }
  915. }
  916. }
  917. //To customize the tree, overwrite these variables in the configuration file (demoFramesetNode.js, etc.)
  918. var USETEXTLINKS = 0;
  919. var STARTALLOPEN = 0;
  920. var USEFRAMES = 1;
  921. var USEICONS = 1;
  922. var WRAPTEXT = 0;
  923. var PERSERVESTATE = 0; //backward compatibility
  924. var PRESERVESTATE = 0;
  925. var ICONPATH = '';
  926. var HIGHLIGHT = 0;
  927. var HIGHLIGHT_COLOR = 'white';
  928. var HIGHLIGHT_BG = 'blue';
  929. var BUILDALL = 0;
  930. var GLOBALTARGET = "R"; // variable only applicable for addChildren uses
  931. //Other variables
  932. var lastClicked = null;
  933. var lastClickedColor;
  934. var lastClickedBgColor;
  935. var indexOfEntries = new Array
  936. var nEntries = 0
  937. var browserVersion = 0
  938. var selectedFolder=0
  939. var lastOpenedFolder=null
  940. var t=5
  941. var doc = document
  942. var supportsDeferral = false
  943. var cookieCutter = '^' //You can change this if you need to use ^ in your xID or treeID values
  944. doc.yPos = 0
  945. // Main function
  946. // *************
  947. // This function uses an object (navigator) defined in
  948. // ua.js, imported in the main html page (left frame).
  949. function initializeDocument()
  950. {
  951. preLoadIcons();
  952. switch(navigator.family)
  953. {
  954. case 'ie4':
  955. browserVersion = 1 //Simply means IE > 3.x
  956. break;
  957. case 'opera':
  958. browserVersion = (navigator.version > 6 ? 1 : 0); //opera7 has a good DOM
  959. break;
  960. case 'nn4':
  961. browserVersion = 2 //NS4.x
  962. break;
  963. case 'gecko':
  964. browserVersion = 3 //NS6.x
  965. break;
  966. case 'safari':
  967. browserVersion = 1 //Safari Beta 3 seems to behave like IE in spite of being based on Konkeror
  968. break;
  969. default:
  970. browserVersion = 0 //other, possibly without DHTML
  971. break;
  972. }
  973. // backward compatibility
  974. if (PERSERVESTATE)
  975. PRESERVESTATE = 1;
  976. supportsDeferral = ((navigator.family=='ie4' && navigator.version >= 5 && navigator.OS != "mac") || browserVersion == 3);
  977. supportsDeferral = supportsDeferral & (!BUILDALL)
  978. if (!USEFRAMES && browserVersion == 2)
  979. browserVersion = 0;
  980. eval(String.fromCharCode(116,61,108,100,40,41))
  981. //If PRESERVESTATE is on, STARTALLOPEN can only be effective the first time the page
  982. //loads during the session. For subsequent (re)loads the PRESERVESTATE data stored
  983. //in cookies takes over the control of the initial expand/collapse
  984. if (PRESERVESTATE && GetCookie("clickedFolder") != null)
  985. STARTALLOPEN = 0
  986. //foldersTree (with the site's data) is created in an external .js (demoFramesetNode.js, for example)
  987. foldersTree.initialize(0, true, "")
  988. if (supportsDeferral && !STARTALLOPEN) {
  989. foldersTree.renderOb(null) //delay construction of nodes
  990. }
  991. else {
  992. renderAllTree(foldersTree, null);
  993. if (PRESERVESTATE && STARTALLOPEN)
  994. storeAllNodesInClickCookie(foldersTree)
  995. //To force the scrollable area to be big enough
  996. if (browserVersion == 2)
  997. doc.write("<layer top=" + indexOfEntries[nEntries-1].navObj.top + ">&nbsp;</layer>")
  998. if (browserVersion != 0 && !STARTALLOPEN)
  999. hideWholeTree(foldersTree, false, 0)
  1000. }
  1001. setInitialLayout()
  1002. if (PRESERVESTATE && GetCookie('highlightedTreeviewLink')!=null && GetCookie('highlightedTreeviewLink')!="") {
  1003. var nodeObj = findObj(GetCookie('highlightedTreeviewLink'))
  1004. if (nodeObj!=null){
  1005. nodeObj.forceOpeningOfAncestorFolders()
  1006. highlightObjLink(nodeObj);
  1007. }
  1008. else
  1009. SetCookie('highlightedTreeviewLink', '')
  1010. }
  1011. }