treeview.js 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756
  1. /*
  2. This file is part of the DITA Open Toolkit project hosted on
  3. Sourceforge.net. See the accompanying license.txt file for
  4. applicable licenses.
  5. Copyright (c) 2006, Yahoo! Inc. All rights reserved.
  6. Code licensed under the BSD License:
  7. http://developer.yahoo.net/yui/license.txt
  8. version: 0.10.0
  9. */
  10. /* Copyright (c) 2006 Yahoo! Inc. All rights reserved. */
  11. /**
  12. * Contains the tree view state data and the root node. This is an
  13. * ordered tree; child nodes will be displayed in the order created, and
  14. * there currently is no way to change this.
  15. *
  16. * @constructor
  17. * @todo graft (appendBefore, appendAfter)
  18. * @param {string} id The id of the element that the tree will be inserted
  19. * into.
  20. */
  21. YAHOO.widget.TreeView = function(id) {
  22. if (id) { this.init(id); }
  23. };
  24. /**
  25. * Count of all nodes in all trees
  26. * @type int
  27. */
  28. YAHOO.widget.TreeView.nodeCount = 0;
  29. YAHOO.widget.TreeView.prototype = {
  30. /**
  31. * The id of tree container element
  32. *
  33. * @type String
  34. */
  35. id: null,
  36. /**
  37. * Flat collection of all nodes in this tree
  38. *
  39. * @type Node[]
  40. * @private
  41. */
  42. _nodes: null,
  43. /**
  44. * We lock the tree control while waiting for the dynamic loader to return
  45. *
  46. * @type boolean
  47. */
  48. locked: false,
  49. /**
  50. * The animation to use for expanding children, if any
  51. *
  52. * @type string
  53. * @private
  54. */
  55. _expandAnim: null,
  56. /**
  57. * The animation to use for collapsing children, if any
  58. *
  59. * @type string
  60. * @private
  61. */
  62. _collapseAnim: null,
  63. /**
  64. * The current number of animations that are executing
  65. *
  66. * @type int
  67. * @private
  68. */
  69. _animCount: 0,
  70. /**
  71. * The maximum number of animations to run at one time.
  72. *
  73. * @type int
  74. */
  75. maxAnim: 2,
  76. /**
  77. * Sets up the animation for expanding children
  78. *
  79. * @param {string} the type of animation (acceptable constants in YAHOO.widget.TVAnim)
  80. */
  81. setExpandAnim: function(type) {
  82. if (YAHOO.widget.TVAnim.isValid(type)) {
  83. this._expandAnim = type;
  84. }
  85. },
  86. /**
  87. * Sets up the animation for collapsing children
  88. *
  89. * @param {string} the type of animation (acceptable constants in YAHOO.widget.TVAnim)
  90. */
  91. setCollapseAnim: function(type) {
  92. if (YAHOO.widget.TVAnim.isValid(type)) {
  93. this._collapseAnim = type;
  94. }
  95. },
  96. /**
  97. * Perform the expand animation if configured, or just show the
  98. * element if not configured or too many animations are in progress
  99. *
  100. * @param el {HTMLElement} the element to animate
  101. * @return {boolean} true if animation could be invoked, false otherwise
  102. */
  103. animateExpand: function(el) {
  104. if (this._expandAnim && this._animCount < this.maxAnim) {
  105. // this.locked = true;
  106. var tree = this;
  107. var a = YAHOO.widget.TVAnim.getAnim(this._expandAnim, el,
  108. function() { tree.expandComplete(); });
  109. if (a) {
  110. ++this._animCount;
  111. a.animate();
  112. }
  113. return true;
  114. }
  115. return false;
  116. },
  117. /**
  118. * Perform the collapse animation if configured, or just show the
  119. * element if not configured or too many animations are in progress
  120. *
  121. * @param el {HTMLElement} the element to animate
  122. * @return {boolean} true if animation could be invoked, false otherwise
  123. */
  124. animateCollapse: function(el) {
  125. if (this._collapseAnim && this._animCount < this.maxAnim) {
  126. // this.locked = true;
  127. var tree = this;
  128. var a = YAHOO.widget.TVAnim.getAnim(this._collapseAnim, el,
  129. function() { tree.collapseComplete(); });
  130. if (a) {
  131. ++this._animCount;
  132. a.animate();
  133. }
  134. return true;
  135. }
  136. return false;
  137. },
  138. /**
  139. * Function executed when the expand animation completes
  140. */
  141. expandComplete: function() {
  142. --this._animCount;
  143. // this.locked = false;
  144. },
  145. /**
  146. * Function executed when the collapse animation completes
  147. */
  148. collapseComplete: function() {
  149. --this._animCount;
  150. // this.locked = false;
  151. },
  152. /**
  153. * Initializes the tree
  154. *
  155. * @parm {string} id the id of the element that will hold the tree
  156. * @private
  157. */
  158. init: function(id) {
  159. this.id = id;
  160. this._nodes = [];
  161. // store a global reference
  162. YAHOO.widget.TreeView.trees[id] = this;
  163. // Set up the root node
  164. this.root = new YAHOO.widget.RootNode(this);
  165. },
  166. /**
  167. * Renders the tree boilerplate and visible nodes
  168. */
  169. draw: function() {
  170. var html = this.root.getHtml();
  171. if(document.getElementById(this.id))
  172. document.getElementById(this.id).innerHTML = html;
  173. /*document.getElementById(this.id).innerHTML = html;*/
  174. this.firstDraw = false;
  175. },
  176. /**
  177. * Nodes register themselves with the tree instance when they are created.
  178. *
  179. * @param node {Node} the node to register
  180. * @private
  181. */
  182. regNode: function(node) {
  183. this._nodes[node.index] = node;
  184. },
  185. /**
  186. * Returns the root node of this tree
  187. *
  188. * @return {Node} the root node
  189. */
  190. getRoot: function() {
  191. return this.root;
  192. },
  193. /**
  194. * Configures this tree to dynamically load all child data
  195. *
  196. * @param {function} fnDataLoader the function that will be called to get the data
  197. * @param iconMode {int} configures the icon that is displayed when a dynamic
  198. * load node is expanded the first time without children. By default, the
  199. * "collapse" icon will be used. If set to 1, the leaf node icon will be
  200. * displayed.
  201. */
  202. setDynamicLoad: function(fnDataLoader, iconMode) {
  203. this.root.setDynamicLoad(fnDataLoader, iconMode);
  204. },
  205. /**
  206. * Expands all child nodes. Note: this conflicts with the "multiExpand"
  207. * node property. If expand all is called in a tree with nodes that
  208. * do not allow multiple siblings to be displayed, only the last sibling
  209. * will be expanded.
  210. */
  211. expandAll: function() {
  212. if (!this.locked) {
  213. this.root.expandAll();
  214. }
  215. },
  216. /**
  217. * Collapses all expanded child nodes in the entire tree.
  218. */
  219. collapseAll: function() {
  220. if (!this.locked) {
  221. this.root.collapseAll();
  222. }
  223. },
  224. /**
  225. * Returns a node in the tree that has the specified index (this index
  226. * is created internally, so this function probably will only be used
  227. * in html generated for a given node.)
  228. *
  229. * @param {int} nodeIndex the index of the node wanted
  230. * @return {Node} the node with index=nodeIndex, null if no match
  231. */
  232. getNodeByIndex: function(nodeIndex) {
  233. var n = this._nodes[nodeIndex];
  234. return (n) ? n : null;
  235. },
  236. /**
  237. * Returns a node that has a matching property and value in the data
  238. * object that was passed into its constructor. Provides a flexible
  239. * way for the implementer to get a particular node.
  240. *
  241. * @param {object} property the property to search (usually a string)
  242. * @param {object} value the value we want to find (usuall an int or string)
  243. * @return {Node} the matching node, null if no match
  244. */
  245. getNodeByProperty: function(property, value) {
  246. for (var i in this._nodes) {
  247. var n = this._nodes[i];
  248. if (n.data && value == n.data[property]) {
  249. return n;
  250. }
  251. }
  252. return null;
  253. },
  254. /**
  255. * Removes the node and its children, and optionally refreshes the branch
  256. * of the tree that was affected.
  257. * @param {Node} The node to remove
  258. * @param {boolean} autoRefresh automatically refreshes branch if true
  259. * @return {boolean} False is there was a problem, true otherwise.
  260. */
  261. removeNode: function(node, autoRefresh) {
  262. // Don't delete the root node
  263. if (node.isRoot()) {
  264. return false;
  265. }
  266. // Get the branch that we may need to refresh
  267. var p = node.parent;
  268. if (p.parent) {
  269. p = p.parent;
  270. }
  271. // Delete the node and its children
  272. this._deleteNode(node);
  273. // Refresh the parent of the parent
  274. if (autoRefresh && p && p.childrenRendered) {
  275. p.refresh();
  276. }
  277. return true;
  278. },
  279. /**
  280. * Deletes this nodes child collection, recursively. Also collapses
  281. * the node, and resets the dynamic load flag. The primary use for
  282. * this method is to purge a node and allow it to fetch its data
  283. * dynamically again.
  284. * @param {Node} node the node to purge
  285. */
  286. removeChildren: function(node) {
  287. for (var i=0, len=node.children.length;i<len;++i) {
  288. this._deleteNode(node.children[i]);
  289. }
  290. node.childrenRendered = false;
  291. node.dynamicLoadComplete = false;
  292. node.collapse();
  293. },
  294. /**
  295. * Deletes the node and recurses children
  296. * @private
  297. */
  298. _deleteNode: function(node) {
  299. var p = node.parent;
  300. // Remove all the child nodes first
  301. this.removeChildren(node);
  302. // Update the parent's collection of children
  303. var a = [];
  304. for (i=0, len=p.children.length;i<len;++i) {
  305. if (p.children[i] != node) {
  306. a[a.length] = p.children[i];
  307. }
  308. }
  309. p.children = a;
  310. // reset the childrenRendered flag for the parent
  311. p.childrenRendered = false;
  312. // Update the sibling relationship
  313. if (node.previousSibling) {
  314. node.previousSibling.nextSibling = node.nextSibling;
  315. }
  316. if (node.nextSibling) {
  317. node.nextSibling.previousSibling = node.previousSibling;
  318. }
  319. // Update the tree's node collection
  320. delete this._nodes[node.index];
  321. },
  322. /**
  323. * Abstract method that is executed when a node is expanded
  324. *
  325. * @param node {Node} the node that was expanded
  326. */
  327. onExpand: function(node) { },
  328. /**
  329. * Abstract method that is executed when a node is collapsed
  330. *
  331. * @param node {Node} the node that was collapsed.
  332. */
  333. onCollapse: function(node) { }
  334. };
  335. /**
  336. * Global cache of tree instances
  337. *
  338. * @type Array
  339. * @private
  340. */
  341. YAHOO.widget.TreeView.trees = [];
  342. /**
  343. * Global method for getting a tree by its id. Used in the generated
  344. * tree html.
  345. *
  346. * @param treeId {String} the id of the tree instance
  347. * @return {TreeView} the tree instance requested, null if not found.
  348. */
  349. YAHOO.widget.TreeView.getTree = function(treeId) {
  350. var t = YAHOO.widget.TreeView.trees[treeId];
  351. return (t) ? t : null;
  352. };
  353. /**
  354. * Global method for getting a node by its id. Used in the generated
  355. * tree html.
  356. *
  357. * @param treeId {String} the id of the tree instance
  358. * @param nodeIndex {String} the index of the node to return
  359. * @return {Node} the node instance requested, null if not found
  360. */
  361. YAHOO.widget.TreeView.getNode = function(treeId, nodeIndex) {
  362. var t = YAHOO.widget.TreeView.getTree(treeId);
  363. return (t) ? t.getNodeByIndex(nodeIndex) : null;
  364. };
  365. /**
  366. * Adds an event. Replace with event manager when available
  367. *
  368. * @param el the elment to bind the handler to
  369. * @param {string} sType the type of event handler
  370. * @param {function} fn the callback to invoke
  371. * @param {boolean} capture if true event is capture phase, bubble otherwise
  372. */
  373. YAHOO.widget.TreeView.addHandler = function (el, sType, fn, capture) {
  374. capture = (capture) ? true : false;
  375. if (el.addEventListener) {
  376. el.addEventListener(sType, fn, capture);
  377. } else if (el.attachEvent) {
  378. el.attachEvent("on" + sType, fn);
  379. } else {
  380. el["on" + sType] = fn;
  381. }
  382. };
  383. /**
  384. * Attempts to preload the images defined in the styles used to draw the tree by
  385. * rendering off-screen elements that use the styles.
  386. */
  387. YAHOO.widget.TreeView.preload = function() {
  388. var styles = [
  389. "ygtvtn",
  390. "ygtvtm",
  391. "ygtvtmh",
  392. "ygtvtp",
  393. "ygtvtph",
  394. "ygtvln",
  395. "ygtvlm",
  396. "ygtvlmh",
  397. "ygtvlp",
  398. "ygtvlph",
  399. "ygtvloading"
  400. ];
  401. var sb = [];
  402. for (var i = 0; i < styles.length; ++i) {
  403. sb[sb.length] = '<span class="' + styles[i] + '">&nbsp;</span>';
  404. }
  405. var f = document.createElement("div");
  406. var s = f.style;
  407. s.position = "absolute";
  408. s.top = "-1000px";
  409. s.left = "-1000px";
  410. f.innerHTML = sb.join("");
  411. document.body.appendChild(f);
  412. };
  413. YAHOO.widget.TreeView.addHandler(window,
  414. "load", YAHOO.widget.TreeView.preload);
  415. /* Copyright (c) 2006 Yahoo! Inc. All rights reserved. */
  416. /**
  417. * The base class for all tree nodes. The node's presentation and behavior in
  418. * response to mouse events is handled in Node subclasses.
  419. *
  420. * @param oData {object} a string or object containing the data that will
  421. * be used to render this node
  422. * @param oParent {Node} this node's parent node
  423. * @param expanded {boolean} the initial expanded/collapsed state
  424. * @constructor
  425. */
  426. YAHOO.widget.Node = function(oData, oParent, expanded) {
  427. if (oParent) { this.init(oData, oParent, expanded); }
  428. };
  429. YAHOO.widget.Node.prototype = {
  430. /**
  431. * The index for this instance obtained from global counter in YAHOO.widget.TreeView.
  432. *
  433. * @type int
  434. */
  435. index: 0,
  436. /**
  437. * This node's child node collection.
  438. *
  439. * @type Node[]
  440. */
  441. children: null,
  442. /**
  443. * Tree instance this node is part of
  444. *
  445. * @type TreeView
  446. */
  447. tree: null,
  448. /**
  449. * The data linked to this node. This can be any object or primitive
  450. * value, and the data can be used in getNodeHtml().
  451. *
  452. * @type object
  453. */
  454. data: null,
  455. /**
  456. * Parent node
  457. *
  458. * @type Node
  459. */
  460. parent: null,
  461. /**
  462. * The depth of this node. We start at -1 for the root node.
  463. *
  464. * @type int
  465. */
  466. depth: -1,
  467. /**
  468. * The href for the node's label. If one is not specified, the href will
  469. * be set so that it toggles the node.
  470. *
  471. * @type string
  472. */
  473. href: null,
  474. /**
  475. * The label href target, defaults to current window
  476. *
  477. * @type string
  478. */
  479. target: "_self",
  480. /**
  481. * The node's expanded/collapsed state
  482. *
  483. * @type boolean
  484. */
  485. expanded: false,
  486. /**
  487. * Can multiple children be expanded at once?
  488. *
  489. * @type boolean
  490. */
  491. multiExpand: true,
  492. /**
  493. * Should we render children for a collapsed node? It is possible that the
  494. * implementer will want to render the hidden data... @todo verify that we
  495. * need this, and implement it if we do.
  496. *
  497. * @type boolean
  498. */
  499. renderHidden: false,
  500. /**
  501. * This flag is set to true when the html is generated for this node's
  502. * children, and set to false when new children are added.
  503. * @type boolean
  504. */
  505. childrenRendered: false,
  506. /**
  507. * Dynamically loaded nodes only fetch the data the first time they are
  508. * expanded. This flag is set to true once the data has been fetched.
  509. * @type boolean
  510. */
  511. dynamicLoadComplete: false,
  512. /**
  513. * This node's previous sibling
  514. *
  515. * @type Node
  516. */
  517. previousSibling: null,
  518. /**
  519. * This node's next sibling
  520. *
  521. * @type Node
  522. */
  523. nextSibling: null,
  524. /**
  525. * We can set the node up to call an external method to get the child
  526. * data dynamically.
  527. *
  528. * @type boolean
  529. * @private
  530. */
  531. _dynLoad: false,
  532. /**
  533. * Function to execute when we need to get this node's child data.
  534. *
  535. * @type function
  536. */
  537. dataLoader: null,
  538. /**
  539. * This is true for dynamically loading nodes while waiting for the
  540. * callback to return.
  541. *
  542. * @type boolean
  543. */
  544. isLoading: false,
  545. /**
  546. * The toggle/branch icon will not show if this is set to false. This
  547. * could be useful if the implementer wants to have the child contain
  548. * extra info about the parent, rather than an actual node.
  549. *
  550. * @type boolean
  551. */
  552. hasIcon: true,
  553. /**
  554. * Used to configure what happens when a dynamic load node is expanded
  555. * and we discover that it does not have children. By default, it is
  556. * treated as if it still could have children (plus/minus icon). Set
  557. * iconMode to have it display like a leaf node instead.
  558. * @type int
  559. */
  560. iconMode: 0,
  561. /**
  562. * The node type
  563. * @private
  564. */
  565. _type: "Node",
  566. /*
  567. spacerPath: "http://us.i1.yimg.com/us.yimg.com/i/space.gif",
  568. expandedText: "Expanded",
  569. collapsedText: "Collapsed",
  570. loadingText: "Loading",
  571. */
  572. /**
  573. * Initializes this node, gets some of the properties from the parent
  574. *
  575. * @param oData {object} a string or object containing the data that will
  576. * be used to render this node
  577. * @param oParent {Node} this node's parent node
  578. * @param expanded {boolean} the initial expanded/collapsed state
  579. */
  580. init: function(oData, oParent, expanded) {
  581. this.data = oData;
  582. this.children = [];
  583. this.index = YAHOO.widget.TreeView.nodeCount;
  584. ++YAHOO.widget.TreeView.nodeCount;
  585. this.expanded = expanded;
  586. // oParent should never be null except when we create the root node.
  587. if (oParent) {
  588. this.tree = oParent.tree;
  589. this.parent = oParent;
  590. this.href = "javascript:" + this.getToggleLink();
  591. this.depth = oParent.depth + 1;
  592. this.multiExpand = oParent.multiExpand;
  593. oParent.appendChild(this);
  594. }
  595. },
  596. /**
  597. * Appends a node to the child collection.
  598. *
  599. * @param node {Node} the new node
  600. * @return {Node} the child node
  601. * @private
  602. * @TODO insertBefore, insertAfter
  603. */
  604. appendChild: function(node) {
  605. if (this.hasChildren()) {
  606. var sib = this.children[this.children.length - 1];
  607. sib.nextSibling = node;
  608. node.previousSibling = sib;
  609. }
  610. this.tree.regNode(node);
  611. this.children[this.children.length] = node;
  612. this.childrenRendered = false;
  613. return node;
  614. },
  615. /**
  616. * Returns a node array of this node's siblings, null if none.
  617. *
  618. * @return Node[]
  619. */
  620. getSiblings: function() {
  621. return this.parent.children;
  622. },
  623. /**
  624. * Shows this node's children
  625. */
  626. showChildren: function() {
  627. if (!this.tree.animateExpand(this.getChildrenEl())) {
  628. if (this.hasChildren()) {
  629. this.getChildrenEl().style.display = "";
  630. }
  631. }
  632. },
  633. /**
  634. * Hides this node's children
  635. */
  636. hideChildren: function() {
  637. if (!this.tree.animateCollapse(this.getChildrenEl())) {
  638. this.getChildrenEl().style.display = "none";
  639. }
  640. },
  641. /**
  642. * Returns the id for this node's container div
  643. *
  644. * @return {string} the element id
  645. */
  646. getElId: function() {
  647. return "ygtv" + this.index;
  648. },
  649. /**
  650. * Returns the id for this node's children div
  651. *
  652. * @return {string} the element id for this node's children div
  653. */
  654. getChildrenElId: function() {
  655. return "ygtvc" + this.index;
  656. },
  657. /**
  658. * Returns the id for this node's toggle element
  659. *
  660. * @return {string} the toggel element id
  661. */
  662. getToggleElId: function() {
  663. return "ygtvt" + this.index;
  664. },
  665. /**
  666. * Returns the id for this node's spacer image. The spacer is positioned
  667. * over the toggle and provides feedback for screen readers.
  668. * @return {string} the id for the spacer image
  669. */
  670. /*
  671. getSpacerId: function() {
  672. return "ygtvspacer" + this.index;
  673. },
  674. */
  675. /**
  676. * Returns this node's container html element
  677. * @return {HTMLElement} the container html element
  678. */
  679. getEl: function() {
  680. return document.getElementById(this.getElId());
  681. },
  682. /**
  683. * Returns the div that was generated for this node's children
  684. * @return {HTMLElement} this node's children div
  685. */
  686. getChildrenEl: function() {
  687. return document.getElementById(this.getChildrenElId());
  688. },
  689. /**
  690. * Returns the element that is being used for this node's toggle.
  691. * @return {HTMLElement} this node's toggle html element
  692. */
  693. getToggleEl: function() {
  694. return document.getElementById(this.getToggleElId());
  695. },
  696. /**
  697. * Returns the element that is being used for this node's spacer.
  698. * @return {HTMLElement} this node's spacer html element
  699. */
  700. /*
  701. getSpacer: function() {
  702. return document.getElementById( this.getSpacerId() ) || {};
  703. },
  704. */
  705. /*
  706. getStateText: function() {
  707. if (this.isLoading) {
  708. return this.loadingText;
  709. } else if (this.hasChildren(true)) {
  710. if (this.expanded) {
  711. return this.expandedText;
  712. } else {
  713. return this.collapsedText;
  714. }
  715. } else {
  716. return "";
  717. }
  718. },
  719. */
  720. /**
  721. * Generates the link that will invoke this node's toggle method
  722. * @return {string} the javascript url for toggling this node
  723. */
  724. getToggleLink: function() {
  725. return "YAHOO.widget.TreeView.getNode(\'" + this.tree.id + "\'," +
  726. this.index + ").toggle()";
  727. },
  728. /**
  729. * Hides this nodes children (creating them if necessary), changes the
  730. * toggle style.
  731. */
  732. collapse: function() {
  733. // Only collapse if currently expanded
  734. if (!this.expanded) { return; }
  735. // fire the collapse event handler
  736. var ret = this.tree.onCollapse(this);
  737. if ("undefined" != typeof ret && !ret) {
  738. return;
  739. }
  740. if (!this.getEl()) {
  741. this.expanded = false;
  742. return;
  743. }
  744. // hide the child div
  745. this.hideChildren();
  746. this.expanded = false;
  747. if (this.hasIcon) {
  748. this.getToggleEl().className = this.getStyle();
  749. }
  750. // this.getSpacer().title = this.getStateText();
  751. },
  752. /**
  753. * Shows this nodes children (creating them if necessary), changes the
  754. * toggle style, and collapses its siblings if multiExpand is not set.
  755. */
  756. expand: function() {
  757. // Only expand if currently collapsed.
  758. if (this.expanded) { return; }
  759. // fire the expand event handler
  760. var ret = this.tree.onExpand(this);
  761. if ("undefined" != typeof ret && !ret) {
  762. return;
  763. }
  764. if (!this.getEl()) {
  765. this.expanded = true;
  766. return;
  767. }
  768. if (! this.childrenRendered) {
  769. this.getChildrenEl().innerHTML = this.renderChildren();
  770. } else {
  771. }
  772. this.expanded = true;
  773. if (this.hasIcon) {
  774. this.getToggleEl().className = this.getStyle();
  775. }
  776. // this.getSpacer().title = this.getStateText();
  777. // We do an extra check for children here because the lazy
  778. // load feature can expose nodes that have no children.
  779. // if (!this.hasChildren()) {
  780. if (this.isLoading) {
  781. this.expanded = false;
  782. return;
  783. }
  784. if (! this.multiExpand) {
  785. var sibs = this.getSiblings();
  786. for (var i=0; i<sibs.length; ++i) {
  787. if (sibs[i] != this && sibs[i].expanded) {
  788. sibs[i].collapse();
  789. }
  790. }
  791. }
  792. this.showChildren();
  793. },
  794. /**
  795. * Returns the css style name for the toggle
  796. *
  797. * @return {string} the css class for this node's toggle
  798. */
  799. getStyle: function() {
  800. if (this.isLoading) {
  801. return "ygtvloading";
  802. } else {
  803. // location top or bottom, middle nodes also get the top style
  804. var loc = (this.nextSibling) ? "t" : "l";
  805. // type p=plus(expand), m=minus(collapase), n=none(no children)
  806. var type = "n";
  807. if (this.hasChildren(true) || (this.isDynamic() && !this.getIconMode())) {
  808. // if (this.hasChildren(true)) {
  809. type = (this.expanded) ? "m" : "p";
  810. }
  811. return "ygtv" + loc + type;
  812. }
  813. },
  814. /**
  815. * Returns the hover style for the icon
  816. * @return {string} the css class hover state
  817. */
  818. getHoverStyle: function() {
  819. var s = this.getStyle();
  820. if (this.hasChildren(true) && !this.isLoading) {
  821. s += "h";
  822. }
  823. return s;
  824. },
  825. /**
  826. * Recursively expands all of this node's children.
  827. */
  828. expandAll: function() {
  829. for (var i=0;i<this.children.length;++i) {
  830. var c = this.children[i];
  831. if (c.isDynamic()) {
  832. alert("Not supported (lazy load + expand all)");
  833. break;
  834. } else if (! c.multiExpand) {
  835. alert("Not supported (no multi-expand + expand all)");
  836. break;
  837. } else {
  838. c.expand();
  839. c.expandAll();
  840. }
  841. }
  842. },
  843. /**
  844. * Recursively collapses all of this node's children.
  845. */
  846. collapseAll: function() {
  847. for (var i=0;i<this.children.length;++i) {
  848. this.children[i].collapse();
  849. this.children[i].collapseAll();
  850. }
  851. },
  852. /**
  853. * Configures this node for dynamically obtaining the child data
  854. * when the node is first expanded. Calling it without the callback
  855. * will turn off dynamic load for the node.
  856. *
  857. * @param fmDataLoader {function} the function that will be used to get the data.
  858. * @param iconMode {int} configures the icon that is displayed when a dynamic
  859. * load node is expanded the first time without children. By default, the
  860. * "collapse" icon will be used. If set to 1, the leaf node icon will be
  861. * displayed.
  862. */
  863. setDynamicLoad: function(fnDataLoader, iconMode) {
  864. if (fnDataLoader) {
  865. this.dataLoader = fnDataLoader;
  866. this._dynLoad = true;
  867. } else {
  868. this.dataLoader = null;
  869. this._dynLoad = false;
  870. }
  871. if (iconMode) {
  872. this.iconMode = iconMode;
  873. }
  874. },
  875. /**
  876. * Evaluates if this node is the root node of the tree
  877. *
  878. * @return {boolean} true if this is the root node
  879. */
  880. isRoot: function() {
  881. return (this == this.tree.root);
  882. },
  883. /**
  884. * Evaluates if this node's children should be loaded dynamically. Looks for
  885. * the property both in this instance and the root node. If the tree is
  886. * defined to load all children dynamically, the data callback function is
  887. * defined in the root node
  888. *
  889. * @return {boolean} true if this node's children are to be loaded dynamically
  890. */
  891. isDynamic: function() {
  892. var lazy = (!this.isRoot() && (this._dynLoad || this.tree.root._dynLoad));
  893. return lazy;
  894. },
  895. getIconMode: function() {
  896. return (this.iconMode || this.tree.root.iconMode);
  897. },
  898. /**
  899. * Checks if this node has children. If this node is lazy-loading and the
  900. * children have not been rendered, we do not know whether or not there
  901. * are actual children. In most cases, we need to assume that there are
  902. * children (for instance, the toggle needs to show the expandable
  903. * presentation state). In other times we want to know if there are rendered
  904. * children. For the latter, "checkForLazyLoad" should be false.
  905. *
  906. * @param checkForLazyLoad {boolean} should we check for unloaded children?
  907. * @return {boolean} true if this has children or if it might and we are
  908. * checking for this condition.
  909. */
  910. hasChildren: function(checkForLazyLoad) {
  911. return ( this.children.length > 0 ||
  912. (checkForLazyLoad && this.isDynamic() && !this.dynamicLoadComplete) );
  913. },
  914. /**
  915. * Expands if node is collapsed, collapses otherwise.
  916. */
  917. toggle: function() {
  918. if (!this.tree.locked && ( this.hasChildren(true) || this.isDynamic()) ) {
  919. if (this.expanded) { this.collapse(); } else { this.expand(); }
  920. }
  921. },
  922. /**
  923. * Returns the markup for this node and its children.
  924. *
  925. * @return {string} the markup for this node and its expanded children.
  926. */
  927. getHtml: function() {
  928. var sb = [];
  929. sb[sb.length] = '<div class="ygtvitem" id="' + this.getElId() + '">';
  930. sb[sb.length] = this.getNodeHtml();
  931. sb[sb.length] = this.getChildrenHtml();
  932. sb[sb.length] = '</div>';
  933. return sb.join("");
  934. },
  935. /**
  936. * Called when first rendering the tree. We always build the div that will
  937. * contain this nodes children, but we don't render the children themselves
  938. * unless this node is expanded.
  939. *
  940. * @return {string} the children container div html and any expanded children
  941. * @private
  942. */
  943. getChildrenHtml: function() {
  944. var sb = [];
  945. sb[sb.length] = '<div class="ygtvchildren"';
  946. sb[sb.length] = ' id="' + this.getChildrenElId() + '"';
  947. if (!this.expanded) {
  948. sb[sb.length] = ' style="display:none;"';
  949. }
  950. sb[sb.length] = '>';
  951. // Don't render the actual child node HTML unless this node is expanded.
  952. if ( (this.hasChildren(true) && this.expanded) ||
  953. (this.renderHidden && !this.isDynamic()) ) {
  954. sb[sb.length] = this.renderChildren();
  955. }
  956. sb[sb.length] = '</div>';
  957. return sb.join("");
  958. },
  959. /**
  960. * Generates the markup for the child nodes. This is not done until the node
  961. * is expanded.
  962. *
  963. * @return {string} the html for this node's children
  964. * @private
  965. */
  966. renderChildren: function() {
  967. var node = this;
  968. if (this.isDynamic() && !this.dynamicLoadComplete) {
  969. this.isLoading = true;
  970. this.tree.locked = true;
  971. if (this.dataLoader) {
  972. setTimeout(
  973. function() {
  974. node.dataLoader(node,
  975. function() {
  976. node.loadComplete();
  977. });
  978. }, 10);
  979. } else if (this.tree.root.dataLoader) {
  980. setTimeout(
  981. function() {
  982. node.tree.root.dataLoader(node,
  983. function() {
  984. node.loadComplete();
  985. });
  986. }, 10);
  987. } else {
  988. return "Error: data loader not found or not specified.";
  989. }
  990. return "";
  991. } else {
  992. return this.completeRender();
  993. }
  994. },
  995. /**
  996. * Called when we know we have all the child data.
  997. * @return {string} children html
  998. */
  999. completeRender: function() {
  1000. var sb = [];
  1001. for (var i=0; i < this.children.length; ++i) {
  1002. this.children[i].childrenRendered = false;
  1003. sb[sb.length] = this.children[i].getHtml();
  1004. }
  1005. this.childrenRendered = true;
  1006. return sb.join("");
  1007. },
  1008. /**
  1009. * Load complete is the callback function we pass to the data provider
  1010. * in dynamic load situations.
  1011. */
  1012. loadComplete: function() {
  1013. this.getChildrenEl().innerHTML = this.completeRender();
  1014. this.dynamicLoadComplete = true;
  1015. this.isLoading = false;
  1016. this.expand();
  1017. this.tree.locked = false;
  1018. },
  1019. /**
  1020. * Returns this node's ancestor at the specified depth.
  1021. *
  1022. * @param {int} depth the depth of the ancestor.
  1023. * @return {Node} the ancestor
  1024. */
  1025. getAncestor: function(depth) {
  1026. if (depth >= this.depth || depth < 0) {
  1027. return null;
  1028. }
  1029. var p = this.parent;
  1030. while (p.depth > depth) {
  1031. p = p.parent;
  1032. }
  1033. return p;
  1034. },
  1035. /**
  1036. * Returns the css class for the spacer at the specified depth for
  1037. * this node. If this node's ancestor at the specified depth
  1038. * has a next sibling the presentation is different than if it
  1039. * does not have a next sibling
  1040. *
  1041. * @param {int} depth the depth of the ancestor.
  1042. * @return {string} the css class for the spacer
  1043. */
  1044. getDepthStyle: function(depth) {
  1045. return (this.getAncestor(depth).nextSibling) ?
  1046. "ygtvdepthcell" : "ygtvblankdepthcell";
  1047. },
  1048. /**
  1049. * Get the markup for the node. This is designed to be overrided so that we can
  1050. * support different types of nodes.
  1051. *
  1052. * @return {string} The HTML that will render this node.
  1053. */
  1054. getNodeHtml: function() {
  1055. return "";
  1056. },
  1057. /**
  1058. * Regenerates the html for this node and its children. To be used when the
  1059. * node is expanded and new children have been added.
  1060. */
  1061. refresh: function() {
  1062. // this.loadComplete();
  1063. this.getChildrenEl().innerHTML = this.completeRender();
  1064. if (this.hasIcon) {
  1065. var el = this.getToggleEl();
  1066. if (el) {
  1067. el.className = this.getStyle();
  1068. }
  1069. }
  1070. }
  1071. };
  1072. /* Copyright (c) 2006 Yahoo! Inc. All rights reserved. */
  1073. /**
  1074. * A custom YAHOO.widget.Node that handles the unique nature of
  1075. * the virtual, presentationless root node.
  1076. *
  1077. * @extends YAHOO.widget.Node
  1078. * @constructor
  1079. */
  1080. YAHOO.widget.RootNode = function(oTree) {
  1081. // Initialize the node with null params. The root node is a
  1082. // special case where the node has no presentation. So we have
  1083. // to alter the standard properties a bit.
  1084. this.init(null, null, true);
  1085. /**
  1086. * For the root node, we get the tree reference from as a param
  1087. * to the constructor instead of from the parent element.
  1088. *
  1089. * @type TreeView
  1090. */
  1091. this.tree = oTree;
  1092. };
  1093. YAHOO.widget.RootNode.prototype = new YAHOO.widget.Node();
  1094. // overrides YAHOO.widget.Node
  1095. YAHOO.widget.RootNode.prototype.getNodeHtml = function() {
  1096. return "";
  1097. };
  1098. /* Copyright (c) 2006 Yahoo! Inc. All rights reserved. */
  1099. /**
  1100. * The default node presentation. The first parameter should be
  1101. * either a string that will be used as the node's label, or an object
  1102. * that has a string propery called label. By default, the clicking the
  1103. * label will toggle the expanded/collapsed state of the node. By
  1104. * changing the href property of the instance, this behavior can be
  1105. * changed so that the label will go to the specified href.
  1106. *
  1107. * @extends YAHOO.widget.Node
  1108. * @constructor
  1109. * @param oData {object} a string or object containing the data that will
  1110. * be used to render this node
  1111. * @param oParent {YAHOO.widget.Node} this node's parent node
  1112. * @param expanded {boolean} the initial expanded/collapsed state
  1113. */
  1114. YAHOO.widget.TextNode = function(oData, oParent, expanded) {
  1115. this.type = "TextNode";
  1116. if (oParent) {
  1117. this.init(oData, oParent, expanded);
  1118. this.setUpLabel(oData);
  1119. }
  1120. };
  1121. YAHOO.widget.TextNode.prototype = new YAHOO.widget.Node();
  1122. /**
  1123. * The CSS class for the label href. Defaults to ygtvlabel, but can be
  1124. * overridden to provide a custom presentation for a specific node.
  1125. *
  1126. * @type string
  1127. */
  1128. YAHOO.widget.TextNode.prototype.labelStyle = "ygtvlabel";
  1129. /**
  1130. * The derived element id of the label for this node
  1131. *
  1132. * @type string
  1133. */
  1134. YAHOO.widget.TextNode.prototype.labelElId = null;
  1135. /**
  1136. * The text for the label. It is assumed that the oData parameter will
  1137. * either be a string that will be used as the label, or an object that
  1138. * has a property called "label" that we will use.
  1139. *
  1140. * @type string
  1141. */
  1142. YAHOO.widget.TextNode.prototype.label = null;
  1143. /**
  1144. * Sets up the node label
  1145. *
  1146. * @param oData string containing the label, or an object with a label property
  1147. */
  1148. YAHOO.widget.TextNode.prototype.setUpLabel = function(oData) {
  1149. if (typeof oData == "string") {
  1150. oData = { label: oData };
  1151. }
  1152. this.label = oData.label;
  1153. // update the link
  1154. if (oData.href) {
  1155. this.href = oData.href;
  1156. }
  1157. // set the target
  1158. if (oData.target) {
  1159. this.target = oData.target;
  1160. }
  1161. if (oData.style) {
  1162. this.labelStyle = oData.style;
  1163. }
  1164. this.labelElId = "ygtvlabelel" + this.index;
  1165. };
  1166. /**
  1167. * Returns the label element
  1168. *
  1169. * @return {object} the element
  1170. */
  1171. YAHOO.widget.TextNode.prototype.getLabelEl = function() {
  1172. return document.getElementById(this.labelElId);
  1173. };
  1174. // overrides YAHOO.widget.Node
  1175. YAHOO.widget.TextNode.prototype.getNodeHtml = function() {
  1176. var sb = [];
  1177. sb[sb.length] = '<table border="0" cellpadding="0" cellspacing="0">';
  1178. sb[sb.length] = '<tr>';
  1179. for (i=0;i<this.depth;++i) {
  1180. // sb[sb.length] = '<td class="ygtvdepthcell">&nbsp;</td>';
  1181. sb[sb.length] = '<td class="' + this.getDepthStyle(i) + '">&nbsp;</td>';
  1182. }
  1183. var getNode = 'YAHOO.widget.TreeView.getNode(\'' +
  1184. this.tree.id + '\',' + this.index + ')';
  1185. sb[sb.length] = '<td';
  1186. // sb[sb.length] = ' onselectstart="return false"';
  1187. sb[sb.length] = ' id="' + this.getToggleElId() + '"';
  1188. sb[sb.length] = ' class="' + this.getStyle() + '"';
  1189. if (this.hasChildren(true)) {
  1190. sb[sb.length] = ' onmouseover="this.className=';
  1191. sb[sb.length] = getNode + '.getHoverStyle()"';
  1192. sb[sb.length] = ' onmouseout="this.className=';
  1193. sb[sb.length] = getNode + '.getStyle()"';
  1194. }
  1195. sb[sb.length] = ' onclick="javascript:' + this.getToggleLink() + '">';
  1196. /*
  1197. sb[sb.length] = '<img id="' + this.getSpacerId() + '"';
  1198. sb[sb.length] = ' alt=""';
  1199. sb[sb.length] = ' tabindex=0';
  1200. sb[sb.length] = ' src="' + this.spacerPath + '"';
  1201. sb[sb.length] = ' title="' + this.getStateText() + '"';
  1202. sb[sb.length] = ' class="ygtvspacer"';
  1203. // sb[sb.length] = ' onkeypress="return ' + getNode + '".onKeyPress()"';
  1204. sb[sb.length] = ' />';
  1205. */
  1206. sb[sb.length] = '&nbsp;';
  1207. sb[sb.length] = '</td>';
  1208. sb[sb.length] = '<td>';
  1209. sb[sb.length] = '<a';
  1210. sb[sb.length] = ' id="' + this.labelElId + '"';
  1211. sb[sb.length] = ' class="' + this.labelStyle + '"';
  1212. sb[sb.length] = ' href="' + this.href + '"';
  1213. sb[sb.length] = ' target="' + this.target + '"';
  1214. sb[sb.length] = ' onclick="return ' + getNode + '.onLabelClick(' + getNode +')"';
  1215. /*sb[sb.length] = ' onclick="javascript:' + this.getToggleLink() + '.onLabelClick(' + getNode
  1216. +')"';*/
  1217. if (this.hasChildren(true)) {
  1218. sb[sb.length] = ' onmouseover="document.getElementById(\'';
  1219. sb[sb.length] = this.getToggleElId() + '\').className=';
  1220. sb[sb.length] = getNode + '.getHoverStyle()"';
  1221. sb[sb.length] = ' onmouseout="document.getElementById(\'';
  1222. sb[sb.length] = this.getToggleElId() + '\').className=';
  1223. sb[sb.length] = getNode + '.getStyle()"';
  1224. }
  1225. sb[sb.length] = ' >';
  1226. sb[sb.length] = this.label;
  1227. sb[sb.length] = '</a>';
  1228. sb[sb.length] = '</td>';
  1229. sb[sb.length] = '</tr>';
  1230. sb[sb.length] = '</table>';
  1231. return sb.join("");
  1232. };
  1233. /**
  1234. * Executed when the label is clicked
  1235. * @param me {Node} this node
  1236. * @scope the anchor tag clicked
  1237. * @return false to cancel the anchor click
  1238. */
  1239. YAHOO.widget.TextNode.prototype.onLabelClick = function(me) {
  1240. //return true;
  1241. };
  1242. /* Copyright (c) 2006 Yahoo! Inc. All rights reserved. */
  1243. /**
  1244. * A menu-specific implementation that differs from TextNode in that only
  1245. * one sibling can be expanded at a time.
  1246. * @extends YAHOO.widget.TextNode
  1247. * @constructor
  1248. */
  1249. YAHOO.widget.MenuNode = function(oData, oParent, expanded) {
  1250. if (oParent) {
  1251. this.init(oData, oParent, expanded);
  1252. this.setUpLabel(oData);
  1253. }
  1254. /**
  1255. * Menus usually allow only one branch to be open at a time.
  1256. * @type boolean
  1257. */
  1258. this.multiExpand = false;
  1259. };
  1260. YAHOO.widget.MenuNode.prototype = new YAHOO.widget.TextNode();
  1261. /* Copyright (c) 2006 Yahoo! Inc. All rights reserved. */
  1262. /**
  1263. * This implementation takes either a string or object for the
  1264. * oData argument. If is it a string, we will use it for the display
  1265. * of this node (and it can contain any html code). If the parameter
  1266. * is an object, we look for a parameter called "html" that will be
  1267. * used for this node's display.
  1268. *
  1269. * @extends YAHOO.widget.Node
  1270. * @constructor
  1271. * @param oData {object} a string or object containing the data that will
  1272. * be used to render this node
  1273. * @param oParent {YAHOO.widget.Node} this node's parent node
  1274. * @param expanded {boolean} the initial expanded/collapsed state
  1275. * @param hasIcon {boolean} specifies whether or not leaf nodes should
  1276. * have an icon
  1277. */
  1278. YAHOO.widget.HTMLNode = function(oData, oParent, expanded, hasIcon) {
  1279. if (oParent) {
  1280. this.init(oData, oParent, expanded);
  1281. this.initContent(oData, hasIcon);
  1282. }
  1283. };
  1284. YAHOO.widget.HTMLNode.prototype = new YAHOO.widget.Node();
  1285. /**
  1286. * The CSS class for the label href. Defaults to ygtvlabel, but can be
  1287. * overridden to provide a custom presentation for a specific node.
  1288. *
  1289. * @type string
  1290. */
  1291. YAHOO.widget.HTMLNode.prototype.contentStyle = "ygtvhtml";
  1292. /**
  1293. * The generated id that will contain the data passed in by the implementer.
  1294. *
  1295. * @type string
  1296. */
  1297. YAHOO.widget.HTMLNode.prototype.contentElId = null;
  1298. /**
  1299. * The HTML content to use for this node's display
  1300. *
  1301. * @type string
  1302. */
  1303. YAHOO.widget.HTMLNode.prototype.content = null;
  1304. /**
  1305. * Sets up the node label
  1306. *
  1307. * @param {object} An html string or object containing an html property
  1308. * @param {boolean} hasIcon determines if the node will be rendered with an
  1309. * icon or not
  1310. */
  1311. YAHOO.widget.HTMLNode.prototype.initContent = function(oData, hasIcon) {
  1312. if (typeof oData == "string") {
  1313. oData = { html: oData };
  1314. }
  1315. this.html = oData.html;
  1316. this.contentElId = "ygtvcontentel" + this.index;
  1317. this.hasIcon = hasIcon;
  1318. };
  1319. /**
  1320. * Returns the outer html element for this node's content
  1321. *
  1322. * @return {HTMLElement} the element
  1323. */
  1324. YAHOO.widget.HTMLNode.prototype.getContentEl = function() {
  1325. return document.getElementById(this.contentElId);
  1326. };
  1327. // overrides YAHOO.widget.Node
  1328. YAHOO.widget.HTMLNode.prototype.getNodeHtml = function() {
  1329. var sb = [];
  1330. sb[sb.length] = '<table border="0" cellpadding="0" cellspacing="0">';
  1331. sb[sb.length] = '<tr>';
  1332. for (i=0;i<this.depth;++i) {
  1333. sb[sb.length] = '<td class="' + this.getDepthStyle(i) + '">&nbsp;</td>';
  1334. }
  1335. if (this.hasIcon) {
  1336. sb[sb.length] = '<td';
  1337. sb[sb.length] = ' id="' + this.getToggleElId() + '"';
  1338. sb[sb.length] = ' class="' + this.getStyle() + '"';
  1339. sb[sb.length] = ' onclick="javascript:' + this.getToggleLink() + '"';
  1340. if (this.hasChildren(true)) {
  1341. sb[sb.length] = ' onmouseover="this.className=';
  1342. sb[sb.length] = 'YAHOO.widget.TreeView.getNode(\'';
  1343. sb[sb.length] = this.tree.id + '\',' + this.index + ').getHoverStyle()"';
  1344. sb[sb.length] = ' onmouseout="this.className=';
  1345. sb[sb.length] = 'YAHOO.widget.TreeView.getNode(\'';
  1346. sb[sb.length] = this.tree.id + '\',' + this.index + ').getStyle()"';
  1347. }
  1348. sb[sb.length] = '>&nbsp;</td>';
  1349. }
  1350. sb[sb.length] = '<td';
  1351. sb[sb.length] = ' id="' + this.contentElId + '"';
  1352. sb[sb.length] = ' class="' + this.contentStyle + '"';
  1353. sb[sb.length] = ' >';
  1354. sb[sb.length] = this.html;
  1355. sb[sb.length] = '</td>';
  1356. sb[sb.length] = '</tr>';
  1357. sb[sb.length] = '</table>';
  1358. return sb.join("");
  1359. };
  1360. /* Copyright (c) 2006 Yahoo! Inc. All rights reserved. */
  1361. /**
  1362. * A static factory class for tree view expand/collapse animations
  1363. *
  1364. * @constructor
  1365. */
  1366. YAHOO.widget.TVAnim = function() {
  1367. return {
  1368. /**
  1369. * Constant for the fade in animation
  1370. *
  1371. * @type string
  1372. */
  1373. FADE_IN: "TVFadeIn",
  1374. /**
  1375. * Constant for the fade out animation
  1376. *
  1377. * @type string
  1378. */
  1379. FADE_OUT: "TVFadeOut",
  1380. /**
  1381. * Returns a ygAnim instance of the given type
  1382. *
  1383. * @param type {string} the type of animation
  1384. * @param el {HTMLElement} the element to element (probably the children div)
  1385. * @param callback {function} function to invoke when the animation is done.
  1386. * @return {YAHOO.util.Animation} the animation instance
  1387. */
  1388. getAnim: function(type, el, callback) {
  1389. if (YAHOO.widget[type]) {
  1390. return new YAHOO.widget[type](el, callback);
  1391. } else {
  1392. return null;
  1393. }
  1394. },
  1395. /**
  1396. * Returns true if the specified animation class is available
  1397. *
  1398. * @param type {string} the type of animation
  1399. * @return {boolean} true if valid, false if not
  1400. */
  1401. isValid: function(type) {
  1402. return (YAHOO.widget[type]);
  1403. }
  1404. };
  1405. } ();
  1406. /* Copyright (c) 2006 Yahoo! Inc. All rights reserved. */
  1407. /**
  1408. * A 1/2 second fade-in animation.
  1409. *
  1410. * @constructor
  1411. * @param el {HTMLElement} the element to animate
  1412. * @param callback {function} function to invoke when the animation is finished
  1413. */
  1414. YAHOO.widget.TVFadeIn = function(el, callback) {
  1415. /**
  1416. * The element to animate
  1417. * @type HTMLElement
  1418. */
  1419. this.el = el;
  1420. /**
  1421. * the callback to invoke when the animation is complete
  1422. *
  1423. * @type function
  1424. */
  1425. this.callback = callback;
  1426. /**
  1427. * @private
  1428. */
  1429. };
  1430. /**
  1431. * Performs the animation
  1432. */
  1433. YAHOO.widget.TVFadeIn.prototype = {
  1434. animate: function() {
  1435. var tvanim = this;
  1436. var s = this.el.style;
  1437. s.opacity = 0.1;
  1438. s.filter = "alpha(opacity=10)";
  1439. s.display = "";
  1440. // var dur = ( navigator.userAgent.match(/msie/gi) ) ? 0.05 : 0.4;
  1441. var dur = 0.4;
  1442. // var a = new ygAnim_Fade(this.el, dur, 1);
  1443. // a.setStart(0.1);
  1444. // a.onComplete = function() { tvanim.onComplete(); };
  1445. // var a = new YAHOO.util.Anim(this.el, 'opacity', 0.1, 1);
  1446. var a = new YAHOO.util.Anim(this.el, {opacity: {from: 0.1, to: 1, unit:""}}, dur);
  1447. a.onComplete.subscribe( function() { tvanim.onComplete(); } );
  1448. a.animate();
  1449. },
  1450. /**
  1451. * Clean up and invoke callback
  1452. */
  1453. onComplete: function() {
  1454. this.callback();
  1455. }
  1456. };
  1457. /* Copyright (c) 2006 Yahoo! Inc. All rights reserved. */
  1458. /**
  1459. * A 1/2 second fade out animation.
  1460. *
  1461. * @constructor
  1462. * @param el {HTMLElement} the element to animate
  1463. * @param callback {Function} function to invoke when the animation is finished
  1464. */
  1465. YAHOO.widget.TVFadeOut = function(el, callback) {
  1466. /**
  1467. * The element to animate
  1468. * @type HTMLElement
  1469. */
  1470. this.el = el;
  1471. /**
  1472. * the callback to invoke when the animation is complete
  1473. *
  1474. * @type function
  1475. */
  1476. this.callback = callback;
  1477. /**
  1478. * @private
  1479. */
  1480. };
  1481. /**
  1482. * Performs the animation
  1483. */
  1484. YAHOO.widget.TVFadeOut.prototype = {
  1485. animate: function() {
  1486. var tvanim = this;
  1487. // var dur = ( navigator.userAgent.match(/msie/gi) ) ? 0.05 : 0.4;
  1488. var dur = 0.4;
  1489. // var a = new ygAnim_Fade(this.el, dur, 0.1);
  1490. // a.onComplete = function() { tvanim.onComplete(); };
  1491. // var a = new YAHOO.util.Anim(this.el, 'opacity', 1, 0.1);
  1492. var a = new YAHOO.util.Anim(this.el, {opacity: {from: 1, to: 0.1, unit:""}}, dur);
  1493. a.onComplete.subscribe( function() { tvanim.onComplete(); } );
  1494. a.animate();
  1495. },
  1496. /**
  1497. * Clean up and invoke callback
  1498. */
  1499. onComplete: function() {
  1500. var s = this.el.style;
  1501. s.display = "none";
  1502. // s.opacity = 1;
  1503. s.filter = "alpha(opacity=100)";
  1504. this.callback();
  1505. }
  1506. };