📄 xtree.js
字号:
return false; } else if (key == 40) { if (this.open) { this.getFirst().select(); } else { var sib = this.getNextSibling(); if (sib) { sib.select(); } } return false; } else if (key == 38) { this.getPreviousSibling().select(); return false; } return true;}WebFXTreeItem.prototype.toString = function (nItem, nItemCount) { var foo = this.parentNode; var indent = ''; if (nItem + 1 == nItemCount) { this.parentNode._last = true; } var i = 0; while (foo.parentNode) { foo = foo.parentNode; indent = "<img id=\"" + this.id + "-indent-" + i + "\" src=\"" + ((foo._last)?webFXTreeConfig.blankIcon:webFXTreeConfig.iIcon) + "\">" + indent; i++; } this._level = i; if (this.childNodes.length) { this.folder = 1; } else { this.open = false; } if ((this.folder) || (webFXTreeHandler.behavior != 'classic')) { if (!this.icon) { this.icon = webFXTreeConfig.folderIcon; } if (!this.openIcon) { this.openIcon = webFXTreeConfig.openFolderIcon; } } else if (!this.icon) { this.icon = webFXTreeConfig.fileIcon; } var label = this.text.replace(/</g, '<').replace(/>/g, '>'); var str = "<div id=\"" + this.id + "\" ondblclick=\"webFXTreeHandler.toggle(this);\" class=\"webfx-tree-item\" onkeydown=\"return webFXTreeHandler.keydown(this, event)\">" + indent + "<img id=\"" + this.id + "-plus\" src=\"" + ((this.folder)?((this.open)?((this.parentNode._last)?webFXTreeConfig.lMinusIcon:webFXTreeConfig.tMinusIcon):((this.parentNode._last)?webFXTreeConfig.lPlusIcon:webFXTreeConfig.tPlusIcon)):((this.parentNode._last)?webFXTreeConfig.lIcon:webFXTreeConfig.tIcon)) + "\" onclick=\"webFXTreeHandler.toggle(this);\">" + "<img id=\"" + this.id + "-icon\" class=\"webfx-tree-icon\" src=\"" + ((webFXTreeHandler.behavior == 'classic' && this.open)?this.openIcon:this.icon) + "\" onclick=\"webFXTreeHandler.select(this);\">" ; var svalue = this.value; var selectedstr = ""; if(svalue==null){ svalue=this.text; } if(this.radio=="Y"||this.radion=="y"||this.radio=="true"){ str+="<input type=\"Radio\" id=\"selRadioObj\" name=\"selRadioObj\" value=\""+svalue+"\">"; //"+selectedstr+" }else if(this.checkbox=="Y"||this.checkbox=="y"||this.checkbox=="true"){ if(this.checked=="Y"||this.checked=="y"||this.checked=="true"){ selectedstr="checked" } str+="<input type=\"Checkbox\" id=\"selCheckObj\" name=\"selCheckObj\" value=\""+svalue+"\" "+selectedstr+">"; } str+="<a href=\"" + this.action + "\" id=\"" + this.id + "-anchor\" onfocus=\"webFXTreeHandler.focus(this);\" onblur=\"webFXTreeHandler.blur(this);\"" + (this.target ? " target=\"" + this.target + "\"" : "") + ">" + label + "</a></div>" + "<div id=\"" + this.id + "-cont\" class=\"webfx-tree-container\" style=\"display: " + ((this.open)?'block':'none') + ";\">"; var sb = []; for (var i = 0; i < this.childNodes.length; i++) { sb[i] = this.childNodes[i].toString(i,this.childNodes.length); } this.plusIcon = ((this.parentNode._last)?webFXTreeConfig.lPlusIcon:webFXTreeConfig.tPlusIcon); this.minusIcon = ((this.parentNode._last)?webFXTreeConfig.lMinusIcon:webFXTreeConfig.tMinusIcon); //if(this.text=="1.3.1.1") // alert(str + sb.join("") + "</div>"); return str + sb.join("") + "</div>";}/**************************************************************//* xmlextras *//**************************************************************/// used to find the Automation server namefunction getDomDocumentPrefix() { if (getDomDocumentPrefix.prefix) return getDomDocumentPrefix.prefix; var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"]; var o; for (var i = 0; i < prefixes.length; i++) { try { // try to create the objects o = new ActiveXObject(prefixes[i] + ".DomDocument"); return getDomDocumentPrefix.prefix = prefixes[i]; } catch (ex) {}; } throw new Error("Could not find an installed XML parser");}function getXmlHttpPrefix() { if (getXmlHttpPrefix.prefix) return getXmlHttpPrefix.prefix; var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"]; var o; for (var i = 0; i < prefixes.length; i++) { try { // try to create the objects o = new ActiveXObject(prefixes[i] + ".XmlHttp"); return getXmlHttpPrefix.prefix = prefixes[i]; } catch (ex) {}; } throw new Error("Could not find an installed XML parser");}//////////////////////////// Start the Real stuff ////////////////////////////// XmlHttp factoryfunction XmlHttp() {}XmlHttp.create = function () { try { if (window.XMLHttpRequest) { var req = new XMLHttpRequest(); // some versions of Moz do not support the readyState property // and the onreadystate event so we patch it! if (req.readyState == null) { req.readyState = 1; req.addEventListener("load", function () { req.readyState = 4; if (typeof req.onreadystatechange == "function") req.onreadystatechange(); }, false); } return req; } if (window.ActiveXObject) { return new ActiveXObject(getXmlHttpPrefix() + ".XmlHttp"); } } catch (ex) {} // fell through throw new Error("Your browser does not support XmlHttp objects");};// XmlDocument factoryfunction XmlDocument() {}XmlDocument.create = function () { try { // DOM2 if (document.implementation && document.implementation.createDocument) { var doc = document.implementation.createDocument("", "", null); // some versions of Moz do not support the readyState property // and the onreadystate event so we patch it! if (doc.readyState == null) { doc.readyState = 1; doc.addEventListener("load", function () { doc.readyState = 4; if (typeof doc.onreadystatechange == "function") doc.onreadystatechange(); }, false); } return doc; } if (window.ActiveXObject) return new ActiveXObject(getDomDocumentPrefix() + ".DomDocument"); } catch (ex) {} throw new Error("Your browser does not support XmlDocument objects");};// Create the loadXML method and xml getter for Mozillaif (window.DOMParser && window.XMLSerializer && window.Node && Node.prototype && Node.prototype.__defineGetter__) { // XMLDocument did not extend the Document interface in some versions // of Mozilla. Extend both! XMLDocument.prototype.loadXML = Document.prototype.loadXML = function (s) { // parse the string to a new doc var doc2 = (new DOMParser()).parseFromString(s, "text/xml"); // remove all initial children while (this.hasChildNodes()) this.removeChild(this.lastChild); // insert and import nodes for (var i = 0; i < doc2.childNodes.length; i++) { this.appendChild(this.importNode(doc2.childNodes[i], true)); } }; /* * xml getter * * This serializes the DOM tree to an XML String * * Usage: var sXml = oNode.xml * */ // XMLDocument did not extend the Document interface in some versions // of Mozilla. Extend both! XMLDocument.prototype.__defineGetter__("xml", function () { return (new XMLSerializer()).serializeToString(this); }); Document.prototype.__defineGetter__("xml", function () { return (new XMLSerializer()).serializeToString(this); });}/**************************************************************//* xmlextras *//**************************************************************/webFXTreeConfig.loadingText = "正在加载...";webFXTreeConfig.loadErrorTextTemplate = "加载错误 \"%1%\"";webFXTreeConfig.emptyErrorTextTemplate = "错误: \"%1%\" 没有TreeNode节点!";/* * WebFXLoadTree class */function WebFXLoadTree(sText, sXmlSrc, sAction, sBehavior, sIcon, sOpenIcon) { // call super this.WebFXTree = WebFXTree; this.WebFXTree(sText, sAction, sBehavior, sIcon, sOpenIcon); // setup default property values this.src = sXmlSrc; this.loading = false; this.loaded = false; this.errorText = ""; // check start state and load if open if (this.open) _startLoadXmlTree(this.src, this); else { // and create loading item if not this._loadingItem = new WebFXTreeItem(webFXTreeConfig.loadingText); this.add(this._loadingItem); }}WebFXLoadTree.prototype = new WebFXTree;// override the expand method to load the xml fileWebFXLoadTree.prototype._webfxtree_expand = WebFXTree.prototype.expand;WebFXLoadTree.prototype.expand = function() { if (!this.loaded && !this.loading) { // load _startLoadXmlTree(this.src, this); } this._webfxtree_expand();};/* * WebFXLoadTreeItem class */function WebFXLoadTreeItem(sText, sXmlSrc, sAction, eParent, sIcon, sOpenIcon,sRadio,sCheckBox,sValue,sChecked) { // call super this.WebFXTreeItem = WebFXTreeItem; this.WebFXTreeItem(sText, sAction, eParent, sIcon, sOpenIcon); this.radio = sRadio; this.checkbox = sCheckBox; this.value = sValue; this.checked = sChecked; // setup default property values this.src = sXmlSrc; this.loading = false; this.loaded = false; this.errorText = ""; // check start state and load if open if (this.open) _startLoadXmlTree(this.src, this); else { // and create loading item if not this._loadingItem = new WebFXTreeItem(webFXTreeConfig.loadingText); this.add(this._loadingItem); }}WebFXLoadTreeItem.prototype = new WebFXTreeItem;// override the expand method to load the xml fileWebFXLoadTreeItem.prototype._webfxtreeitem_expand = WebFXTreeItem.prototype.expand;WebFXLoadTreeItem.prototype.expand = function() { if (!this.loaded && !this.loading) { // load _startLoadXmlTree(this.src, this); } this._webfxtreeitem_expand();};// reloads the src file if already loadedWebFXLoadTree.prototype.reload =WebFXLoadTreeItem.prototype.reload = function () { // if loading do nothing if (this.loaded) { var open = this.open; // remove try{ while (this.childNodes.length > 0){ this.childNodes[this.childNodes.length - 1].remove(); } }catch(ex){} this.loaded = false; this._loadingItem = new WebFXTreeItem(webFXTreeConfig.loadingText); this.add(this._loadingItem); if (open){ this.expand(); } } else if (this.open && !this.loading){ _startLoadXmlTree(this.src, this); alert(".."); }};/* * Helper functions */// creates the xmlhttp object and starts the load of the xml documentfunction _startLoadXmlTree(sSrc, jsNode) { if (jsNode.loading || jsNode.loaded) return; jsNode.loading = true; var xmlHttp = XmlHttp.create(); xmlHttp.open("GET", sSrc, true); // async xmlHttp.onreadystatechange = function () { if (xmlHttp.readyState == 4) { _xmlFileLoaded(xmlHttp.responseXML, jsNode,sSrc); } }; // call in new thread to allow ui to update window.setTimeout(function () { xmlHttp.send(null); }, 10);}// Converts an xml tree to a js tree. See article about xml tree formatfunction _xmlTreeToJsTree(oNode) { // retreive attributes var text = oNode.getAttribute("text"); var action = oNode.getAttribute("action"); var parent = null; var icon = oNode.getAttribute("icon"); var openIcon = oNode.getAttribute("openIcon"); var src = oNode.getAttribute("src"); var target = oNode.getAttribute("target"); var sRadio = oNode.getAttribute("radio"); var sCheckbox = oNode.getAttribute("checkbox"); var sValue = oNode.getAttribute("value"); var sChecked = oNode.getAttribute("checked"); // create jsNode var jsNode; if (src != null && src != ""){ jsNode = new WebFXLoadTreeItem(text, src, action, parent, icon, openIcon,sRadio,sCheckbox,sValue,sChecked); } else{ jsNode = new WebFXTreeItem(text, action, parent, icon, openIcon,sRadio,sCheckbox,sValue,sChecked); } if (target != ""){ jsNode.target = target; } // go through childNOdes var cs = oNode.childNodes; var l = cs.length; for (var i = 0; i < l; i++) { if (cs[i].tagName == "TreeNode") jsNode.add( _xmlTreeToJsTree(cs[i]), true ); } return jsNode;}// Inserts an xml document as a subtree to the provided nodefunction _xmlFileLoaded(oXmlDoc, jsParentNode,sSrc) { if (jsParentNode.loaded) return; var bIndent = false; var bAnyChildren = false; jsParentNode.loaded = true; jsParentNode.loading = false; //if xmlHTTP load faild. use XmlDocument to load it; if(oXmlDoc == null|| oXmlDoc.documentElement == null){ try{ oXmlDoc = XmlDocument.create(); oXmlDoc.load(sSrc); }catch(ex){ oXmlDoc = null; } } // check that the load of the xml file went well if( oXmlDoc == null || oXmlDoc.documentElement == null) { jsParentNode.errorText = parseTemplateString(webFXTreeConfig.loadErrorTextTemplate, jsParentNode.src); } else { // there is one extra level of tree elements var root = oXmlDoc.documentElement; // loop through all tree children var cs = root.childNodes; var l = cs.length; for (var i = 0; i < l; i++) { if (cs[i].tagName == "TreeNode") { bAnyChildren = true; bIndent = true; jsParentNode.add( _xmlTreeToJsTree(cs[i]), true); } } // if no children we got an error if (!bAnyChildren) jsParentNode.errorText = parseTemplateString(webFXTreeConfig.emptyErrorTextTemplate, jsParentNode.src); } // remove dummy if (jsParentNode._loadingItem != null) { jsParentNode._loadingItem.remove(); bIndent = true; } if (bIndent) { // indent now that all items are added //jsParentNode.indent(); } // show error in status bar if (jsParentNode.errorText != "") window.status = jsParentNode.errorText;}// parses a string and replaces %n% with argument nr nfunction parseTemplateString(sTemplate) { var args = arguments; var s = sTemplate; s = s.replace(/\%\%/g, "%"); for (var i = 1; i < args.length; i++) s = s.replace( new RegExp("\%" + i + "\%", "g"), args[i] ) return s;}//end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -