3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.2.1
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
18 Ext.apply(Ext.Template.prototype, {
19 <div id="cfg-Ext.Template-disableFormats"></div>/**
20 * @cfg {Boolean} disableFormats Specify <tt>true</tt> to disable format
21 * functions in the template. If the template does not contain
22 * {@link Ext.util.Format format functions}, setting <code>disableFormats</code>
23 * to true will reduce <code>{@link #apply}</code> time. Defaults to <tt>false</tt>.
25 var t = new Ext.Template(
26 '<div name="{id}">',
27 '<span class="{cls}">{name} {value}</span>',
30 compiled: true, // {@link #compile} immediately
31 disableFormats: true // reduce <code>{@link #apply}</code> time since no formatting
35 * For a list of available format functions, see {@link Ext.util.Format}.
37 disableFormats : false,
38 <div id="prop-Ext.Template-disableFormats"></div>/**
39 * See <code>{@link #disableFormats}</code>.
41 * @property disableFormats
44 <div id="prop-Ext.Template-re"></div>/**
45 * The regular expression used to match template variables
50 re : /\{([\w-]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g,
51 argsRe : /^\s*['"](.*)["']\s*$/,
53 compileBRe : /(\r\n|\n)/g,
56 <div id="method-Ext.Template-applyTemplate"></div>/**
57 * Returns an HTML fragment of this template with the specified values applied.
58 * @param {Object/Array} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})
59 * @return {String} The HTML fragment
62 applyTemplate : function(values){
64 useF = me.disableFormats !== true,
69 return me.compiled(values);
71 function fn(m, name, format, args){
73 if (format.substr(0, 5) == "this.") {
74 return tpl.call(format.substr(5), values[name], values);
77 // quoted values are required for strings in compiled templates,
78 // but for non compiled we need to strip them
79 // quoted reversed for jsmin
81 args = args.split(',');
82 for(var i = 0, len = args.length; i < len; i++){
83 args[i] = args[i].replace(re, "$1");
85 args = [values[name]].concat(args);
87 args = [values[name]];
89 return fm[format].apply(fm, args);
92 return values[name] !== undefined ? values[name] : "";
95 return me.html.replace(me.re, fn);
98 <div id="method-Ext.Template-compile"></div>/**
99 * Compiles the template into an internal function, eliminating the RegEx overhead.
100 * @return {Ext.Template} this
103 compile : function(){
105 fm = Ext.util.Format,
106 useF = me.disableFormats !== true,
107 sep = Ext.isGecko ? "+" : ",",
110 function fn(m, name, format, args){
112 args = args ? ',' + args : "";
113 if(format.substr(0, 5) != "this."){
114 format = "fm." + format + '(';
116 format = 'this.call("'+ format.substr(5) + '", ';
120 args= ''; format = "(values['" + name + "'] == undefined ? '' : ";
122 return "'"+ sep + format + "values['" + name + "']" + args + ")"+sep+"'";
125 // branched to use + in gecko and [].join() in others
127 body = "this.compiled = function(values){ return '" +
128 me.html.replace(me.compileARe, '\\\\').replace(me.compileBRe, '\\n').replace(me.compileCRe, "\\'").replace(me.re, fn) +
131 body = ["this.compiled = function(values){ return ['"];
132 body.push(me.html.replace(me.compileARe, '\\\\').replace(me.compileBRe, '\\n').replace(me.compileCRe, "\\'").replace(me.re, fn));
133 body.push("'].join('');};");
134 body = body.join('');
140 // private function used to call members
141 call : function(fnName, value, allValues){
142 return this[fnName](value, allValues);
145 Ext.Template.prototype.apply = Ext.Template.prototype.applyTemplate;