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.0
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,
52 <div id="method-Ext.Template-applyTemplate"></div>/**
53 * Returns an HTML fragment of this template with the specified values applied.
54 * @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'})
55 * @return {String} The HTML fragment
58 applyTemplate : function(values){
60 useF = me.disableFormats !== true,
65 return me.compiled(values);
67 function fn(m, name, format, args){
69 if (format.substr(0, 5) == "this.") {
70 return tpl.call(format.substr(5), values[name], values);
73 // quoted values are required for strings in compiled templates,
74 // but for non compiled we need to strip them
75 // quoted reversed for jsmin
76 var re = /^\s*['"](.*)["']\s*$/;
77 args = args.split(',');
78 for(var i = 0, len = args.length; i < len; i++){
79 args[i] = args[i].replace(re, "$1");
81 args = [values[name]].concat(args);
83 args = [values[name]];
85 return fm[format].apply(fm, args);
88 return values[name] !== undefined ? values[name] : "";
91 return me.html.replace(me.re, fn);
94 <div id="method-Ext.Template-compile"></div>/**
95 * Compiles the template into an internal function, eliminating the RegEx overhead.
96 * @return {Ext.Template} this
101 fm = Ext.util.Format,
102 useF = me.disableFormats !== true,
103 sep = Ext.isGecko ? "+" : ",",
106 function fn(m, name, format, args){
108 args = args ? ',' + args : "";
109 if(format.substr(0, 5) != "this."){
110 format = "fm." + format + '(';
112 format = 'this.call("'+ format.substr(5) + '", ';
116 args= ''; format = "(values['" + name + "'] == undefined ? '' : ";
118 return "'"+ sep + format + "values['" + name + "']" + args + ")"+sep+"'";
121 // branched to use + in gecko and [].join() in others
123 body = "this.compiled = function(values){ return '" +
124 me.html.replace(/\\/g, '\\\\').replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn) +
127 body = ["this.compiled = function(values){ return ['"];
128 body.push(me.html.replace(/\\/g, '\\\\').replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn));
129 body.push("'].join('');};");
130 body = body.join('');
136 // private function used to call members
137 call : function(fnName, value, allValues){
138 return this[fnName](value, allValues);
141 Ext.Template.prototype.apply = Ext.Template.prototype.applyTemplate; </pre>