treemenu.js 30 KB

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