/ *** I don't know how to upload an attachment, so I have this ********** // ******************************************* ********************************************** Program: My Flybean * version: 1.00 * function: web tree view * author: Juan Island huzhou-cq@163.com * * Copyright 2004-2005 Juan Island ******************** *********************************************************** // ******************************************************** ********************** * Tree.js is a tree map for displaying resources. When creating a tree object, a picture * resource is specified for the tree, By default, image resources are in ImageS / Tree in the IMAGES / TREE of the root of the application, and the user can also replace the corresponding icon with the PUTIMAGE method in the image resource. * If the child node of the node needs to be dynamically loaded, you can add a dynamic loaded node in the node, such as * node.AppenddyNamicChild (URL); * URL is the child node resource. In sub-node resources, you can pass * var iframe = window.frameElement; * var parentnode = iframe.treeparentnode; * var node1 = parentnode.Appendchild ("TEST0", "TEST"); * ParentNode.Appendchild ("Test1", "TEST"); * ParentNode.Appendchild ("test8", "test"); * ParentNode.Appendchild ("test9", "test"); * * // child node is completed * iframe.notify (); * To dynamically load the child node, pay attention to call the Notify method when loading is completed, notify the tree dynamic load * child node is completed. * Note: A tree object can only have a root node ********************************************* ****************************** /
/ ** * Tree style table object * Document DOC tree Document Object * / function treestylesheet (DOC) {this.doc = DOC == NULL? Window.Document: DOC;
// Style Table Object this.stylesheet = this.doc.createstylesheet ();
// Style Table Rule object this.Rules = New Array (6);
// rule selector var selectors = new array (6); selectors [0] = "a.tree ___: link"; selectors [1] = "a.tree ___: visited";
// Note that the definition of the STYLER of A element HOVER must be selectors [2] = "a.tree __: hover" after Visited; selectors [3] = ".tree ___ node_text_td"; selectors [4] = ".tree ___ node_text_td_mouseover"; selectors [5 ] = ".tree ___ node_text_td_selected"; // Rule's csstext var values = new array (6); VALUES [0] = values [1] = "font-size: 12px;" "color: # 000000;" "TEXT -Decoration: None; VALUES [2] = "font-size: 12px;" "color: # cc0000;" "Text-Decoration: underline"; values [3] = values [4] = "Border: None " " Padding-right: 6px; " " padding-left: 6px; " " Padding-top: 1px; " " Height: 19px "; VALUES [5] = VALUES [3] " background Color: # 6face3 ";
For (var i = 0; i this.Rules [i] = this.stylesheet.rules [i]; / ********************************************* * The following is available The method of the object in the tree object style table, * You can get these methods to get the style of the node, * and specify your style ********************** ******************* / / Link default Style this.getLinkStyle = function () {Return this.Rules [0];} // Mouse hovering on the link to the link on the default style = function () {Return this.Rules [1];} // Default by the link to the default style gETLINKVISITEDSTYLE = function () {Return this.Rules [2]; // Node The default of the Cells of the Cell style = function () {Return this.Rules [3];} // Node where the CELL is located with the default of the mouse to move in the mouse shift "@ g r = function () {return this.rules [4];} // Node selected the default of the CELL this.GetNodeElectedSTyle = function () {Return this.Rules [5];}} / ** * Retrieves the node of the current event from the event * / function gettreenode () {var table = window.event.srcelement; while (table.tagname == null || table.tagname! = "Table") {TABLE = Table.ParentNode; if (table == null) {// Nothing found return null;}} Var node = Table.Node; if (node == null) {// did not find return null;} IF (Node == "[Object Treenode]") {return node;} // Didn't find return null;} / ** * Tree icon resource * String Context application name, the default image resource of the tree in * IMAGES / TREE of the application's root directory, access to * /conText/images/tree/*.gif Visit * / Function imagelist (context) {// node icon index // blank picture this.blank = 0; // The icon of the root node of the contracted THIS.ROOT_COLLLAPSED_IMAGE = 1; // Expand the icon of the root node this.Root_expaned_image = 2; // Shrinkful node (with sub-node) icon this.node_collapsed_image = 3; // Expanded node (with subpost) icon this.node_expaned_image = 4; // leaf node icon this.leaf_image = 5; // Connect node icon resources this.line = 6; this.Line_i = 7; this.Line_L = 8; this.Line_L_fallen = 9; this.line_t = 10; this.Line_Plus_Root = 11; this.Line_minus_root = 12; THISLINE_PLUS_ROOT_T = 13; this.line_minus_root_t = 14; this.Line_Plus_L = 15; this.Line_minus_l = 16; this.Line_Plus_t = 17; this.Line_minus_t = 18; // The relative path of the icon resource this.ImageBase = "images / tree /"; if (context! = Null) {if (Context.Charat (Context.length - 1)! = "/") {This.imagebase = context "/" this.Imagebase;} else {this.imagebase = context this.imagebase;}} // icon resource URL this.images = new array (19); this.images [this.blank] = this.imagebase "blank.gif"; this.images [this.root_collapsed_image] = this.imagebase "IMG_Parent_collapsed .gif "; this.images [this.ROOT_EXPANED_IMAGE] = this.imageBase " img_parent_expanded.gif "; this.images [this.NODE_COLLAPSED_IMAGE] = this.imageBase " img_parent_collapsed.gif "; this.images [this.NODE_EXPANED_IMAGE] = this.Imagebase "img_parent_expanded.gif"; this.images [this.Leaf_Image] = this.imagebase "img_leaf.gif"; this.images [this.line] = this.imagebase "line.gif"; this .images [this.line_i] = this.imagebase "line_i.gif"; this.images [this.line_l] = this.gif "; this.gif"; this.Images [this.line_l_fallen] = this.Imagebase "line_l2.gif"; this.images [this.line_t] = this.imagebase "line_t.gif"; this.images [this.line_plus_root] = TH is.imageBase "line_plus_root.gif"; this.images [this.LINE_MINUS_ROOT] = this.imageBase "line_minus_root.gif"; this.images [this.LINE_PLUS_ROOT_T] = this.imageBase "line_plus_root_T.gif"; this. images [this.LINE_MINUS_ROOT_T] = this.imageBase "line_minus_root_T.gif"; this.images [this.LINE_PLUS_L] = this.imageBase "line_plus_L.gif"; this.images [this.LINE_MINUS_L] = this.imageBase " LINE_MINUS_L.GIF "; this.Images [this.line_plus_t] = this.imagebase " line_plus_t.gif "; this.images [this.line_minus_t] = this.ImageBase " line_minus_t.gif "; / ** * Add icon resources To object * int index icon in resource index * String src icon relative URL * int Width icon wide * int Height icon high * / this.putimage = function (index, src, width, height) {this.images [index ] = this.Imagebase src; var img = new image (width, height); img.src = this.images [index]; / ** * Get the SRC * INDEX icon of the icon object in the resource in the resource index * / this.getimage = function (index) {returnimages [index]; THIS.SETIMAGEBASE = Function (URL) {this.imagebase = url} this.getimagebase = function () {returnimhot () {Return this.imagebase;}} / ** * Construct the tree node, this function should be tuned by its parent node. * String TEXT Node Text * String Link Node Link * String ID Node ID * Bean Tree Tree Object * String Target Node Link Target Frame * / Function Treenode (Text, Link, ID, Tree, Target) {/ ** * Node The index in the tree is usually, this value is meaningless. * But maybe we want to hold (with it to associate) this * node object through a simple value, that is, we can find this node object from the tree through this value, we can pass one The node holds the index in the tree * with this object. Note that we should call this method, rather than directly accessing this * attribute. * / This.index = -1; this.getIndex = function () {if (this.index == -1) {this.index = this.tree.getnodeIndex (); this.tree.nodes [this.index] = this;} return this.index;} / ******************************************************************************************************** ******************** * Node's tree * / this.tree = Tree; this.gettree = function () {return this.tree;} / ** * Node's parent node * / this.parentNode = null; this.setParentNode = function (node) {this.parentNode = node;} this.getParentNode = function () {return this.parentNode;} / ** * Whether the node is root node * / this.isroot = function () {return this.parentnode == this.tree;} / ******************************************************************************************** **************** / this.initbranch = function () {/ ** * Connect the branch icon element of the tree node * / this.branch = this.tree.doc.createElement "img"); / ** * Connect the branch icon in the tree node in the index of the icon resource * / this.branch.index = this.tree.Images.Line_L; this.branch.src = this.tree.images.getimage (this.branch.index; this.branch.width = 19; this.branch.height = 20; // branch connection tree node object this.branch.Node = this; / ** * Click the branch icon event, The result is the unfolding or contracting node, * all child nodes of the node, change the node icon, * Change the branch of the connection node * / this.branch.onclick = function () {var node = this.node; if (Node == null;} if (node.haschild ()) {if (node.model) {// Current node shrinks, expand all child node.expand ();} else { // The current node is expanded, shrink all child node node.collapse ();}}}} this.getbranch = function () {return this.branch;} this.setbranchindex = function (index) {this.branch.index = index This.changebranch ();} this.getbranchindex = function () {returnide this.branch.index;} / ** * Set the branches icon * Boolean Haschild node Is there a child node * boolean islastchild current node is the last child node of its parent node * / this.setbranch = function (Haschild, islastchild) {if (Haschild == null) {hasChild = this.hasChild ();} if (isLastChild == null) {isLastChild = this.getNextSibling () == null;}? if (isLastChild) {this.branch.index = hasChild this.tree.images.LINE_PLUS_L : this.tree.Images.Line_L;} else {this.branch.index = Haschild? this.tree.images.Line_plus_t: this.tree.Images.Line_t; }imagebranch ();} / ** * Change the branch icon of the connection node * When the node is contracted and expanded, change its index * / this.changebranch = function (model) {if (model == null) {model = this.model;} (Model) {this.branch.src = this.tree.images.Getimage (this.branch.index);} else {this.branch.src = this.tree.images.getimage (this.branch.index 1) }} / ** * Hidden branch icon * / this.hidebranch = function () {i (this.branch.parentnode! = Null) {this.branch.ParentNode.Width = "1";} this.branch.style.display = "none"; / ** * Show branch icon * / this.showbranch = function () {if (this.branch.parentnode! = Null) {this.branch.ParentNode.Width = "19";} this.branch.Style.display = "block"; / ****************************************************************************************** *************************** / this.initImage = function () {/ ** * Node icon object * / this.createElement ("IMG "); // node symbol When the icon in the resource is indexed in the resource, the index when the index is in the index of the index of the index, this.Index = 0; this.image.WIDTH = 16 Im.image.height = 15; this.image.style.cursor = "hand"; this.image.Node = this; / ** * Handling Node icon Click Event * This event will be processed into a link link Click * / this.Image.onclick = function () {// node var node = this.node; if (node == null) {return;} node.link.click ();} // Load Node Icon this.setImage (false, true);} / ** * Set the current node icon mode * Boolean model value TRUE represents node shrinkage, false representative expansion * / this.setimagemodel = function (model) {if (model == null) {model = this.model;} THIS.IMAGE.SRC = Model? this.tree.images.getimage (this.Image.index): this.tree.Images.getimage (this.Image.index 1);} / ** * Node's icon index * Boolean Haschild node Is there a child node * Boolean Refresh icon is updated * / this.setimage = function (Haschild, refresh) {if (Haschild == null) {Haschild = false;} // Node is contracted at the index of the icon in the resource, the index when expanded, the index of the index is large than the contracted index, 1.Image.index = this.ISROOT () .Tree.Images.Root_collapsed_image: Haschild? This.tree. Images.node_collapsed_image: this.tree.Images.Leaf_Image; if (refresh) {this.image.Src = this.tree.Images.getimage (this.Image.index);}} THISGETIMAGEINDEX = Function () {return this.image.index;} / ** * Node check box, if the tree settings display check box properties, display * / this.checkbox = null; this.setChecked = function (checked) {if (this.checkbox == null) {alert ("Node does not check the box, not supported!"); throw new error ("Node does not check the box, not supported!"); } {Var result = this.onCheck.call (this.oncheck, this, this.checkbox.checked); if (result == false) {return;}} checked = Checked == NULL? false: checked == true; if (checked) {var force = this.tree.getnodeCheckforce (); if ((force & 0x2) == 2) {var checkboxs = this.getTable (). getElementsBytagname ("CheckBox"); this.tree.setnodecheckforce (0); for (var i = 0; i i ) {nodes [i] .setChecked (true);} this.tree.setnodeCheckforce (force);}}} else {var force}} else};}}} else}}}} else}}}} else}}}} else}}}} else}}}} else}}}} else};}}} else};}}} else {var force}}} {Var checkboxs = this.gettable (). GetElementsBytagname ("Checkbox"); this.tree.setnodeCheckforce (0); for (var i = 0; i NULL) {Return False;} Return this.checkbox.checked;} / ************************************************************* ******************************* / / HTML object this.initTextNode = function () {/ ** * Text node object * / this.text = new object (); this.text.text = this.tree.doc.createtextNode (text); // The table object in the text node this.text.table = null; // Text The cell of the node this.Text.td = NULL; // Create an HTML Table Object this.text.table = this.tree.doc.createElement ("Table"); this.text.table.border = "0"; this.Text.Table.cellspacing = 0; this.Text .Table.cellpadding = 0; Var tbody = this.tree.doc.createElement ("tbody"); var tr = this.tree.doc.createElement ("TR"); // node icon of cell var imagetd = this.tree.doc.createElement ("TD"); imagetd.Appendchild (this.Image); if (this.tree.getshowCheckbox ()) {// check box unit VAR CBTD = this.tree.doc.createElement ("TD"); cbtd.valign = "middle"; CBTD.Style.paddingRight = "2px"; CBTD.Style.paddingleft = "2px"; this.checkbox = this .tree.doc.createElement ("Checkbox"); this.checkbox.checked = false; this.checkbox.Node = this; var view = this.tree.doc.createElement ("img"); view.src = this. Tree.getiMages (). getImagebase () "check0.gif"; this.checkbox.onclick = function () {this.node.setChecked (! this.checked);} this.checkbox.Appendchild (view); CBTD. Appendchild (this.checkbox); tr.Appendchild (CBTD);} // node text cell tHISTEXT.TD = this.tree.doc.createElement ("TD"); this.text.td.clas sName = "tree___node_text_td"; this.text.td.noWrap = true; tr.appendChild (imageTD); tr.appendChild (this.text.td); tbody.appendChild (tr); this.text.table.appendChild (tbody ); // Text Node Table Document Object belongs Treenode this.Text.table.Node = this; / ** * Handling node right-click event * / this.text.table.onContextMenu = function () {// node object var node = this.Node; if (node == null) {Return;} if (! Node.onTextMenu == NULL)) {// uses the current node to parameters, callback specified Return Node.onContextMenu.call (node.ontextMenu, Node);}}} this.setnodeValue = function (text) {this.text .Text.nodeValue = text;} THIS.GETNODEVALUE = Function () {return this.text.text.nodevalue;} / *************************************************************************************************** ****************** / this.initLink = function () {// link this.link = this.tree.doc.createElement ("a"); if (Link == NULL) {this.link.disabled = true;} this.link.href = link == null? "null": link; / ** * Link target framework properties * / this.link.target = target; This.Link.ClassName = "Tree ___"; // Link The node this.link.node = this; // Link text this.link.Appendchild (THIS.TEXT.TEXT); // Add Link Object to Text Node THIS .text.td.Appendchild (this.link); / ** * Handling the cell mouse mobile event in the cell node * / this.link.onmouseover = function () {var td = this.parentNode; var node = this.node; if (node == null) {Return; } if (node.getDynamicChildFlagNode ()) {// node resources are dynamically loaded Note node return false;} td.className = "tree___node_text_td_mouseover"; return false;} this.link.onmouseout = function () {var td = this .parentnode; var node = this.node; if (node == null) {return;}}}}}}} {// node is dynamic load resource prompt node Return False;}}}}}} )) {TD.CLASSNAME = "Tree__node_text_td_selected";} else {td.classname = "Tree__node_text_td"; } Return False;} / ** * Handling Node Click Event * / this.link.onclick = function () {i (this.href == "null") {this.blur (); returnaf false;} Else {// node var node = this.node; if (node == null) {return;}}} (! (! (! (!) {// use the current node as a parameter, callback designation method var Result = Node.onclick.call (node.onclick, node); If (result == false) {// Event is canceled return false;}}} // node The tree VAR Tree = node.tree; if (node.getdynamicchildflagnode ()) {// node is dynamic load resource prompt node return false;} this.parentNode.className = "tree___node_text_td_selected"; if {tree.currentSelectedNode.text.td.className = "tree___node_text_td" ((tree.currentSelectedNode == null)!); tree.currentSelectedNode.setSelected (false); } Tree.currentselectedNode = node; node.setSelected (true); this.blur ();}}} this.setLink = function (link) {this.link.href = link;} this.href = function () {Return THIS.LINK.HREF;} THISTARGET = FUNCTION (TARGET) {this.Link.target = target == NULL? ": target;} this.gettarget = function () {return this.link.target;} / ******* ******************************************************************************************************************** ********** / / ** * MODEL is True, the node shrinks, when False, the node expands * / this.model = true; this.getmodel = function () {Return this.model; } // Node is selected this.selected = false; this.setSelected = function (SELECTED) {this.selected = selected;} this.getSelected = function () {return this.selected; / ****************** Node view *************************** ********************* Node Table Object this.table = null; this.gettable = function () {return this.table;} this.tbody = null; / ** * Node ID * / this.id = ID; this.setId = function (id) {this.id = id; this.table.id = this.id;} this.Getid = function () {Return this.id;} / ** * Entremaster view * / this.initview = function () {// Create a branch of the connection node this.initbranch (); // Create a node icon this.initImage (); // Create a node text this THIS .inittextNode (); this.initLink (); // Create an HTML table object this.table = this.tree.doc.createElement ("Table"); this.table.Border = "0"; this.table.cellspacing = 0; this.table.cellpadding = 0; if (this.id! = Null) {this.table.id = this.id;} this.tbody = this.tree.doc.createElement ("TBody"); Var tr = this.tree.doc.createElement ("TR"); // Connect the branches of the node of cells VAR TDBRANCH = this.tree.doc.createElement ("TD"); tdbranch.width = 19; tdbranch.height = 20; tdbranch.Appendchild (this.branch); // node cell var tdnode = this.tree.doc.createElement ("TD"); tdnode.height = 20; tdnode.valign = "bottom"; tdnode.Appendchild (this.Text.Table); Tr.Appendchild (TDBRANCH); Tr.AppendChild (TDNode); this.tbody.Appendchild (TR); This.Table.Appendchild (this.tbody); / / Table object belonging THIS.TABLE.NODE = THIS; Return this.table; / ************************************************************************************************ ******************** / / child node this.children = new object (); // child segment THIS.CHILDREN.COUNT = 0; // The first child node this.children.firstchild = null; this.getfirstchild = function () {returnim.children.firstchild;} // Last child node this.children.lastchild = null; this.getlastchild = function () {return this.Children.lastchild;} The // The target in the node table object in which the child node is located, the object will be hidden this.children.tr = NULL; // Subpoint container this.children.td = NULL; / ** * Connect the cell of the branch of the next node * When the node has a child node, this attribute makes sense * / this.branchtonextNodetd = NULL; / ** * Nodes of the brothers * / this.previoussibling = null; this.getprevioussibling = function () {return this.previoussibling;} / ** * Nodes of the nodes * / this.nextsibling = null; this.getnextsibling = function () {return this.nextsibling;} / ** * Set brother nodes connected to the node branches * boolean hasNextSibling whether a brother node * / this.setBranchToNext = function (hasNextSibling) {if (hasNextSibling == null) {hasNextSibling = (this.nextSibling == null);!} // brothers provided between the branches if (hasNextSibling == true) {this.branchToNextNodeTD.background = this.tree.images.getImage (this.tree.images.LINE_I);} else {this.branchToNextNodeTD.background = null;}} / ** * Node has a child node * / this.haschild = function () {return this.children.firstchild! = Null;} / ** * child node number * / this.getchildcount = function () {return this.Children.count;} / ** * Return all child node objects * / this.getchildNodes = function () {var nodes = new array (this.children.count); var index = 0; var node = this.getFirstChild (); while (Node! = NULL) {nodes [index ] = node; node = node.getnextsibling ();} return nodes; / ** * Add a child node to the current node * Object Obj If this parameter is a string, it is considered a node text, which is the parameter of the * tree node together with other parameters. If the parameter is an Node or Treenode object, add it to the current * tree node and ignore other parameters. * String Link child node link * String ID * String Target child linkage target framework * * Return returns to join the child node * * Note: If the current node is ready to dynamically load the sub-node, the operation will Make the current node no longer load sub * / this.appendchild = function (obj, link, id, target) {if (obj == null) {return null;} // Child Node Object VAR Node = NULL; // node text var text = null; // node if (obj == "[object treenode]") {if (obj.gettree ()! = This.gettree ()) {var message = "node and its quarterly node does not belong to the same tree object"; Alert (Message); throw new error (message);} if (obj.getParentnode ()! = null) {var message = "The current node has a parent node to be added to other nodes"; Alert (Message); throw new error (} node = obj;} else {text = Obj;} if (this.children.count == 0) {if (this.isroot ()) {// Set the root node tree. THISTBRANCHINDEX (THIS. Tree.Images.Line_Plus_Root); // Root node has a subpost, showing tree branches this.showbranch ();} else {// set node tree twig THISTBRANCH (TRUE);} // Update icon this.setImage (true, true); IF (this.children.tr == null) {// Creating sub-node containers this.createChildrentd ();}} IF (target == null) {target = this.link.target; / = NULL; if (node == null) {// Node does not exist, created node = new Treenode (Text, Link, ID, this.tree, Target); = Node.initView ();} else {ct = node.gettable (); node.parentNode = this; // Set the tree branch node.setbranch (null, true); IF (node.haschild ()) {if (this.getnextsibling ()! = null) {// Setting the brothers THIS.SetbranchToneXT (TRUE);}}} // Add a child node's Table document object to this.children.td.Count ; node.parentnode = this; node.parentNode = this; // The last child node of the current node var LastChild = this.children.lastchild; IF (Lastchild! = NULL) {if (Lastchild.getDynamicChildflagNode ()) {// The last child node is a dynamic child node prompt, deleted this.children.td.removechild (Lastchild.Table); this.children.count -; this.children.firstchild = null;} Else {// Set the brothers of the node node.previoussibling = LastChild; // The final node of the younger node lastchild.nextsibling = Node; // Set the branches of the last node lastchild.setbranch (); if (Lastchild.Haschild ()) {// Setting the brother branches lastchild.setbranchtonext (TRUE);}}} // First child node IF (this.children.firstchild == null) {this.children.firstchild = node;} // Last child node this.children.lastchild = node; return node; / ** * prompt dynamic node child node * / this.dynamicChildFlagNode = false; this.setDynamicChildFlagNode = function (flag) {this.dynamicChildFlagNode = flag == null false: flag == true; if (this.dynamicChildFlagNode ==? true) {if) {this.checkbox.parentNode.removeChild (this.checkbox) ((this.checkbox == null!);}}} this.getDynamicChildFlagNode = function () {return this.dynamicChildFlagNode;} / ** * Add a dynamic subpode for the current node * String Link Dynamic subpode resource URL * / this.appenddynamicchild = function (link) {var node = this.Appendchild ("Loading resources ...", link) Node.setdynamicchildflagnode (true); node.image.style.display = "none"; node.link.disabled = true; // Tree has a dynamic child node this.tree.hasDynamicNode = true; Return node; / ** * Create sub-node container * / this.createchildrentd = function () {this.children.tr = this.tree.doc.createElement ("tr"); // Hide all child nodes this.children.tr.style.display = "none"; // node connects the branches of its brother nodes this.branchtonextNodetd = this.tree.doc.createElement ("TD"); if (! This.isroot () && this.parentNode! = Null&&! (This.nextsibling == Null )) {// The current node is not the last child node of its parent node // sets the brothers THISSETBRANCHTONEXT (TRUE); // Sub-node container this.children.td = this.tree.doc.createElement ("TD"); this.children.tr.Appendchild (this.branchtonextNodet); this.children.tr.Appendchild (this.children.td); this.tbody.Appendchild (this.children.tr); / *************************************************************************************** ***************** * Expand Node * Boolean Deep Whether to expand sub-nodes * / this.expand = function (deEP) {if (this.onexpand! = NULL) {// Use the current node as a parameter, callback specified method var result = this.onexpand.call (this.onexpand, this); if (result == false) {// Event is canceled Return False;}}} IF (this.Haschild ()) {if (this.model) {// current node shrinks, expand all child nodes // Update node tree branches this.changebranch (false); // Node icon this.setimagemodel (false); // Show all child nodes this.children.tr.style.display = "block"; THIS.MODEL = FALSE; IF (this.getlastchild (). getDynamicchildflagnode ()) {this.tree.loaddyNamicNodes (this);}} IF (deEP) {if (this.tree.haSDynamicNode) {// has a dynamic subpode, unstopporary returnif;} // Expand sub-node var nodes = this.getChildNodes (); for (var i = 0; i < Nodes.Length; i ) {nodes [i] .expand (true);}}}} / ** * shrink node * / this.collapse = function () {if (this.oncollapse! = null) {// The current node makes the parameters, the callback designation method var result = this.oncollapse.call (this.oncollapse, this); if (result == false) {// Event is canceled Return False;}}}}} ) {If (! This.model) {// The current node is expanded, shrink all sub-nodes // Update node branches this.changebranch (true); // node icon this.setimagemodel (true); // Show all child nodes this.children.tr.style.display = "none"; THIS.MODEL = True;}}} / ** * Select the node * / this.select = function select () {this.link.click (); / ** * User-defined data object, if the object is cloned when the cloning node is cloned, the object should provide method clone, * This method returns an object clone. If there is no CLONE method in the object, it will clone * a reference to this object * / this.userObject = null; this.SetuserObject = function setuserObject (obj) {this.userObject = Obj;} this .getuserObject = function getuserObject () {Return this.userObject;} / ** * Object information * / this.tostring = function () {return ";} this.valueof = function () {return" [object treneode] ";} / ** * Delete nodes Node * Treenode Child child Node * Return Returns the deleted child node * / this.removechild = function (child) {if (child == null) {return null;} if (child.getparentnode ()! = This) {// The node to be deleted is not the child of the current node Return CHild;} // Parent Node Set to null child.parentNode = NULL; // CHILD Node Table Document Object VAR CT = Child.Table; // Delete the document object in the document Document Ct.ParentNode.RemoveChild (CT); IF (child.haschild ()) {child.setbranchtonext (false);} / = Child.previoussibling; if (node! = Null) {node.nextsibling = child.nextsibling; node.setbranch (); if (child.nextsibling == null) {// brother Node branch treatment IF (node.haschild ()) {node.setbranchtonext (false);}}} Node = child.nextsibling; if (node! = null) {node.previoussibling = child.previoussibling; // node subpost chain processing IF (this.getfirstchild () == child) {this.children.firstchild = child.nextsibling;} if (this.getlastchild () == child) {this.children.lastchild = child .previoussibling; Child.nextsibling = null; child.previounsibling = null; this.children.count--; if (this.children.count == 0) {// No child node // node icon this.setImage (false, true) ; // Show all child nodes this.children.tr.style.display = "none"; // node currently shrink this.Model = true; // Delete the node to connect its brother nodes this.setbranchtonext (false); // Set the node tree twig this.setbranch (); / / Delete the reference to the node in the tree, release the resource child.release (); // currently selected node if (this.tree.currentSelectedNode == child) {this.tree.currentSelectedNode = null; child.text.td.className = "tree___node_text_td"; child.setSelected (false);} Return child; / ** * Reference to the node in the tree, release resource * / this.Release = function () {var nodes = this.getChildNodes (); for (var i = 0; i / ** * Clone node and return new node * Boolean deep is cloning the child node * Return return new node * / this.clonenode = function (deep) {if (deEP == null) {deEP = false;} var Text = this.getnodeValue (); var link = this.getlink (); var id = this.getid (); var target = this.gettarget (); VAR newNode = New Treenode (TEXT, LINK, ID, THIS.TREE, TARGET); NewNode.initView (); // Clone Other Data NewNode.setChecked (); if (! (! (! (! (! (! (! (! (! (! (! NULL)) {if (! (@.userObject.clone == null) {newnot.userObject = this.userObject.clone.call (this.userObject);} else {newnode.userObject = this.userObject}} IF This.Dynamicchildflagnode == true) {newnode.dynamicchildflagnode = true;} else {if (deEP == true) {i (this.haschild ()) {var nodes = this.getChildNodes (); for (var i = 0; I / ** * Insert child node * TREENODE NEWCHILD To insert child node * TREENODE Refchild Before you insert this node, * If it is null, the child node to be inserted is added to the end of the front node * Return Returns new nodes inserted * / this.insertbefore = function (newild, refchild) {if (newchild == null) {Return NULL;} if (refchild == null) {this.Appendchild (newchild);}; NewChild.gettree ()! = this.gettree ()) {var message = "Node is not the same tree object with its quarterfather node"; Alert (Message); throw new error (message);} if (NewChild.getParentNode) )! = null) {var message = "Node already parent node cannot be added to other nodes"; alert (message); throw new error (message); IF (newchild.haschild ()) {// Set brothers branches newchild.setbranchtonext (TRUE); Newild.setbranch (Null, false); if (refChild.previousSibling == null) {this.children.firstChild = newChild;} else {refChild.previousSibling.nextSibling = newChild;} newChild.previousSibling = refChild.previousSibling; refChild.previousSibling = newChild; newChild.nextSibling = refChild; Newchild.ParentNode = this; this.children.count ; The document object of the tree node is inserted into var pn = refchild.getTable (). ParentNode; pn.insertbefore (), refchild.gettable (), refchnical.gettable ()); return newchild;} / ** * replace child node * Treenode NewChild New child node * TREENODE OLDCHILD will be replaced with child node * * return returns a new node * / this.replacechild = function (newild, oldchild) {ketil (oldchild == null) {return null;} if (OldChild == Newchild) {return newchild;} this.insertbefore; this.RemoveChild (OldChild); return newcHild;} / ** * Click the processing method of the node event, its definition may be: function (node) * event The processor will incorporate the currently clicked node as the first parameter * If this method returns false, the event will be canceled * / this.onclick = null; / ** * Mouse right-click the processing method of the node event, which may be: function (node) * Event processor will introduce the node that is currently right-click on the first parameter * If this method returns false, The event will be canceled * / this.onTextMenu = NULL; / ** * Expand the processing method of the node event, which may be: function (node) * Event processor will introduce the node of the event as the first parameter * If this method returns false, the event will be canceled * / This.onexpand = NULL; / ** * Shrink the processing method of the node event, which may be: function (node) * Event processor will incorporate the node of the event as the first parameter * If this method returns FALSE, the event will be canceled * / This.oncollapse = NULL; / ** * Node checkbox Click the handling method of the event, the definition may be: function (node, checked) * Event processor will use the node of the event as the first parameter, * Check box is clicked The selected status is sent to this method as the second parameter * If this method returns false, the event will be canceled * / this.oncheck = null; / ** * Imitation user mouse click operation, if you call this method, Node object * will be simulated click * / this.click = function () {this.link.click ();}} / ** * Tree object and load the CSS file and the icon resource of the tree * String Context application name, the default image resource of the tree in the * application's root directory, * / Context / images / trees / *. GIF to access, * If it is null, the default is "." * String ParentNodeID tree's ID, the so-called parent object, * actually the father of the HTML object relying on the tree The node, the tree will * display it in it, this value is a must-have * Document Doc, the document object for the tree object * String ID * String Target Link target frame * int Width tree width * int HEIGHT Tree High * Boolean ShowCheckbox Node Take check box * * Note: Generate the code of the tree and its nodes, there is no method such as Document.Write *, so you can specify the defer keyword in the Script tag, * To increase HTML analysis speed * / function flybean (Context, PrextNodeID, DOC, ID, Target, Width, Height, ShowCheckbox) {if (Context == NULL) {Context = ";} / ** * tree Document Object * / this.doc = DOC == NULL? WINDOW.Document: doc; this.getdocument = function () {return this.doc; / / Tree Parent Node Processing if (PreentnodeID == Null) {var message = "Unknown Tree object container, specify the value of the ParentNodeID parameter when creating a tree!"; Alert (Message); // Parent Node Var ParentNode = this.doc.getlementByid (PARENTNODEID); if (ParentNode == Null || ParentNode.NodeType == Null || Parentnode.NodeType! = 1) // Nodetype.Element = 1; {Var Message = "You cannot find an element for the ID" ParentNodeID "from the document object!"; Alert (message); throw new error (message);} / ** * Parent node of the tree * / this.parentNode = ParentNode; this.getParentNode = function () {return this.parentNode;} / ** * Table document object * / this.table = this.doc.createElement ("Table"); this.gettable = function () {return this.table;} / ** * The ID value of the tree object, You can find the Table document object of the tree from the document object * / this.id = ID; if (this.id! = Null) {this.table.id = this.id; }imiD = function () {Return this.id;} this.setid = function (id) {this.id = id; this.table.id = id;} THIS.TABLE.BORDER = "0"; this.table.width = width == NULL? 1: width; this.table.height = height == null? 1: height; this.table.cellspacing = 0; this. Table.cellpadding = 4; this.table.tree = this; / ** * Treatment tree Click event * / this.table.onclick = function () {/ / tree object var tree = this.tree; if (Tree == null) {return;}}} = NULL) {// use trees and nodes as parameters, callback designation Return Tree.onclick.call (Tree.Onclick, Tree, gettreenode ());}} / ** * Treat tree Right-click event * / this.table.onContextMenu = function () {// tree object var tree = this.tree; if (Tree == null) {Return;}} (! OnContextMenu == NULL) {// Use tree and nodes to be parameters, callback designation Return Tree.onContextMenu.call (Tree.OnContextMenu, Tree, gettreenode ());}} Var tbody = this.doc.createElement ("tbody"); var tr = this.doc.createElement ("TR"); / ** * Tree Node's container * / this.bole = this.doc.createElement ("TD"); this.getbole = function () {return this.bole;} this.bole.valign = "TOP"; Tr.Appendchild (this.bole); TBody.Appendchild (THISTABLE.APpendChild (Tbody); this.parentnode.Appendchild (this.table); / ** * Tree style * / this.setStyle = function (classname) {this.table.className = classname;} this.getStyle = function () {return this.table.classname;} / ** * Tree icon resource * / this.images = new imagelist (context); this.getimages = function () {returnimages; / ** * Tree object style sheet * / this.stylesheet = new treestylesheet (this.doc); this.gettreeestylesheet = function () {return this.stylesheet;} / ** * The default target framework of the link in the tree in the tree * / this.target = target == null? ": Target; this.gettarget = function getTarget () {returnTARGet;} this.settarget = function SetTarget {this.target = target;} / ** * Tree Node Display check box * / this.showCheckbox = showcheckbox == null? false: showcheckbox == true; this.setshowCheckbox = function (sc) { IF (sc == null) {sc = false;} this.showCheckbox = sc == true;} this.getshowCheckbox = function () {return this.showCheckbox == true;} / ** * Node check box when the state changes, which affect the degree of child nodes, the default is no effect * * / this.nodeCheckForce = 0; this.getNodeCheckForce = function () {return this.nodeCheckForce;} this.setNodeCheckForce = function (ncf) {this.nodeCheckForce = NCF;} / / tree node object this.nodes = new array (); / ** * root node object * / this.root = null; this.getrootnode = function getRootnode () {returnot.Root; / ** * Create root node * / this.appendrootnode = function (text, link, id, target) {if (this.root! = Null) {// can only have one root node alert ("only available in the tree A root node! "); Throw new error (" There can be only one root node in the tree! ");} Target = target == null? This.target: target; var root = new Treenode (Text, link, id, THIS, TARGET; ROOT.PArenTnode = this; THIS.ROOT = root; // Initialization view var table = root.initview (); this.bole.Appendchild (Table); // Root node tree branches hide root.hidebranch (); return root;} / ** * Node index * / this.nodeIndex = 0; this.GetnodeIndex = function getnodeIndex () {returnidEndeIndex ;} / * ** currently selected node * / this.currentSelectedNode = null; this.getSelectedNode = function () {return this.currentSelectedNode;} / ** * checkbox node * / this.getCheckedNodes = function () {if (this.ShowCheckbox == false) {return null;} var cbs = this.gettable (). getElementsBytagname ("checkbox"); var cns = new array (); var index = 0; for (var i = 0; i / **************************************************************************************************** ************** * IFRAM objects used to dynamically load resources * / this.dynamicWindow = NULL; / ** * There is a dynamic sub-node sign in the tree * / this.hasDynamicNode = false; / ** * Dynamic loaded subpost * TREENODE NODE To dynamically load the child node Node * String SRC resource URL * / this.loadDynamicNodes = function (node) {if (this.dynamicWindow == null) {this.dynamicWindow = This.doc.createElement ("iframe"); this. DynamicWindow.Height = 0; this.dynamicWindow.width = 0; // Wait for the load of the subpode queue this.dynamicWindow.list = new array (); // There is resource being loaded into this. DynamicWindow.lock = false; / ** * A node resource loaded * / this.dynamicWindow.notify = function () {// unlock this.lock = false; if (this.List.Length> 0) {this.load (this.list. Shift ());}} / ** * Load node resource * / this.dynamicWindow.Load = function (node) {if (this.lock) {this.list.push (node);} else {this. Lock = true; this.src = node.children.lastchild.Link.href; = Node;}} this.parentnode.Appendchild (this.dynamicWindow); }.dynamicwindow; this.dynamicWindow.Load (Node); / ** * Expand tree * / this.expand = function () {if (this.hasDynamicNode) {Alert ("There is a dynamic child node in the tree, not expanded!"); Return;} if (this.Root! = Null) {this.Root.expand (true);}} / ** * Returns the node object in the tree according to the index of the node * / this.getnodebyindex = function (index) {if (ISNAN (INDEX)) {Alert ("Node's index must be a value"); throw new error "INDEX is not an effective integer"); IF (INDEX <0) {Alert ("INDEX is not an effective integer"); Throw new error ("INDEX is not an effective integer");} Return this.nodes [index]; / ** * Retrieve node objects according to the ID value of the node, * If there are multiple nodes of the ID value equal to the incoming parameters, return * array * / this.getnodebyid = function (id) {var node = This.doc.GtelementByid (ID); if (node.length == null) {return node.node;} var nodes = new array (); for (var i = 0; i / ** * If you use the mouse to go back to the node in the tree, call to this method, * Its definition may be: function (Tree, Node) * Event Processor will use the node of the tree object and the current mouse right-click Parameter is incoming this method, * If the right-click event does not occur on a node, the second parameter will be null, * If this method returns False, the event will no longer go back * / this.onContextMenu = NULL; / ** * Remove the root node of the tree * Treenode root child node * / this.removechild = function (root) {if (root.getParentNode ()! = This) {// The node to delete is not the root node of the current tree Return root; // The parent node is set to null root.parentNode = null; // Root Node Table Document Object VAR CT = root.table; // Delete the document object of the root node from the document Document; Ct.ParentNode.RemoveChild (CT); // Remove the reference to the node in the tree, release the resource root.release (); // Tree in the tree is also this.root = null; / / Currently selected node if (this.currentselectedNode == root) {this.currentselectedNode = null;} Return root; / ** * Object information * / this.tostring = function () {return "[object tree]";} this.Valueof = function () {return "[object trees";}} / ****** *************************************** * The following parameters indicate the node by its parent node check box * Select the influence of the status, as a call method * setNodeCheckforce parameter ********************************************* ******* /// Select the Node check box when the child node is not affected in flyBean.unaffected_on_Check = 0; // Select the node check box, the direct child node is affected by it, flyBean.Affected_on_check = 1; // Select the node check box, all the children and grandchildren are affected by it, flybean.deep_affected_on_check = 2; // Cancel the Node check box When the child node is not affected by it, flyBean.unaffected_on_cancel = 0; // The direct child node is affected by it when the node check box is affected. FlyBean.Affected_on_cancel = 256; // All children and grandchildren are affected by it when the node check box is affected. FlyBean.deep_Affected_on_cancel = 512; / ************************************************** * Example: * // When the node is selected, the direct child node * Tree.setnodeCheckforce (FlyBean.Affected_on_Check); * * // Cancel all the children and grandchildren * Tree.seTnodeCheckforce (FlyBean.deep_Affected_on_cancel); * * // When selecting the node, select all the children and grandchild nodes * // When the node is canceled, it does not affect its child node * Tree.seTnodeCheckforce (flybean.deep_affected_on_check * | flybean.deep_affected_on_cancel); *********** ********************************************* /