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