| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756 |
- /*
- This file is part of the DITA Open Toolkit project hosted on
- Sourceforge.net. See the accompanying license.txt file for
- applicable licenses.
-
- Copyright (c) 2006, Yahoo! Inc. All rights reserved.
- Code licensed under the BSD License:
- http://developer.yahoo.net/yui/license.txt
- version: 0.10.0
- */
- /* Copyright (c) 2006 Yahoo! Inc. All rights reserved. */
- /**
- * Contains the tree view state data and the root node. This is an
- * ordered tree; child nodes will be displayed in the order created, and
- * there currently is no way to change this.
- *
- * @constructor
- * @todo graft (appendBefore, appendAfter)
- * @param {string} id The id of the element that the tree will be inserted
- * into.
- */
- YAHOO.widget.TreeView = function(id) {
- if (id) { this.init(id); }
- };
- /**
- * Count of all nodes in all trees
- * @type int
- */
- YAHOO.widget.TreeView.nodeCount = 0;
- YAHOO.widget.TreeView.prototype = {
- /**
- * The id of tree container element
- *
- * @type String
- */
- id: null,
- /**
- * Flat collection of all nodes in this tree
- *
- * @type Node[]
- * @private
- */
- _nodes: null,
- /**
- * We lock the tree control while waiting for the dynamic loader to return
- *
- * @type boolean
- */
- locked: false,
- /**
- * The animation to use for expanding children, if any
- *
- * @type string
- * @private
- */
- _expandAnim: null,
- /**
- * The animation to use for collapsing children, if any
- *
- * @type string
- * @private
- */
- _collapseAnim: null,
- /**
- * The current number of animations that are executing
- *
- * @type int
- * @private
- */
- _animCount: 0,
- /**
- * The maximum number of animations to run at one time.
- *
- * @type int
- */
- maxAnim: 2,
- /**
- * Sets up the animation for expanding children
- *
- * @param {string} the type of animation (acceptable constants in YAHOO.widget.TVAnim)
- */
- setExpandAnim: function(type) {
- if (YAHOO.widget.TVAnim.isValid(type)) {
- this._expandAnim = type;
- }
- },
- /**
- * Sets up the animation for collapsing children
- *
- * @param {string} the type of animation (acceptable constants in YAHOO.widget.TVAnim)
- */
- setCollapseAnim: function(type) {
- if (YAHOO.widget.TVAnim.isValid(type)) {
- this._collapseAnim = type;
- }
- },
- /**
- * Perform the expand animation if configured, or just show the
- * element if not configured or too many animations are in progress
- *
- * @param el {HTMLElement} the element to animate
- * @return {boolean} true if animation could be invoked, false otherwise
- */
- animateExpand: function(el) {
- if (this._expandAnim && this._animCount < this.maxAnim) {
- // this.locked = true;
- var tree = this;
- var a = YAHOO.widget.TVAnim.getAnim(this._expandAnim, el,
- function() { tree.expandComplete(); });
- if (a) {
- ++this._animCount;
- a.animate();
- }
- return true;
- }
- return false;
- },
- /**
- * Perform the collapse animation if configured, or just show the
- * element if not configured or too many animations are in progress
- *
- * @param el {HTMLElement} the element to animate
- * @return {boolean} true if animation could be invoked, false otherwise
- */
- animateCollapse: function(el) {
- if (this._collapseAnim && this._animCount < this.maxAnim) {
- // this.locked = true;
- var tree = this;
- var a = YAHOO.widget.TVAnim.getAnim(this._collapseAnim, el,
- function() { tree.collapseComplete(); });
- if (a) {
- ++this._animCount;
- a.animate();
- }
- return true;
- }
- return false;
- },
- /**
- * Function executed when the expand animation completes
- */
- expandComplete: function() {
- --this._animCount;
- // this.locked = false;
- },
- /**
- * Function executed when the collapse animation completes
- */
- collapseComplete: function() {
- --this._animCount;
- // this.locked = false;
- },
- /**
- * Initializes the tree
- *
- * @parm {string} id the id of the element that will hold the tree
- * @private
- */
- init: function(id) {
- this.id = id;
- this._nodes = [];
- // store a global reference
- YAHOO.widget.TreeView.trees[id] = this;
- // Set up the root node
- this.root = new YAHOO.widget.RootNode(this);
- },
- /**
- * Renders the tree boilerplate and visible nodes
- */
- draw: function() {
- var html = this.root.getHtml();
- if(document.getElementById(this.id))
- document.getElementById(this.id).innerHTML = html;
- /*document.getElementById(this.id).innerHTML = html;*/
- this.firstDraw = false;
- },
- /**
- * Nodes register themselves with the tree instance when they are created.
- *
- * @param node {Node} the node to register
- * @private
- */
- regNode: function(node) {
- this._nodes[node.index] = node;
- },
- /**
- * Returns the root node of this tree
- *
- * @return {Node} the root node
- */
- getRoot: function() {
- return this.root;
- },
- /**
- * Configures this tree to dynamically load all child data
- *
- * @param {function} fnDataLoader the function that will be called to get the data
- * @param iconMode {int} configures the icon that is displayed when a dynamic
- * load node is expanded the first time without children. By default, the
- * "collapse" icon will be used. If set to 1, the leaf node icon will be
- * displayed.
- */
- setDynamicLoad: function(fnDataLoader, iconMode) {
- this.root.setDynamicLoad(fnDataLoader, iconMode);
- },
- /**
- * Expands all child nodes. Note: this conflicts with the "multiExpand"
- * node property. If expand all is called in a tree with nodes that
- * do not allow multiple siblings to be displayed, only the last sibling
- * will be expanded.
- */
- expandAll: function() {
- if (!this.locked) {
- this.root.expandAll();
- }
- },
- /**
- * Collapses all expanded child nodes in the entire tree.
- */
- collapseAll: function() {
- if (!this.locked) {
- this.root.collapseAll();
- }
- },
- /**
- * Returns a node in the tree that has the specified index (this index
- * is created internally, so this function probably will only be used
- * in html generated for a given node.)
- *
- * @param {int} nodeIndex the index of the node wanted
- * @return {Node} the node with index=nodeIndex, null if no match
- */
- getNodeByIndex: function(nodeIndex) {
- var n = this._nodes[nodeIndex];
- return (n) ? n : null;
- },
- /**
- * Returns a node that has a matching property and value in the data
- * object that was passed into its constructor. Provides a flexible
- * way for the implementer to get a particular node.
- *
- * @param {object} property the property to search (usually a string)
- * @param {object} value the value we want to find (usuall an int or string)
- * @return {Node} the matching node, null if no match
- */
- getNodeByProperty: function(property, value) {
- for (var i in this._nodes) {
- var n = this._nodes[i];
- if (n.data && value == n.data[property]) {
- return n;
- }
- }
- return null;
- },
- /**
- * Removes the node and its children, and optionally refreshes the branch
- * of the tree that was affected.
- * @param {Node} The node to remove
- * @param {boolean} autoRefresh automatically refreshes branch if true
- * @return {boolean} False is there was a problem, true otherwise.
- */
- removeNode: function(node, autoRefresh) {
- // Don't delete the root node
- if (node.isRoot()) {
- return false;
- }
- // Get the branch that we may need to refresh
- var p = node.parent;
- if (p.parent) {
- p = p.parent;
- }
- // Delete the node and its children
- this._deleteNode(node);
- // Refresh the parent of the parent
- if (autoRefresh && p && p.childrenRendered) {
- p.refresh();
- }
- return true;
- },
- /**
- * Deletes this nodes child collection, recursively. Also collapses
- * the node, and resets the dynamic load flag. The primary use for
- * this method is to purge a node and allow it to fetch its data
- * dynamically again.
- * @param {Node} node the node to purge
- */
- removeChildren: function(node) {
- for (var i=0, len=node.children.length;i<len;++i) {
- this._deleteNode(node.children[i]);
- }
- node.childrenRendered = false;
- node.dynamicLoadComplete = false;
- node.collapse();
- },
- /**
- * Deletes the node and recurses children
- * @private
- */
- _deleteNode: function(node) {
- var p = node.parent;
- // Remove all the child nodes first
- this.removeChildren(node);
- // Update the parent's collection of children
- var a = [];
- for (i=0, len=p.children.length;i<len;++i) {
- if (p.children[i] != node) {
- a[a.length] = p.children[i];
- }
- }
- p.children = a;
- // reset the childrenRendered flag for the parent
- p.childrenRendered = false;
- // Update the sibling relationship
- if (node.previousSibling) {
- node.previousSibling.nextSibling = node.nextSibling;
- }
- if (node.nextSibling) {
- node.nextSibling.previousSibling = node.previousSibling;
- }
- // Update the tree's node collection
- delete this._nodes[node.index];
- },
- /**
- * Abstract method that is executed when a node is expanded
- *
- * @param node {Node} the node that was expanded
- */
- onExpand: function(node) { },
- /**
- * Abstract method that is executed when a node is collapsed
- *
- * @param node {Node} the node that was collapsed.
- */
- onCollapse: function(node) { }
- };
- /**
- * Global cache of tree instances
- *
- * @type Array
- * @private
- */
- YAHOO.widget.TreeView.trees = [];
- /**
- * Global method for getting a tree by its id. Used in the generated
- * tree html.
- *
- * @param treeId {String} the id of the tree instance
- * @return {TreeView} the tree instance requested, null if not found.
- */
- YAHOO.widget.TreeView.getTree = function(treeId) {
- var t = YAHOO.widget.TreeView.trees[treeId];
- return (t) ? t : null;
- };
- /**
- * Global method for getting a node by its id. Used in the generated
- * tree html.
- *
- * @param treeId {String} the id of the tree instance
- * @param nodeIndex {String} the index of the node to return
- * @return {Node} the node instance requested, null if not found
- */
- YAHOO.widget.TreeView.getNode = function(treeId, nodeIndex) {
- var t = YAHOO.widget.TreeView.getTree(treeId);
- return (t) ? t.getNodeByIndex(nodeIndex) : null;
- };
- /**
- * Adds an event. Replace with event manager when available
- *
- * @param el the elment to bind the handler to
- * @param {string} sType the type of event handler
- * @param {function} fn the callback to invoke
- * @param {boolean} capture if true event is capture phase, bubble otherwise
- */
- YAHOO.widget.TreeView.addHandler = function (el, sType, fn, capture) {
- capture = (capture) ? true : false;
- if (el.addEventListener) {
- el.addEventListener(sType, fn, capture);
- } else if (el.attachEvent) {
- el.attachEvent("on" + sType, fn);
- } else {
- el["on" + sType] = fn;
- }
- };
- /**
- * Attempts to preload the images defined in the styles used to draw the tree by
- * rendering off-screen elements that use the styles.
- */
- YAHOO.widget.TreeView.preload = function() {
- var styles = [
- "ygtvtn",
- "ygtvtm",
- "ygtvtmh",
- "ygtvtp",
- "ygtvtph",
- "ygtvln",
- "ygtvlm",
- "ygtvlmh",
- "ygtvlp",
- "ygtvlph",
- "ygtvloading"
- ];
- var sb = [];
-
- for (var i = 0; i < styles.length; ++i) {
- sb[sb.length] = '<span class="' + styles[i] + '"> </span>';
- }
- var f = document.createElement("div");
- var s = f.style;
- s.position = "absolute";
- s.top = "-1000px";
- s.left = "-1000px";
- f.innerHTML = sb.join("");
- document.body.appendChild(f);
- };
- YAHOO.widget.TreeView.addHandler(window,
- "load", YAHOO.widget.TreeView.preload);
- /* Copyright (c) 2006 Yahoo! Inc. All rights reserved. */
- /**
- * The base class for all tree nodes. The node's presentation and behavior in
- * response to mouse events is handled in Node subclasses.
- *
- * @param oData {object} a string or object containing the data that will
- * be used to render this node
- * @param oParent {Node} this node's parent node
- * @param expanded {boolean} the initial expanded/collapsed state
- * @constructor
- */
- YAHOO.widget.Node = function(oData, oParent, expanded) {
- if (oParent) { this.init(oData, oParent, expanded); }
- };
- YAHOO.widget.Node.prototype = {
- /**
- * The index for this instance obtained from global counter in YAHOO.widget.TreeView.
- *
- * @type int
- */
- index: 0,
- /**
- * This node's child node collection.
- *
- * @type Node[]
- */
- children: null,
- /**
- * Tree instance this node is part of
- *
- * @type TreeView
- */
- tree: null,
- /**
- * The data linked to this node. This can be any object or primitive
- * value, and the data can be used in getNodeHtml().
- *
- * @type object
- */
- data: null,
- /**
- * Parent node
- *
- * @type Node
- */
- parent: null,
- /**
- * The depth of this node. We start at -1 for the root node.
- *
- * @type int
- */
- depth: -1,
- /**
- * The href for the node's label. If one is not specified, the href will
- * be set so that it toggles the node.
- *
- * @type string
- */
- href: null,
- /**
- * The label href target, defaults to current window
- *
- * @type string
- */
- target: "_self",
- /**
- * The node's expanded/collapsed state
- *
- * @type boolean
- */
- expanded: false,
- /**
- * Can multiple children be expanded at once?
- *
- * @type boolean
- */
- multiExpand: true,
- /**
- * Should we render children for a collapsed node? It is possible that the
- * implementer will want to render the hidden data... @todo verify that we
- * need this, and implement it if we do.
- *
- * @type boolean
- */
- renderHidden: false,
- /**
- * This flag is set to true when the html is generated for this node's
- * children, and set to false when new children are added.
- * @type boolean
- */
- childrenRendered: false,
- /**
- * Dynamically loaded nodes only fetch the data the first time they are
- * expanded. This flag is set to true once the data has been fetched.
- * @type boolean
- */
- dynamicLoadComplete: false,
- /**
- * This node's previous sibling
- *
- * @type Node
- */
- previousSibling: null,
- /**
- * This node's next sibling
- *
- * @type Node
- */
- nextSibling: null,
- /**
- * We can set the node up to call an external method to get the child
- * data dynamically.
- *
- * @type boolean
- * @private
- */
- _dynLoad: false,
- /**
- * Function to execute when we need to get this node's child data.
- *
- * @type function
- */
- dataLoader: null,
- /**
- * This is true for dynamically loading nodes while waiting for the
- * callback to return.
- *
- * @type boolean
- */
- isLoading: false,
- /**
- * The toggle/branch icon will not show if this is set to false. This
- * could be useful if the implementer wants to have the child contain
- * extra info about the parent, rather than an actual node.
- *
- * @type boolean
- */
- hasIcon: true,
- /**
- * Used to configure what happens when a dynamic load node is expanded
- * and we discover that it does not have children. By default, it is
- * treated as if it still could have children (plus/minus icon). Set
- * iconMode to have it display like a leaf node instead.
- * @type int
- */
- iconMode: 0,
- /**
- * The node type
- * @private
- */
- _type: "Node",
- /*
- spacerPath: "http://us.i1.yimg.com/us.yimg.com/i/space.gif",
- expandedText: "Expanded",
- collapsedText: "Collapsed",
- loadingText: "Loading",
- */
- /**
- * Initializes this node, gets some of the properties from the parent
- *
- * @param oData {object} a string or object containing the data that will
- * be used to render this node
- * @param oParent {Node} this node's parent node
- * @param expanded {boolean} the initial expanded/collapsed state
- */
- init: function(oData, oParent, expanded) {
- this.data = oData;
- this.children = [];
- this.index = YAHOO.widget.TreeView.nodeCount;
- ++YAHOO.widget.TreeView.nodeCount;
- this.expanded = expanded;
- // oParent should never be null except when we create the root node.
- if (oParent) {
- this.tree = oParent.tree;
- this.parent = oParent;
- this.href = "javascript:" + this.getToggleLink();
- this.depth = oParent.depth + 1;
- this.multiExpand = oParent.multiExpand;
- oParent.appendChild(this);
- }
- },
- /**
- * Appends a node to the child collection.
- *
- * @param node {Node} the new node
- * @return {Node} the child node
- * @private
- * @TODO insertBefore, insertAfter
- */
- appendChild: function(node) {
- if (this.hasChildren()) {
- var sib = this.children[this.children.length - 1];
- sib.nextSibling = node;
- node.previousSibling = sib;
- }
- this.tree.regNode(node);
- this.children[this.children.length] = node;
- this.childrenRendered = false;
- return node;
- },
- /**
- * Returns a node array of this node's siblings, null if none.
- *
- * @return Node[]
- */
- getSiblings: function() {
- return this.parent.children;
- },
- /**
- * Shows this node's children
- */
- showChildren: function() {
- if (!this.tree.animateExpand(this.getChildrenEl())) {
- if (this.hasChildren()) {
- this.getChildrenEl().style.display = "";
- }
- }
- },
- /**
- * Hides this node's children
- */
- hideChildren: function() {
- if (!this.tree.animateCollapse(this.getChildrenEl())) {
- this.getChildrenEl().style.display = "none";
- }
- },
- /**
- * Returns the id for this node's container div
- *
- * @return {string} the element id
- */
- getElId: function() {
- return "ygtv" + this.index;
- },
- /**
- * Returns the id for this node's children div
- *
- * @return {string} the element id for this node's children div
- */
- getChildrenElId: function() {
- return "ygtvc" + this.index;
- },
- /**
- * Returns the id for this node's toggle element
- *
- * @return {string} the toggel element id
- */
- getToggleElId: function() {
- return "ygtvt" + this.index;
- },
- /**
- * Returns the id for this node's spacer image. The spacer is positioned
- * over the toggle and provides feedback for screen readers.
- * @return {string} the id for the spacer image
- */
- /*
- getSpacerId: function() {
- return "ygtvspacer" + this.index;
- },
- */
- /**
- * Returns this node's container html element
- * @return {HTMLElement} the container html element
- */
- getEl: function() {
- return document.getElementById(this.getElId());
- },
- /**
- * Returns the div that was generated for this node's children
- * @return {HTMLElement} this node's children div
- */
- getChildrenEl: function() {
- return document.getElementById(this.getChildrenElId());
- },
- /**
- * Returns the element that is being used for this node's toggle.
- * @return {HTMLElement} this node's toggle html element
- */
- getToggleEl: function() {
- return document.getElementById(this.getToggleElId());
- },
- /**
- * Returns the element that is being used for this node's spacer.
- * @return {HTMLElement} this node's spacer html element
- */
- /*
- getSpacer: function() {
- return document.getElementById( this.getSpacerId() ) || {};
- },
- */
- /*
- getStateText: function() {
- if (this.isLoading) {
- return this.loadingText;
- } else if (this.hasChildren(true)) {
- if (this.expanded) {
- return this.expandedText;
- } else {
- return this.collapsedText;
- }
- } else {
- return "";
- }
- },
- */
- /**
- * Generates the link that will invoke this node's toggle method
- * @return {string} the javascript url for toggling this node
- */
- getToggleLink: function() {
- return "YAHOO.widget.TreeView.getNode(\'" + this.tree.id + "\'," +
- this.index + ").toggle()";
- },
- /**
- * Hides this nodes children (creating them if necessary), changes the
- * toggle style.
- */
- collapse: function() {
- // Only collapse if currently expanded
- if (!this.expanded) { return; }
- // fire the collapse event handler
- var ret = this.tree.onCollapse(this);
- if ("undefined" != typeof ret && !ret) {
- return;
- }
- if (!this.getEl()) {
- this.expanded = false;
- return;
- }
- // hide the child div
- this.hideChildren();
- this.expanded = false;
- if (this.hasIcon) {
- this.getToggleEl().className = this.getStyle();
- }
- // this.getSpacer().title = this.getStateText();
- },
- /**
- * Shows this nodes children (creating them if necessary), changes the
- * toggle style, and collapses its siblings if multiExpand is not set.
- */
- expand: function() {
- // Only expand if currently collapsed.
- if (this.expanded) { return; }
- // fire the expand event handler
- var ret = this.tree.onExpand(this);
- if ("undefined" != typeof ret && !ret) {
- return;
- }
- if (!this.getEl()) {
- this.expanded = true;
- return;
- }
- if (! this.childrenRendered) {
- this.getChildrenEl().innerHTML = this.renderChildren();
- } else {
- }
- this.expanded = true;
- if (this.hasIcon) {
- this.getToggleEl().className = this.getStyle();
- }
- // this.getSpacer().title = this.getStateText();
- // We do an extra check for children here because the lazy
- // load feature can expose nodes that have no children.
- // if (!this.hasChildren()) {
- if (this.isLoading) {
- this.expanded = false;
- return;
- }
- if (! this.multiExpand) {
- var sibs = this.getSiblings();
- for (var i=0; i<sibs.length; ++i) {
- if (sibs[i] != this && sibs[i].expanded) {
- sibs[i].collapse();
- }
- }
- }
- this.showChildren();
- },
- /**
- * Returns the css style name for the toggle
- *
- * @return {string} the css class for this node's toggle
- */
- getStyle: function() {
- if (this.isLoading) {
- return "ygtvloading";
- } else {
- // location top or bottom, middle nodes also get the top style
- var loc = (this.nextSibling) ? "t" : "l";
- // type p=plus(expand), m=minus(collapase), n=none(no children)
- var type = "n";
- if (this.hasChildren(true) || (this.isDynamic() && !this.getIconMode())) {
- // if (this.hasChildren(true)) {
- type = (this.expanded) ? "m" : "p";
- }
- return "ygtv" + loc + type;
- }
- },
- /**
- * Returns the hover style for the icon
- * @return {string} the css class hover state
- */
- getHoverStyle: function() {
- var s = this.getStyle();
- if (this.hasChildren(true) && !this.isLoading) {
- s += "h";
- }
- return s;
- },
- /**
- * Recursively expands all of this node's children.
- */
- expandAll: function() {
- for (var i=0;i<this.children.length;++i) {
- var c = this.children[i];
- if (c.isDynamic()) {
- alert("Not supported (lazy load + expand all)");
- break;
- } else if (! c.multiExpand) {
- alert("Not supported (no multi-expand + expand all)");
- break;
- } else {
- c.expand();
- c.expandAll();
- }
- }
- },
- /**
- * Recursively collapses all of this node's children.
- */
- collapseAll: function() {
- for (var i=0;i<this.children.length;++i) {
- this.children[i].collapse();
- this.children[i].collapseAll();
- }
- },
- /**
- * Configures this node for dynamically obtaining the child data
- * when the node is first expanded. Calling it without the callback
- * will turn off dynamic load for the node.
- *
- * @param fmDataLoader {function} the function that will be used to get the data.
- * @param iconMode {int} configures the icon that is displayed when a dynamic
- * load node is expanded the first time without children. By default, the
- * "collapse" icon will be used. If set to 1, the leaf node icon will be
- * displayed.
- */
- setDynamicLoad: function(fnDataLoader, iconMode) {
- if (fnDataLoader) {
- this.dataLoader = fnDataLoader;
- this._dynLoad = true;
- } else {
- this.dataLoader = null;
- this._dynLoad = false;
- }
- if (iconMode) {
- this.iconMode = iconMode;
- }
- },
- /**
- * Evaluates if this node is the root node of the tree
- *
- * @return {boolean} true if this is the root node
- */
- isRoot: function() {
- return (this == this.tree.root);
- },
- /**
- * Evaluates if this node's children should be loaded dynamically. Looks for
- * the property both in this instance and the root node. If the tree is
- * defined to load all children dynamically, the data callback function is
- * defined in the root node
- *
- * @return {boolean} true if this node's children are to be loaded dynamically
- */
- isDynamic: function() {
- var lazy = (!this.isRoot() && (this._dynLoad || this.tree.root._dynLoad));
- return lazy;
- },
- getIconMode: function() {
- return (this.iconMode || this.tree.root.iconMode);
- },
- /**
- * Checks if this node has children. If this node is lazy-loading and the
- * children have not been rendered, we do not know whether or not there
- * are actual children. In most cases, we need to assume that there are
- * children (for instance, the toggle needs to show the expandable
- * presentation state). In other times we want to know if there are rendered
- * children. For the latter, "checkForLazyLoad" should be false.
- *
- * @param checkForLazyLoad {boolean} should we check for unloaded children?
- * @return {boolean} true if this has children or if it might and we are
- * checking for this condition.
- */
- hasChildren: function(checkForLazyLoad) {
- return ( this.children.length > 0 ||
- (checkForLazyLoad && this.isDynamic() && !this.dynamicLoadComplete) );
- },
- /**
- * Expands if node is collapsed, collapses otherwise.
- */
- toggle: function() {
- if (!this.tree.locked && ( this.hasChildren(true) || this.isDynamic()) ) {
- if (this.expanded) { this.collapse(); } else { this.expand(); }
- }
- },
- /**
- * Returns the markup for this node and its children.
- *
- * @return {string} the markup for this node and its expanded children.
- */
- getHtml: function() {
- var sb = [];
- sb[sb.length] = '<div class="ygtvitem" id="' + this.getElId() + '">';
- sb[sb.length] = this.getNodeHtml();
- sb[sb.length] = this.getChildrenHtml();
- sb[sb.length] = '</div>';
- return sb.join("");
- },
- /**
- * Called when first rendering the tree. We always build the div that will
- * contain this nodes children, but we don't render the children themselves
- * unless this node is expanded.
- *
- * @return {string} the children container div html and any expanded children
- * @private
- */
- getChildrenHtml: function() {
- var sb = [];
- sb[sb.length] = '<div class="ygtvchildren"';
- sb[sb.length] = ' id="' + this.getChildrenElId() + '"';
- if (!this.expanded) {
- sb[sb.length] = ' style="display:none;"';
- }
- sb[sb.length] = '>';
- // Don't render the actual child node HTML unless this node is expanded.
- if ( (this.hasChildren(true) && this.expanded) ||
- (this.renderHidden && !this.isDynamic()) ) {
- sb[sb.length] = this.renderChildren();
- }
- sb[sb.length] = '</div>';
- return sb.join("");
- },
- /**
- * Generates the markup for the child nodes. This is not done until the node
- * is expanded.
- *
- * @return {string} the html for this node's children
- * @private
- */
- renderChildren: function() {
- var node = this;
- if (this.isDynamic() && !this.dynamicLoadComplete) {
- this.isLoading = true;
- this.tree.locked = true;
- if (this.dataLoader) {
- setTimeout(
- function() {
- node.dataLoader(node,
- function() {
- node.loadComplete();
- });
- }, 10);
-
- } else if (this.tree.root.dataLoader) {
- setTimeout(
- function() {
- node.tree.root.dataLoader(node,
- function() {
- node.loadComplete();
- });
- }, 10);
- } else {
- return "Error: data loader not found or not specified.";
- }
- return "";
- } else {
- return this.completeRender();
- }
- },
- /**
- * Called when we know we have all the child data.
- * @return {string} children html
- */
- completeRender: function() {
- var sb = [];
- for (var i=0; i < this.children.length; ++i) {
- this.children[i].childrenRendered = false;
- sb[sb.length] = this.children[i].getHtml();
- }
-
- this.childrenRendered = true;
- return sb.join("");
- },
- /**
- * Load complete is the callback function we pass to the data provider
- * in dynamic load situations.
- */
- loadComplete: function() {
- this.getChildrenEl().innerHTML = this.completeRender();
- this.dynamicLoadComplete = true;
- this.isLoading = false;
- this.expand();
- this.tree.locked = false;
- },
- /**
- * Returns this node's ancestor at the specified depth.
- *
- * @param {int} depth the depth of the ancestor.
- * @return {Node} the ancestor
- */
- getAncestor: function(depth) {
- if (depth >= this.depth || depth < 0) {
- return null;
- }
- var p = this.parent;
-
- while (p.depth > depth) {
- p = p.parent;
- }
- return p;
- },
- /**
- * Returns the css class for the spacer at the specified depth for
- * this node. If this node's ancestor at the specified depth
- * has a next sibling the presentation is different than if it
- * does not have a next sibling
- *
- * @param {int} depth the depth of the ancestor.
- * @return {string} the css class for the spacer
- */
- getDepthStyle: function(depth) {
- return (this.getAncestor(depth).nextSibling) ?
- "ygtvdepthcell" : "ygtvblankdepthcell";
- },
- /**
- * Get the markup for the node. This is designed to be overrided so that we can
- * support different types of nodes.
- *
- * @return {string} The HTML that will render this node.
- */
- getNodeHtml: function() {
- return "";
- },
- /**
- * Regenerates the html for this node and its children. To be used when the
- * node is expanded and new children have been added.
- */
- refresh: function() {
- // this.loadComplete();
- this.getChildrenEl().innerHTML = this.completeRender();
- if (this.hasIcon) {
- var el = this.getToggleEl();
- if (el) {
- el.className = this.getStyle();
- }
- }
- }
- };
- /* Copyright (c) 2006 Yahoo! Inc. All rights reserved. */
- /**
- * A custom YAHOO.widget.Node that handles the unique nature of
- * the virtual, presentationless root node.
- *
- * @extends YAHOO.widget.Node
- * @constructor
- */
- YAHOO.widget.RootNode = function(oTree) {
- // Initialize the node with null params. The root node is a
- // special case where the node has no presentation. So we have
- // to alter the standard properties a bit.
- this.init(null, null, true);
-
- /**
- * For the root node, we get the tree reference from as a param
- * to the constructor instead of from the parent element.
- *
- * @type TreeView
- */
- this.tree = oTree;
- };
- YAHOO.widget.RootNode.prototype = new YAHOO.widget.Node();
- // overrides YAHOO.widget.Node
- YAHOO.widget.RootNode.prototype.getNodeHtml = function() {
- return "";
- };
- /* Copyright (c) 2006 Yahoo! Inc. All rights reserved. */
- /**
- * The default node presentation. The first parameter should be
- * either a string that will be used as the node's label, or an object
- * that has a string propery called label. By default, the clicking the
- * label will toggle the expanded/collapsed state of the node. By
- * changing the href property of the instance, this behavior can be
- * changed so that the label will go to the specified href.
- *
- * @extends YAHOO.widget.Node
- * @constructor
- * @param oData {object} a string or object containing the data that will
- * be used to render this node
- * @param oParent {YAHOO.widget.Node} this node's parent node
- * @param expanded {boolean} the initial expanded/collapsed state
- */
- YAHOO.widget.TextNode = function(oData, oParent, expanded) {
- this.type = "TextNode";
- if (oParent) {
- this.init(oData, oParent, expanded);
- this.setUpLabel(oData);
- }
- };
- YAHOO.widget.TextNode.prototype = new YAHOO.widget.Node();
- /**
- * The CSS class for the label href. Defaults to ygtvlabel, but can be
- * overridden to provide a custom presentation for a specific node.
- *
- * @type string
- */
- YAHOO.widget.TextNode.prototype.labelStyle = "ygtvlabel";
- /**
- * The derived element id of the label for this node
- *
- * @type string
- */
- YAHOO.widget.TextNode.prototype.labelElId = null;
- /**
- * The text for the label. It is assumed that the oData parameter will
- * either be a string that will be used as the label, or an object that
- * has a property called "label" that we will use.
- *
- * @type string
- */
- YAHOO.widget.TextNode.prototype.label = null;
- /**
- * Sets up the node label
- *
- * @param oData string containing the label, or an object with a label property
- */
- YAHOO.widget.TextNode.prototype.setUpLabel = function(oData) {
- if (typeof oData == "string") {
- oData = { label: oData };
- }
- this.label = oData.label;
-
- // update the link
- if (oData.href) {
- this.href = oData.href;
- }
- // set the target
- if (oData.target) {
- this.target = oData.target;
- }
- if (oData.style) {
- this.labelStyle = oData.style;
- }
- this.labelElId = "ygtvlabelel" + this.index;
- };
- /**
- * Returns the label element
- *
- * @return {object} the element
- */
- YAHOO.widget.TextNode.prototype.getLabelEl = function() {
- return document.getElementById(this.labelElId);
- };
- // overrides YAHOO.widget.Node
- YAHOO.widget.TextNode.prototype.getNodeHtml = function() {
- var sb = [];
- sb[sb.length] = '<table border="0" cellpadding="0" cellspacing="0">';
- sb[sb.length] = '<tr>';
-
- for (i=0;i<this.depth;++i) {
- // sb[sb.length] = '<td class="ygtvdepthcell"> </td>';
- sb[sb.length] = '<td class="' + this.getDepthStyle(i) + '"> </td>';
- }
- var getNode = 'YAHOO.widget.TreeView.getNode(\'' +
- this.tree.id + '\',' + this.index + ')';
- sb[sb.length] = '<td';
- // sb[sb.length] = ' onselectstart="return false"';
- sb[sb.length] = ' id="' + this.getToggleElId() + '"';
- sb[sb.length] = ' class="' + this.getStyle() + '"';
- if (this.hasChildren(true)) {
- sb[sb.length] = ' onmouseover="this.className=';
- sb[sb.length] = getNode + '.getHoverStyle()"';
- sb[sb.length] = ' onmouseout="this.className=';
- sb[sb.length] = getNode + '.getStyle()"';
- }
- sb[sb.length] = ' onclick="javascript:' + this.getToggleLink() + '">';
- /*
- sb[sb.length] = '<img id="' + this.getSpacerId() + '"';
- sb[sb.length] = ' alt=""';
- sb[sb.length] = ' tabindex=0';
- sb[sb.length] = ' src="' + this.spacerPath + '"';
- sb[sb.length] = ' title="' + this.getStateText() + '"';
- sb[sb.length] = ' class="ygtvspacer"';
- // sb[sb.length] = ' onkeypress="return ' + getNode + '".onKeyPress()"';
- sb[sb.length] = ' />';
- */
- sb[sb.length] = ' ';
- sb[sb.length] = '</td>';
- sb[sb.length] = '<td>';
- sb[sb.length] = '<a';
- sb[sb.length] = ' id="' + this.labelElId + '"';
- sb[sb.length] = ' class="' + this.labelStyle + '"';
- sb[sb.length] = ' href="' + this.href + '"';
- sb[sb.length] = ' target="' + this.target + '"';
-
- sb[sb.length] = ' onclick="return ' + getNode + '.onLabelClick(' + getNode +')"';
- /*sb[sb.length] = ' onclick="javascript:' + this.getToggleLink() + '.onLabelClick(' + getNode
- +')"';*/
- if (this.hasChildren(true)) {
- sb[sb.length] = ' onmouseover="document.getElementById(\'';
- sb[sb.length] = this.getToggleElId() + '\').className=';
- sb[sb.length] = getNode + '.getHoverStyle()"';
- sb[sb.length] = ' onmouseout="document.getElementById(\'';
- sb[sb.length] = this.getToggleElId() + '\').className=';
- sb[sb.length] = getNode + '.getStyle()"';
- }
- sb[sb.length] = ' >';
- sb[sb.length] = this.label;
- sb[sb.length] = '</a>';
- sb[sb.length] = '</td>';
- sb[sb.length] = '</tr>';
- sb[sb.length] = '</table>';
- return sb.join("");
- };
- /**
- * Executed when the label is clicked
- * @param me {Node} this node
- * @scope the anchor tag clicked
- * @return false to cancel the anchor click
- */
- YAHOO.widget.TextNode.prototype.onLabelClick = function(me) {
- //return true;
- };
- /* Copyright (c) 2006 Yahoo! Inc. All rights reserved. */
- /**
- * A menu-specific implementation that differs from TextNode in that only
- * one sibling can be expanded at a time.
- * @extends YAHOO.widget.TextNode
- * @constructor
- */
- YAHOO.widget.MenuNode = function(oData, oParent, expanded) {
- if (oParent) {
- this.init(oData, oParent, expanded);
- this.setUpLabel(oData);
- }
- /**
- * Menus usually allow only one branch to be open at a time.
- * @type boolean
- */
- this.multiExpand = false;
- };
- YAHOO.widget.MenuNode.prototype = new YAHOO.widget.TextNode();
- /* Copyright (c) 2006 Yahoo! Inc. All rights reserved. */
- /**
- * This implementation takes either a string or object for the
- * oData argument. If is it a string, we will use it for the display
- * of this node (and it can contain any html code). If the parameter
- * is an object, we look for a parameter called "html" that will be
- * used for this node's display.
- *
- * @extends YAHOO.widget.Node
- * @constructor
- * @param oData {object} a string or object containing the data that will
- * be used to render this node
- * @param oParent {YAHOO.widget.Node} this node's parent node
- * @param expanded {boolean} the initial expanded/collapsed state
- * @param hasIcon {boolean} specifies whether or not leaf nodes should
- * have an icon
- */
- YAHOO.widget.HTMLNode = function(oData, oParent, expanded, hasIcon) {
- if (oParent) {
- this.init(oData, oParent, expanded);
- this.initContent(oData, hasIcon);
- }
- };
- YAHOO.widget.HTMLNode.prototype = new YAHOO.widget.Node();
- /**
- * The CSS class for the label href. Defaults to ygtvlabel, but can be
- * overridden to provide a custom presentation for a specific node.
- *
- * @type string
- */
- YAHOO.widget.HTMLNode.prototype.contentStyle = "ygtvhtml";
- /**
- * The generated id that will contain the data passed in by the implementer.
- *
- * @type string
- */
- YAHOO.widget.HTMLNode.prototype.contentElId = null;
- /**
- * The HTML content to use for this node's display
- *
- * @type string
- */
- YAHOO.widget.HTMLNode.prototype.content = null;
- /**
- * Sets up the node label
- *
- * @param {object} An html string or object containing an html property
- * @param {boolean} hasIcon determines if the node will be rendered with an
- * icon or not
- */
- YAHOO.widget.HTMLNode.prototype.initContent = function(oData, hasIcon) {
- if (typeof oData == "string") {
- oData = { html: oData };
- }
- this.html = oData.html;
- this.contentElId = "ygtvcontentel" + this.index;
- this.hasIcon = hasIcon;
- };
- /**
- * Returns the outer html element for this node's content
- *
- * @return {HTMLElement} the element
- */
- YAHOO.widget.HTMLNode.prototype.getContentEl = function() {
- return document.getElementById(this.contentElId);
- };
- // overrides YAHOO.widget.Node
- YAHOO.widget.HTMLNode.prototype.getNodeHtml = function() {
- var sb = [];
- sb[sb.length] = '<table border="0" cellpadding="0" cellspacing="0">';
- sb[sb.length] = '<tr>';
-
- for (i=0;i<this.depth;++i) {
- sb[sb.length] = '<td class="' + this.getDepthStyle(i) + '"> </td>';
- }
- if (this.hasIcon) {
- sb[sb.length] = '<td';
- sb[sb.length] = ' id="' + this.getToggleElId() + '"';
- sb[sb.length] = ' class="' + this.getStyle() + '"';
- sb[sb.length] = ' onclick="javascript:' + this.getToggleLink() + '"';
- if (this.hasChildren(true)) {
- sb[sb.length] = ' onmouseover="this.className=';
- sb[sb.length] = 'YAHOO.widget.TreeView.getNode(\'';
- sb[sb.length] = this.tree.id + '\',' + this.index + ').getHoverStyle()"';
- sb[sb.length] = ' onmouseout="this.className=';
- sb[sb.length] = 'YAHOO.widget.TreeView.getNode(\'';
- sb[sb.length] = this.tree.id + '\',' + this.index + ').getStyle()"';
- }
- sb[sb.length] = '> </td>';
- }
- sb[sb.length] = '<td';
- sb[sb.length] = ' id="' + this.contentElId + '"';
- sb[sb.length] = ' class="' + this.contentStyle + '"';
- sb[sb.length] = ' >';
- sb[sb.length] = this.html;
- sb[sb.length] = '</td>';
- sb[sb.length] = '</tr>';
- sb[sb.length] = '</table>';
- return sb.join("");
- };
- /* Copyright (c) 2006 Yahoo! Inc. All rights reserved. */
- /**
- * A static factory class for tree view expand/collapse animations
- *
- * @constructor
- */
- YAHOO.widget.TVAnim = function() {
- return {
- /**
- * Constant for the fade in animation
- *
- * @type string
- */
- FADE_IN: "TVFadeIn",
- /**
- * Constant for the fade out animation
- *
- * @type string
- */
- FADE_OUT: "TVFadeOut",
- /**
- * Returns a ygAnim instance of the given type
- *
- * @param type {string} the type of animation
- * @param el {HTMLElement} the element to element (probably the children div)
- * @param callback {function} function to invoke when the animation is done.
- * @return {YAHOO.util.Animation} the animation instance
- */
- getAnim: function(type, el, callback) {
- if (YAHOO.widget[type]) {
- return new YAHOO.widget[type](el, callback);
- } else {
- return null;
- }
- },
- /**
- * Returns true if the specified animation class is available
- *
- * @param type {string} the type of animation
- * @return {boolean} true if valid, false if not
- */
- isValid: function(type) {
- return (YAHOO.widget[type]);
- }
- };
- } ();
- /* Copyright (c) 2006 Yahoo! Inc. All rights reserved. */
- /**
- * A 1/2 second fade-in animation.
- *
- * @constructor
- * @param el {HTMLElement} the element to animate
- * @param callback {function} function to invoke when the animation is finished
- */
- YAHOO.widget.TVFadeIn = function(el, callback) {
- /**
- * The element to animate
- * @type HTMLElement
- */
- this.el = el;
- /**
- * the callback to invoke when the animation is complete
- *
- * @type function
- */
- this.callback = callback;
- /**
- * @private
- */
- };
- /**
- * Performs the animation
- */
- YAHOO.widget.TVFadeIn.prototype = {
- animate: function() {
- var tvanim = this;
- var s = this.el.style;
- s.opacity = 0.1;
- s.filter = "alpha(opacity=10)";
- s.display = "";
- // var dur = ( navigator.userAgent.match(/msie/gi) ) ? 0.05 : 0.4;
- var dur = 0.4;
- // var a = new ygAnim_Fade(this.el, dur, 1);
- // a.setStart(0.1);
- // a.onComplete = function() { tvanim.onComplete(); };
- // var a = new YAHOO.util.Anim(this.el, 'opacity', 0.1, 1);
- var a = new YAHOO.util.Anim(this.el, {opacity: {from: 0.1, to: 1, unit:""}}, dur);
- a.onComplete.subscribe( function() { tvanim.onComplete(); } );
- a.animate();
- },
- /**
- * Clean up and invoke callback
- */
- onComplete: function() {
- this.callback();
- }
- };
- /* Copyright (c) 2006 Yahoo! Inc. All rights reserved. */
- /**
- * A 1/2 second fade out animation.
- *
- * @constructor
- * @param el {HTMLElement} the element to animate
- * @param callback {Function} function to invoke when the animation is finished
- */
- YAHOO.widget.TVFadeOut = function(el, callback) {
- /**
- * The element to animate
- * @type HTMLElement
- */
- this.el = el;
- /**
- * the callback to invoke when the animation is complete
- *
- * @type function
- */
- this.callback = callback;
- /**
- * @private
- */
- };
- /**
- * Performs the animation
- */
- YAHOO.widget.TVFadeOut.prototype = {
- animate: function() {
- var tvanim = this;
- // var dur = ( navigator.userAgent.match(/msie/gi) ) ? 0.05 : 0.4;
- var dur = 0.4;
- // var a = new ygAnim_Fade(this.el, dur, 0.1);
- // a.onComplete = function() { tvanim.onComplete(); };
- // var a = new YAHOO.util.Anim(this.el, 'opacity', 1, 0.1);
- var a = new YAHOO.util.Anim(this.el, {opacity: {from: 1, to: 0.1, unit:""}}, dur);
- a.onComplete.subscribe( function() { tvanim.onComplete(); } );
- a.animate();
- },
- /**
- * Clean up and invoke callback
- */
- onComplete: function() {
- var s = this.el.style;
- s.display = "none";
- // s.opacity = 1;
- s.filter = "alpha(opacity=100)";
- this.callback();
- }
- };
|