treeview.js 48 KB

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