X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/c930e9176a5a85509c5b0230e2bff5c22a591432..b37ceabb82336ee82757cd32efe353cfab8ec267:/src/util/XTemplate.js diff --git a/src/util/XTemplate.js b/src/util/XTemplate.js index e8e78156..09f1994d 100644 --- a/src/util/XTemplate.js +++ b/src/util/XTemplate.js @@ -1,18 +1,44 @@ /*! - * Ext JS Library 3.0.0 - * Copyright(c) 2006-2009 Ext JS, LLC + * Ext JS Library 3.2.2 + * Copyright(c) 2006-2010 Ext JS, Inc. * licensing@extjs.com * http://www.extjs.com/license */ /** * @class Ext.XTemplate * @extends Ext.Template - *

A template class that supports advanced functionality like autofilling arrays, conditional processing with - * basic comparison operators, sub-templates, basic math function support, special built-in template variables, - * inline code execution and more. XTemplate also provides the templating mechanism built into {@link Ext.DataView}.

- *

XTemplate supports many special tags and built-in operators that aren't defined as part of the API, but are - * supported in the templates that can be created. The following examples demonstrate all of the supported features. - * This is the data object used for reference in each code example:

+ *

A template class that supports advanced functionality like:

+ *

XTemplate provides the templating mechanism built into:

+ * + *

For example usage {@link #XTemplate see the constructor}.

+ * + * @constructor + * The {@link Ext.Template#Template Ext.Template constructor} describes + * the acceptable parameters to pass to the constructor. The following + * examples demonstrate all of the supported features.

+ * + *
+ * + * @param {Mixed} config */ Ext.XTemplate = function(){ Ext.XTemplate.superclass.constructor.apply(this, arguments); var me = this, - s = me.html, - re = /]*>((?:(?=([^<]+))\2|<(?!tpl\b[^>]*>))*?)<\/tpl>/, - nameRe = /^]*?for="(.*?)"/, - ifRe = /^]*?if="(.*?)"/, - execRe = /^]*?exec="(.*?)"/, - m, - id = 0, - tpls = [], - VALUES = 'values', - PARENT = 'parent', - XINDEX = 'xindex', - XCOUNT = 'xcount', - RETURN = 'return ', - WITHVALUES = 'with(values){ '; + s = me.html, + re = /]*>((?:(?=([^<]+))\2|<(?!tpl\b[^>]*>))*?)<\/tpl>/, + nameRe = /^]*?for="(.*?)"/, + ifRe = /^]*?if="(.*?)"/, + execRe = /^]*?exec="(.*?)"/, + m, + id = 0, + tpls = [], + VALUES = 'values', + PARENT = 'parent', + XINDEX = 'xindex', + XCOUNT = 'xcount', + RETURN = 'return ', + WITHVALUES = 'with(values){ '; s = ['', s, ''].join(''); while((m = s.match(re))){ - var m2 = m[0].match(nameRe), - m3 = m[0].match(ifRe), - m4 = m[0].match(execRe), - exp = null, - fn = null, - exec = null, - name = m2 && m2[1] ? m2[1] : ''; + var m2 = m[0].match(nameRe), + m3 = m[0].match(ifRe), + m4 = m[0].match(execRe), + exp = null, + fn = null, + exec = null, + name = m2 && m2[1] ? m2[1] : ''; if (m3) { exp = m3 && m3[1] ? m3[1] : null; @@ -236,9 +334,9 @@ Ext.XTemplate = function(){ s = s.replace(m[0], '{xtpl'+ id + '}'); ++id; } - Ext.each(tpls, function(t) { - me.compileTpl(t); - }); + for(var i = tpls.length-1; i >= 0; --i){ + me.compileTpl(tpls[i]); + } me.master = tpls[tpls.length-1]; me.tpls = tpls; }; @@ -251,10 +349,10 @@ Ext.extend(Ext.XTemplate, Ext.Template, { // private applySubTemplate : function(id, values, parent, xindex, xcount){ var me = this, - len, - t = me.tpls[id], - vs, - buf = []; + len, + t = me.tpls[id], + vs, + buf = []; if ((t.test && !t.test.call(me, values, parent, xindex, xcount)) || (t.exec && t.exec.call(me, values, parent, xindex, xcount))) { return ''; @@ -263,9 +361,9 @@ Ext.extend(Ext.XTemplate, Ext.Template, { len = vs.length; parent = t.target ? values : parent; if(t.target && Ext.isArray(vs)){ - Ext.each(vs, function(v, i) { - buf[buf.length] = t.compiled.call(me, v, parent, i+1, len); - }); + for(var i = 0, len = vs.length; i < len; i++){ + buf[buf.length] = t.compiled.call(me, vs[i], parent, i+1, len); + } return buf.join(''); } return t.compiled.call(me, vs, parent, xindex, xcount); @@ -274,7 +372,7 @@ Ext.extend(Ext.XTemplate, Ext.Template, { // private compileTpl : function(tpl){ var fm = Ext.util.Format, - useF = this.disableFormats !== true, + useF = this.disableFormats !== true, sep = Ext.isGecko ? "+" : ",", body; @@ -310,7 +408,8 @@ Ext.extend(Ext.XTemplate, Ext.Template, { } function codeFn(m, code){ - return "'"+ sep +'('+code+')'+sep+"'"; + // Single quotes get escaped when the template is compiled, however we want to undo this when running code. + return "'" + sep + '(' + code.replace(/\\'/g, "'") + ')' + sep + "'"; } // branched to use + in gecko and [].join() in others @@ -376,4 +475,4 @@ Ext.XTemplate.prototype.apply = Ext.XTemplate.prototype.applyTemplate; Ext.XTemplate.from = function(el){ el = Ext.getDom(el); return new Ext.XTemplate(el.value || el.innerHTML); -}; \ No newline at end of file +};