📄 ajaxtags_parser.js
字号:
/** * Copyright 2005 Darren L. Spurgeon * Copyright 2007-2008 Jens Kapitza * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *//** * Response Parsers defaults and functions wich can be used for HTML, TEXT and * XML call DefaultResponseParser(TYPE) with the needed type */var DefaultResponseParser = Class .create( { initialize : function(defaultType) { this.type = defaultType || "xml"; this.content = null; this.contentText = null; this.contentXML = null; }, load : function(request) { this.contentText = request.responseText; this.contentXML = request.responseXML; this.parse(); }, parse : function(forceType) { var cache = this.type; var xdata; if (arguments.length == 1) { this.type = forceType; } if (this.type == "xml") { var root = this.contentXML.documentElement; var responseNodes = root.getElementsByTagName("response"); xdata = []; responseNodes.each = Array.prototype._each; responseNodes .each( function(responseNode) { items = responseNode .getElementsByTagName("item"); items.each = Array.prototype._each; items.each( function(itemNode) { nameNodes = itemNode .getElementsByTagName("name"); valueNodes = itemNode .getElementsByTagName("value"); var row = []; nameNodes.each = Array.prototype._each; valueNodes.each = Array.prototype._each; nameNodes .each( function( nameNode) { row .push(nameNode.firstChild ? nameNode.firstChild.nodeValue : ""); }); if (row.length != 1) { throw new Error( "XML is not supported"); } valueNodes .each( function( valueNode) { row .push(valueNode.firstChild ? valueNode.firstChild.nodeValue : ""); }); xdata.push(row); }); }); } else if (this.type == "text") { xdata = []; this.contentText.split('\n').each( function(line) { xdata.push(line.split(',')); }); } else if (this.type == "html") { xdata = this.contentText; // response is HMTL } this.content = xdata; this.type = cache; // just copy it back } });var ResponseXmlToHtmlParser = Class.create(DefaultResponseParser, { initialize : function($super,isPlainText) { $super(); this.plaintext = isPlainText ? true : false; }, parse : function($super) { $super(); // call parent var contentdiv = document.createElement("div"); for (i = 0; i < this.content.length; i++) { h1 = document.createElement("h1"); if (!this.plaintext) { h1.innerHTML += this.content[i][0]; } else { h1.appendChild(document.createTextNode(this.content[i][0])); } contentdiv.appendChild(h1); for (j = 1; j < this.content[i].length; j++) { div = document.createElement("div"); if (!this.plaintext) { div.innerHTML += this.content[i][j]; } else { div.appendChild(document.createTextNode(this.content[i][j])); } contentdiv.appendChild(div); } } // #4 // now switch content if (this.content.length >= 1) { this.content = contentdiv.innerHTML; } else { this.content = ""; // keine daten dann '' } // skip plz}});var ResponseCallBackXmlParser = Class.create(DefaultResponseParser, { initialize : function($super) { $super(); }, // XXX remove this prepareData : function(dataarray) { this.items = []; for (i = 0; i < dataarray.length; i++) { this.items.push( [ dataarray[i][0], dataarray[i][1], (dataarray[i][2] ? true : false) ]); } }});var ResponseXmlToHtmlListParser = Class.create(DefaultResponseParser, { initialize : function($super, isNotPlainText) { $super("xmltohtmllist"); // base init this.plaintext = isNotPlainText ? false : true;},parse : function($super) { $super("xml"); var contentdiv = document.createElement("div"); var ul = document.createElement("ul"); for (i = 0; i < this.content.length; i++) { liElement = document.createElement("li"); liElement.id = this.content[i][1]; if (this.plaintext) { liElement.appendChild(document.createTextNode(this.content[i][0])); } else { liElement.innerHTML = this.content[i][0]; } ul.appendChild(liElement); } contentdiv.appendChild(ul); if (this.content.length >= 1) { this.content = contentdiv.innerHTML; } else { this.content = ""; // keine daten dann ''}}});var ResponseXmlToHtmlLinkListParser = Class .create( DefaultResponseParser, { initialize : function($super) { $super( "xmltohtmllinklist"); }, load : function(request) { this.xml = request.responseXML; this.collapsedClass = request.collapsedClass; this.treeClass = request.treeClass; this.nodeClass = request.nodeClass; this.expandedNodes = []; this.parse(); }, parse : function() { var ul = document.createElement('ul'); ul.className = this.treeClass; var root = this.xml.documentElement; var responseNodes = root .getElementsByTagName("response"); if (responseNodes.length > 0) { responseNode = responseNodes[0]; itemNodes = responseNode .getElementsByTagName("item"); if (itemNodes.length === 0) { ul = null; } for (i = 0; i < itemNodes.length; i++) { nameNodes = itemNodes[i] .getElementsByTagName("name"); valueNodes = itemNodes[i] .getElementsByTagName("value"); urlNodes = itemNodes[i] .getElementsByTagName("url"); collapsedNodes = itemNodes[i] .getElementsByTagName("collapsed"); leafnodes = itemNodes[i] .getElementsByTagName("leaf"); if (nameNodes.length > 0 && valueNodes.length > 0) { name = nameNodes[0].firstChild.nodeValue; value = valueNodes[0].firstChild.nodeValue; url = "#"; if (urlNodes.length > 0) { url = urlNodes[0].firstChild.nodeValue; } leaf = false; if (leafnodes.length > 0) { leaf = leafnodes[0].firstChild.nodeValue; } collapsed = false; if (collapsedNodes.length > 0) { collapsed = parseBoolean(collapsedNodes[0].firstChild.nodeValue); } li = document.createElement('li'); li.id = "li_" + value; ul.appendChild(li); if (!parseBoolean(leaf)) { span = document.createElement('span'); li.appendChild(span); // img geht im IE nicht span.id = "span_" + value; span.className = this.collapsedClass; } link = document.createElement('a'); li.appendChild(link); link.href = url; link.className = this.nodeClass; link.appendChild(document .createTextNode(name)); div = document.createElement('div'); li.appendChild(div); div.id = value; div.setAttribute("style", ""); div.style.display = "none"; if (!collapsed) { this.expandedNodes.push(value); } } } } this.content = ul; } });
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -