📄 template.js
字号:
$JSI.addCacheScript('js/xml/template.js',function(){this.hook = function(s){return eval(s);};eval(this.varText);function Template(xmlDoc) {this.taglib = {};this.putTaglib(new DefaultTag(), "*");this.putTaglib(new XHTMLTag());this.putTaglib(new CoreTag());if (typeof xmlDoc == "string") {this.doc = Template.loadDoc(xmlDoc);} else {if (xmlDoc != null) {this.doc = xmlDoc;}}}Template.prototype.putTaglib = function (tl, ns) {this.taglib[ns || tl.$namespaceURI] = tl;};Template.loadDoc = function (value) {if (!/^\s*</.test(value)) {var doc = new Request(value).send().getResult();if (typeof doc != "string") {return doc;} else {value = doc;}}if (window.DOMParser) {return new DOMParser().parseFromString(value, "text/xml");} else {var doc = new ActiveXObject("Microsoft.XMLDOM");doc.async = "false";doc.loadXML(value);return doc;}};Template.prototype.render = function (data, out) {if (out == null && data instanceof OutputContext) {var context = data;} else {var context = new OutputContext(data, out);}context.template = this;var ctl = context.taglib;context.taglib = new StackMap(this.taglib);for (var n in ctl) {context.taglib[n] = ctl[n];}context.output(this.doc);};function ValueStack(data) {this.context = data;this.stack = [];}ValueStack.prototype.push = function (data) {this.stack.push(this.context);this.context = new StackMap(this.context);for (var n in data) {this.context[n] = data[n];}};ValueStack.prototype.pop = function () {this.context = this.stack.pop();};ValueStack.prototype.setVariable = function (id, value) {this.context[id] = value;};ValueStack.prototype.getVariable = function (id) {return this.context[id];};function OutputContext(data, out) {if (data == null) {data = {};}this.taglib = {};this.valueStack = new ValueStack(data);this.out = out;if (out.writeln) {this.writeln = this.println = this.nativeWriteln;}this.depth = 0;}OutputContext.prototype.putTaglib = Template.prototype.putTaglib;OutputContext.prototype.print = OutputContext.prototype.write = function (str) {this.out.write(str);};OutputContext.prototype.writeln = OutputContext.prototype.println = function (str) {this.print(str);this.print("\r\n");};OutputContext.prototype.nativeWriteln = function (str) {this.out.writeln(str);};OutputContext.prototype.printIndent = function (str) {return;this.out.write("\r\n");for (var i = 0; i < this.depth; i++) {this.out.write(" ");}};OutputContext.prototype.evalExpression = function (el, showError) {try {with (this.valueStack.context) {return eval(el);}}catch (e) {return this.processException(e);}};OutputContext.prototype.processException = function (e) {$log.debug("expression eval error:", e);return "";};OutputContext.prototype.evalBoolean = function (str) {if (str) {switch (str.toLowerCase()) {case "true":return true;case "false":return false;}try {str = this.evalText(str);if (str == "" || (str.toLowerCase()) == "false") {return false;} else {return true;}}catch (e) {return null;}} else {return null;}};OutputContext.prototype.evalText = function (str) {var k = 0;var result = "";if (!str) {return str;}while (true) {var i = str.indexOf("${", k);while (str.charAt(i - 1) == "\\") {result += str.substring(k, i - 1);k = i;i = str.indexOf("${", k + 1);}if (i >= 0) {var j = str.indexOf("}", i);var x = str.indexOf("{", i + 2);if (x > i && x < j) {for (var d = 1, j = i + 2; j < str.length; j++) {var c = str.charAt(j);if (c == "'" || c == "\"") {while (j < str.length) {j = str.indexOf(c, j + 1);for (var n = j - 1; str.charAt(n) == "\\"; n--) {}if ((j - n) % 2 == 1) {break;}}} else {if (c == "{") {d++;} else {if (c == "}") {d--;if (d == 0) {break;}}}}}}if (i == 0 && j == (str.length - 1)) {var el = str.substring(i + 2, j);return this.evalExpression(el);}if (j > 0) {var el = str.substring(i + 2, j);if (str[i - 1] == "!") {result += str.substring(k, i - 1);} else {result += str.substring(k, i);}try {result += this.evalExpression(el);}catch (e) {}finally {k = j + 1;}continue;} else {result += str.substring(k, str.length);break;}} else {result += str.substring(k, str.length);break;}}return result;};OutputContext.prototype.encodeText = function (str) {return str ? str.toString().replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&") : "";};OutputContext.prototype.encodeAttribute = function (str) {return str ? str.toString().replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&") : "";};OutputContext.prototype.getTaglib = function (ns) {if (ns) {return this.taglib[ns] || this.taglib["*"];} else {return this.taglib["*"];}};OutputContext.prototype.output = function (node) {if (node == null) {return;}var taglib = this.getTaglib(node.namespaceURI);switch (node.nodeType) {case 1:taglib.$Element(this, node);break;case 3:taglib.$Text(this, node);break;case 4:taglib.$CDATASection(this, node);break;case 5:this.$EntityReference(this, node);break;case 6:taglib.$Entity(this, node);break;case 7:taglib.$ProcessingInstruction(this, node);break;case 8:taglib.$Comment(this, node);break;case 9:taglib.$Document(this, node);break;case 10:taglib.$DocumentType(this, node);break;case 11:taglib.$DocumentFragment(this, node);break;case 12:taglib.$Notation(this, node);break;case 2:taglib.$Attribute(this, node);break;default:this.println("<!-- ERROR\uff1a UNKNOW nodeType:" + node.nodeType + "-->");}};});
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -