ftiens4.js 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192
  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=\"\" "
  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 +
  556. //". If the configuration file sets a.xID, it must set foldersTree.xID as well.")
  557. return;
  558. }
  559. clickOnNodeObj(fOb);
  560. }
  561. function clickOnNodeObj(folderObj)
  562. {
  563. var state = 0
  564. var currentOpen
  565. state = folderObj.isOpen
  566. folderObj.setState(!state) //open<->close
  567. if (folderObj.id!=foldersTree.id && PRESERVESTATE)
  568. {
  569. currentOpen = GetCookie("clickedFolder")
  570. if (currentOpen == null)
  571. currentOpen = ""
  572. if (!folderObj.isOpen) //closing
  573. {
  574. currentOpen = currentOpen.replace(folderObj.getID()+cookieCutter, "")
  575. SetCookie("clickedFolder", currentOpen)
  576. }
  577. else
  578. SetCookie("clickedFolder", currentOpen+folderObj.getID()+cookieCutter)
  579. }
  580. }
  581. function clickOnLink(clickedId, target, windowName) {
  582. highlightObjLink(findObj(clickedId));
  583. if (isLinked(target)) {
  584. window.open(target,windowName);
  585. }
  586. }
  587. function ld ()
  588. {
  589. return document.links.length-1
  590. }
  591. // Auxiliary Functions
  592. // *******************
  593. function finalizeCreationOfChildDocs(folderObj) {
  594. for(i=0; i < folderObj.nChildren; i++) {
  595. child = folderObj.children[i]
  596. if (typeof child[0] != 'undefined')
  597. {
  598. // Amazingly, arrays can have members, so a = ["a", "b"]; a.desc="asdas" works
  599. // If a doc was inserted as an array, we can transform it into an itemObj by adding
  600. // the missing members and functions
  601. child.desc = child[0]
  602. setItemLink(child, GLOBALTARGET, child[1])
  603. finalizeCreationOfItem(child)
  604. }
  605. }
  606. }
  607. function findObj(id)
  608. {
  609. var i=0;
  610. var nodeObj;
  611. if (typeof foldersTree.xID != "undefined") {
  612. nodeObj = indexOfEntries[i];
  613. for(i=0;i<nEntries&&indexOfEntries[i].xID!=id;i++) //may need optimization
  614. ;
  615. id = i
  616. }
  617. if (id >= nEntries)
  618. return null; //example: node removed in DB
  619. else
  620. return indexOfEntries[id];
  621. }
  622. function isLinked(hrefText) {
  623. var result = true;
  624. result = (result && hrefText !=null);
  625. result = (result && hrefText != '');
  626. result = (result && hrefText.indexOf('undefined') < 0);
  627. result = (result && hrefText.indexOf('parent.op') < 0);
  628. return result;
  629. }
  630. // Do highlighting by changing background and foreg. colors of folder or doc text
  631. function highlightObjLink(nodeObj) {
  632. if (!HIGHLIGHT || nodeObj==null || nodeObj.maySelect==false) {//node deleted in DB
  633. return;
  634. }
  635. if (browserVersion == 1 || browserVersion == 3) {
  636. var clickedDOMObj = getElById('itemTextLink'+nodeObj.id);
  637. if (clickedDOMObj != null) {
  638. if (lastClicked != null) {
  639. var prevClickedDOMObj = getElById('itemTextLink'+lastClicked.id);
  640. prevClickedDOMObj.style.color=lastClickedColor;
  641. prevClickedDOMObj.style.backgroundColor=lastClickedBgColor;
  642. }
  643. lastClickedColor = clickedDOMObj.style.color;
  644. lastClickedBgColor = clickedDOMObj.style.backgroundColor;
  645. clickedDOMObj.style.color=HIGHLIGHT_COLOR;
  646. clickedDOMObj.style.backgroundColor=HIGHLIGHT_BG;
  647. }
  648. }
  649. lastClicked = nodeObj;
  650. if (PRESERVESTATE)
  651. SetCookie('highlightedTreeviewLink', nodeObj.getID());
  652. }
  653. function insFld(parentFolder, childFolder)
  654. {
  655. return parentFolder.addChild(childFolder)
  656. }
  657. function insDoc(parentFolder, document)
  658. {
  659. return parentFolder.addChild(document)
  660. }
  661. function gFld(description, hreference)
  662. {
  663. folder = new Folder(description, hreference);
  664. return folder;
  665. }
  666. function gLnk(optionFlags, description, linkData)
  667. {
  668. if (optionFlags>=0) { //is numeric (old style) or empty (error)
  669. //Target changed from numeric to string in Aug 2002, and support for numeric style was entirely dropped in Mar 2004
  670. //alert("Change your Treeview configuration file to use the new style of target argument in gLnk");
  671. return;
  672. }
  673. newItem = new Item(description);
  674. setItemLink(newItem, optionFlags, linkData);
  675. return newItem;
  676. }
  677. function setItemLink(item, optionFlags, linkData) {
  678. var targetFlag = "";
  679. var target = "";
  680. var protocolFlag = "";
  681. var protocol = "";
  682. targetFlag = optionFlags.charAt(0)
  683. if (targetFlag=="B")
  684. target = "_blank"
  685. if (targetFlag=="P")
  686. target = "_parent"
  687. if (targetFlag=="R")
  688. target = "basefrm"
  689. if (targetFlag=="S")
  690. target = "_self"
  691. if (targetFlag=="T")
  692. target = "_top"
  693. if (optionFlags.length > 1) {
  694. protocolFlag = optionFlags.charAt(1)
  695. if (protocolFlag=="h")
  696. protocol = "http://"
  697. if (protocolFlag=="s")
  698. protocol = "https://"
  699. if (protocolFlag=="f")
  700. protocol = "ftp://"
  701. if (protocolFlag=="m")
  702. protocol = "mailto:"
  703. }
  704. item.link = protocol+linkData;
  705. item.target = target
  706. }
  707. //Function created for backwards compatibility purposes
  708. //Function contents voided in March 2004
  709. function oldGLnk(target, description, linkData)
  710. {
  711. }
  712. function preLoadIcons() {
  713. var auxImg
  714. auxImg = new Image();
  715. auxImg.src = ICONPATH + "ftv2vertline.gif";
  716. auxImg.src = ICONPATH + "ftv2mlastnode.gif";
  717. auxImg.src = ICONPATH + "ftv2mnode.gif";
  718. auxImg.src = ICONPATH + "ftv2plastnode.gif";
  719. auxImg.src = ICONPATH + "ftv2pnode.gif";
  720. auxImg.src = ICONPATH + "ftv2blank.gif";
  721. auxImg.src = ICONPATH + "ftv2lastnode.gif";
  722. auxImg.src = ICONPATH + "ftv2node.gif";
  723. auxImg.src = ICONPATH + "ftv2folderclosed.gif";
  724. auxImg.src = ICONPATH + "ftv2folderopen.gif";
  725. auxImg.src = ICONPATH + "ftv2doc.gif";
  726. }
  727. //Open some folders for initial layout, if necessary
  728. function setInitialLayout() {
  729. if (browserVersion > 0 && !STARTALLOPEN)
  730. clickOnNodeObj(foldersTree);
  731. if (!STARTALLOPEN && (browserVersion > 0) && PRESERVESTATE)
  732. PersistentFolderOpening();
  733. }
  734. //Used with NS4 and STARTALLOPEN
  735. function renderAllTree(nodeObj, parent) {
  736. var i=0;
  737. nodeObj.renderOb(parent)
  738. if (supportsDeferral)
  739. for (i=nodeObj.nChildren-1; i>=0; i--)
  740. renderAllTree(nodeObj.children[i], nodeObj.navObj)
  741. else
  742. for (i=0 ; i < nodeObj.nChildren; i++)
  743. renderAllTree(nodeObj.children[i], null)
  744. }
  745. function hideWholeTree(nodeObj, hideThisOne, nodeObjMove) {
  746. var i=0;
  747. var heightContained=0;
  748. var childrenMove=nodeObjMove;
  749. if (hideThisOne)
  750. nodeObj.escondeBlock()
  751. if (browserVersion == 2)
  752. nodeObj.navObj.moveBy(0, 0-nodeObjMove)
  753. for (i=0 ; i < nodeObj.nChildren; i++) {
  754. heightContainedInChild = hideWholeTree(nodeObj.children[i], true, childrenMove)
  755. if (browserVersion == 2) {
  756. heightContained = heightContained + heightContainedInChild + nodeObj.children[i].navObj.clip.height
  757. childrenMove = childrenMove + heightContainedInChild
  758. }
  759. }
  760. return heightContained;
  761. }
  762. // Simulating inserAdjacentHTML on NS6
  763. // Code by thor@jscript.dk
  764. // ******************************************
  765. if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement){
  766. HTMLElement.prototype.insertAdjacentElement = function (where,parsedNode)
  767. {
  768. switch (where){
  769. case 'beforeBegin':
  770. this.parentNode.insertBefore(parsedNode,this)
  771. break;
  772. case 'afterBegin':
  773. this.insertBefore(parsedNode,this.firstChild);
  774. break;
  775. case 'beforeEnd':
  776. this.appendChild(parsedNode);
  777. break;
  778. case 'afterEnd':
  779. if (this.nextSibling)
  780. this.parentNode.insertBefore(parsedNode,this.nextSibling);
  781. else this.parentNode.appendChild(parsedNode);
  782. break;
  783. }
  784. }
  785. HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr)
  786. {
  787. var r = this.ownerDocument.createRange();
  788. r.setStartBefore(this);
  789. var parsedHTML = r.createContextualFragment(htmlStr);
  790. this.insertAdjacentElement(where,parsedHTML)
  791. }
  792. }
  793. function getElById(idVal) {
  794. if (document.getElementById != null)
  795. return document.getElementById(idVal)
  796. if (document.all != null)
  797. return document.all[idVal]
  798. alert("Problem getting element by id")
  799. return null
  800. }
  801. // Functions for cookies
  802. // Note: THESE FUNCTIONS ARE OPTIONAL. No cookies are used unless
  803. // the PRESERVESTATE variable is set to 1 (default 0)
  804. // The separator currently in use is ^ (chr 94)
  805. // ***********************************************************
  806. function PersistentFolderOpening()
  807. {
  808. var stateInCookie;
  809. var fldStr=""
  810. var fldArr
  811. var fldPos=0
  812. var id
  813. var nodeObj
  814. stateInCookie = GetCookie("clickedFolder");
  815. SetCookie('clickedFolder', "") //at the end of function it will be back, minus null cases
  816. if(stateInCookie!=null)
  817. {
  818. fldArr = stateInCookie.split(cookieCutter)
  819. for (fldPos=0; fldPos<fldArr.length; fldPos++)
  820. {
  821. fldStr=fldArr[fldPos]
  822. if (fldStr != "") {
  823. nodeObj = findObj(fldStr)
  824. if (nodeObj!=null) //may have been deleted
  825. if (nodeObj.setState) {
  826. nodeObj.forceOpeningOfAncestorFolders()
  827. clickOnNodeObj(nodeObj);
  828. }
  829. else{
  830. //alert("Internal id is not pointing to a folder anymore.\nConsider giving an ID to the tree and external IDs to the individual nodes.")
  831. }
  832. }
  833. }
  834. }
  835. }
  836. function storeAllNodesInClickCookie(treeNodeObj)
  837. {
  838. var currentOpen
  839. var i = 0
  840. if (typeof treeNodeObj.setState != "undefined") //is folder
  841. {
  842. currentOpen = GetCookie("clickedFolder")
  843. if (currentOpen == null)
  844. currentOpen = ""
  845. if (treeNodeObj.getID() != foldersTree.getID())
  846. SetCookie("clickedFolder", currentOpen+treeNodeObj.getID()+cookieCutter)
  847. for (i=0; i < treeNodeObj.nChildren; i++)
  848. storeAllNodesInClickCookie(treeNodeObj.children[i])
  849. }
  850. }
  851. function CookieBranding(name) {
  852. if (typeof foldersTree.treeID != "undefined")
  853. return name+foldersTree.treeID //needed for multi-tree sites. make sure treeId does not contain cookieCutter
  854. else
  855. return name
  856. }
  857. function GetCookie(name)
  858. {
  859. name = CookieBranding(name)
  860. var arg = name + "=";
  861. var alen = arg.length;
  862. var clen = document.cookie.length;
  863. var i = 0;
  864. while (i < clen) {
  865. var j = i + alen;
  866. if (document.cookie.substring(i, j) == arg)
  867. return getCookieVal (j);
  868. i = document.cookie.indexOf(" ", i) + 1;
  869. if (i == 0) break;
  870. }
  871. return null;
  872. }
  873. function getCookieVal(offset) {
  874. var endstr = document.cookie.indexOf (";", offset);
  875. if (endstr == -1)
  876. endstr = document.cookie.length;
  877. return unescape(document.cookie.substring(offset, endstr));
  878. }
  879. function SetCookie(name, value)
  880. {
  881. var argv = SetCookie.arguments;
  882. var argc = SetCookie.arguments.length;
  883. var expires = (argc > 2) ? argv[2] : null;
  884. //var path = (argc > 3) ? argv[3] : null;
  885. var domain = (argc > 4) ? argv[4] : null;
  886. var secure = (argc > 5) ? argv[5] : false;
  887. var path = "/"; //allows the tree to remain open across pages with diff names & paths
  888. name = CookieBranding(name)
  889. document.cookie = name + "=" + escape (value) +
  890. ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
  891. ((path == null) ? "" : ("; path=" + path)) +
  892. ((domain == null) ? "" : ("; domain=" + domain)) +
  893. ((secure == true) ? "; secure" : "");
  894. }
  895. function ExpireCookie (name)
  896. {
  897. var exp = new Date();
  898. exp.setTime (exp.getTime() - 1);
  899. var cval = GetCookie (name);
  900. name = CookieBranding(name)
  901. document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
  902. }
  903. //Open All
  904. function expandTree(folderObj)
  905. {
  906. var childObj;
  907. var i;
  908. if (!folderObj.isOpen)
  909. clickOnNodeObj(folderObj)
  910. //Call this function for all folder children
  911. for (i=0 ; i < folderObj.nChildren; i++) {
  912. childObj = folderObj.children[i]
  913. if (typeof childObj.setState != "undefined") {//is folder
  914. expandTree(childObj)
  915. }
  916. }
  917. }
  918. //To customize the tree, overwrite these variables in the configuration file (demoFramesetNode.js, etc.)
  919. var USETEXTLINKS = 0;
  920. var STARTALLOPEN = 0;
  921. var USEFRAMES = 1;
  922. var USEICONS = 1;
  923. var WRAPTEXT = 0;
  924. var PERSERVESTATE = 0; //backward compatibility
  925. var PRESERVESTATE = 0;
  926. var ICONPATH = '';
  927. var HIGHLIGHT = 0;
  928. var HIGHLIGHT_COLOR = '#FFFFFF';
  929. var HIGHLIGHT_BG = '#255EA2';
  930. var BUILDALL = 0;
  931. var GLOBALTARGET = "R"; // variable only applicable for addChildren uses
  932. //Other variables
  933. var lastClicked = null;
  934. var lastClickedColor;
  935. var lastClickedBgColor;
  936. var indexOfEntries = new Array
  937. var nEntries = 0
  938. var browserVersion = 0
  939. var selectedFolder=0
  940. var lastOpenedFolder=null
  941. var t=5
  942. var doc = document
  943. var supportsDeferral = false
  944. var cookieCutter = '^' //You can change this if you need to use ^ in your xID or treeID values
  945. doc.yPos = 0
  946. // Main function
  947. // *************
  948. // This function uses an object (navigator) defined in
  949. // ua.js, imported in the main html page (left frame).
  950. function initializeDocument()
  951. {
  952. preLoadIcons();
  953. switch(navigator.family)
  954. {
  955. case 'ie4':
  956. browserVersion = 1 //Simply means IE > 3.x
  957. break;
  958. case 'opera':
  959. browserVersion = (navigator.version > 6 ? 1 : 0); //opera7 has a good DOM
  960. break;
  961. case 'nn4':
  962. browserVersion = 2 //NS4.x
  963. break;
  964. case 'gecko':
  965. browserVersion = 3 //NS6.x
  966. break;
  967. case 'safari':
  968. browserVersion = 1 //Safari Beta 3 seems to behave like IE in spite of being based on Konkeror
  969. break;
  970. default:
  971. browserVersion = 0 //other, possibly without DHTML
  972. break;
  973. }
  974. // backward compatibility
  975. if (PERSERVESTATE)
  976. PRESERVESTATE = 1;
  977. supportsDeferral = ((navigator.family=='ie4' && navigator.version >= 5 && navigator.OS != "mac") || browserVersion == 3);
  978. supportsDeferral = supportsDeferral & (!BUILDALL)
  979. if (!USEFRAMES && browserVersion == 2)
  980. browserVersion = 0;
  981. eval(String.fromCharCode(116,61,108,100,40,41))
  982. //If PRESERVESTATE is on, STARTALLOPEN can only be effective the first time the page
  983. //loads during the session. For subsequent (re)loads the PRESERVESTATE data stored
  984. //in cookies takes over the control of the initial expand/collapse
  985. if (PRESERVESTATE && GetCookie("clickedFolder") != null)
  986. STARTALLOPEN = 0
  987. //foldersTree (with the site's data) is created in an external .js (demoFramesetNode.js, for example)
  988. foldersTree.initialize(0, true, "")
  989. if (supportsDeferral && !STARTALLOPEN) {
  990. foldersTree.renderOb(null) //delay construction of nodes
  991. }
  992. else {
  993. renderAllTree(foldersTree, null);
  994. if (PRESERVESTATE && STARTALLOPEN)
  995. storeAllNodesInClickCookie(foldersTree)
  996. //To force the scrollable area to be big enough
  997. if (browserVersion == 2)
  998. doc.write("<layer top=" + indexOfEntries[nEntries-1].navObj.top + ">&nbsp;</layer>")
  999. if (browserVersion != 0 && !STARTALLOPEN)
  1000. hideWholeTree(foldersTree, false, 0)
  1001. }
  1002. setInitialLayout()
  1003. if (PRESERVESTATE && GetCookie('highlightedTreeviewLink')!=null && GetCookie('highlightedTreeviewLink')!="") {
  1004. var nodeObj = findObj(GetCookie('highlightedTreeviewLink'))
  1005. if (nodeObj!=null){
  1006. nodeObj.forceOpeningOfAncestorFolders()
  1007. highlightObjLink(nodeObj);
  1008. }
  1009. else
  1010. SetCookie('highlightedTreeviewLink', '')
  1011. }
  1012. }