You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

492 lines
20 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-XTemplate-method-constructor'><span id='Ext-XTemplate'>/**
  19. </span></span> * @class Ext.XTemplate
  20. * @extends Ext.Template
  21. * &lt;p&gt;A template class that supports advanced functionality like:&lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  22. * &lt;li&gt;Autofilling arrays using templates and sub-templates&lt;/li&gt;
  23. * &lt;li&gt;Conditional processing with basic comparison operators&lt;/li&gt;
  24. * &lt;li&gt;Basic math function support&lt;/li&gt;
  25. * &lt;li&gt;Execute arbitrary inline code with special built-in template variables&lt;/li&gt;
  26. * &lt;li&gt;Custom member functions&lt;/li&gt;
  27. * &lt;li&gt;Many special tags and built-in operators that aren't defined as part of
  28. * the API, but are supported in the templates that can be created&lt;/li&gt;
  29. * &lt;/ul&gt;&lt;/div&gt;&lt;/p&gt;
  30. * &lt;p&gt;XTemplate provides the templating mechanism built into:&lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  31. * &lt;li&gt;{@link Ext.DataView}&lt;/li&gt;
  32. * &lt;li&gt;{@link Ext.ListView}&lt;/li&gt;
  33. * &lt;li&gt;{@link Ext.form.ComboBox}&lt;/li&gt;
  34. * &lt;li&gt;{@link Ext.grid.TemplateColumn}&lt;/li&gt;
  35. * &lt;li&gt;{@link Ext.grid.GroupingView}&lt;/li&gt;
  36. * &lt;li&gt;{@link Ext.menu.Item}&lt;/li&gt;
  37. * &lt;li&gt;{@link Ext.layout.MenuLayout}&lt;/li&gt;
  38. * &lt;li&gt;{@link Ext.ColorPalette}&lt;/li&gt;
  39. * &lt;/ul&gt;&lt;/div&gt;&lt;/p&gt;
  40. *
  41. * &lt;p&gt;For example usage {@link #XTemplate see the constructor}.&lt;/p&gt;
  42. *
  43. * @constructor
  44. * The {@link Ext.Template#Template Ext.Template constructor} describes
  45. * the acceptable parameters to pass to the constructor. The following
  46. * examples demonstrate all of the supported features.&lt;/p&gt;
  47. *
  48. * &lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  49. *
  50. * &lt;li&gt;&lt;b&gt;&lt;u&gt;Sample Data&lt;/u&gt;&lt;/b&gt;
  51. * &lt;div class=&quot;sub-desc&quot;&gt;
  52. * &lt;p&gt;This is the data object used for reference in each code example:&lt;/p&gt;
  53. * &lt;pre&gt;&lt;code&gt;
  54. var data = {
  55. name: 'Jack Slocum',
  56. title: 'Lead Developer',
  57. company: 'Ext JS, LLC',
  58. email: 'jack@extjs.com',
  59. address: '4 Red Bulls Drive',
  60. city: 'Cleveland',
  61. state: 'Ohio',
  62. zip: '44102',
  63. drinks: ['Red Bull', 'Coffee', 'Water'],
  64. kids: [{
  65. name: 'Sara Grace',
  66. age:3
  67. },{
  68. name: 'Zachary',
  69. age:2
  70. },{
  71. name: 'John James',
  72. age:0
  73. }]
  74. };
  75. * &lt;/code&gt;&lt;/pre&gt;
  76. * &lt;/div&gt;
  77. * &lt;/li&gt;
  78. *
  79. *
  80. * &lt;li&gt;&lt;b&gt;&lt;u&gt;Auto filling of arrays&lt;/u&gt;&lt;/b&gt;
  81. * &lt;div class=&quot;sub-desc&quot;&gt;
  82. * &lt;p&gt;The &lt;b&gt;&lt;tt&gt;tpl&lt;/tt&gt;&lt;/b&gt; tag and the &lt;b&gt;&lt;tt&gt;for&lt;/tt&gt;&lt;/b&gt; operator are used
  83. * to process the provided data object:
  84. * &lt;ul&gt;
  85. * &lt;li&gt;If the value specified in &lt;tt&gt;for&lt;/tt&gt; is an array, it will auto-fill,
  86. * repeating the template block inside the &lt;tt&gt;tpl&lt;/tt&gt; tag for each item in the
  87. * array.&lt;/li&gt;
  88. * &lt;li&gt;If &lt;tt&gt;for=&quot;.&quot;&lt;/tt&gt; is specified, the data object provided is examined.&lt;/li&gt;
  89. * &lt;li&gt;While processing an array, the special variable &lt;tt&gt;{#}&lt;/tt&gt;
  90. * will provide the current array index + 1 (starts at 1, not 0).&lt;/li&gt;
  91. * &lt;/ul&gt;
  92. * &lt;/p&gt;
  93. * &lt;pre&gt;&lt;code&gt;
  94. &amp;lt;tpl &lt;b&gt;for&lt;/b&gt;=&quot;.&quot;&gt;...&amp;lt;/tpl&gt; // loop through array at root node
  95. &amp;lt;tpl &lt;b&gt;for&lt;/b&gt;=&quot;foo&quot;&gt;...&amp;lt;/tpl&gt; // loop through array at foo node
  96. &amp;lt;tpl &lt;b&gt;for&lt;/b&gt;=&quot;foo.bar&quot;&gt;...&amp;lt;/tpl&gt; // loop through array at foo.bar node
  97. * &lt;/code&gt;&lt;/pre&gt;
  98. * Using the sample data above:
  99. * &lt;pre&gt;&lt;code&gt;
  100. var tpl = new Ext.XTemplate(
  101. '&amp;lt;p&gt;Kids: ',
  102. '&amp;lt;tpl &lt;b&gt;for&lt;/b&gt;=&quot;.&quot;&gt;', // process the data.kids node
  103. '&amp;lt;p&gt;{#}. {name}&amp;lt;/p&gt;', // use current array index to autonumber
  104. '&amp;lt;/tpl&gt;&amp;lt;/p&gt;'
  105. );
  106. tpl.overwrite(panel.body, data.kids); // pass the kids property of the data object
  107. * &lt;/code&gt;&lt;/pre&gt;
  108. * &lt;p&gt;An example illustrating how the &lt;b&gt;&lt;tt&gt;for&lt;/tt&gt;&lt;/b&gt; property can be leveraged
  109. * to access specified members of the provided data object to populate the template:&lt;/p&gt;
  110. * &lt;pre&gt;&lt;code&gt;
  111. var tpl = new Ext.XTemplate(
  112. '&amp;lt;p&gt;Name: {name}&amp;lt;/p&gt;',
  113. '&amp;lt;p&gt;Title: {title}&amp;lt;/p&gt;',
  114. '&amp;lt;p&gt;Company: {company}&amp;lt;/p&gt;',
  115. '&amp;lt;p&gt;Kids: ',
  116. '&amp;lt;tpl &lt;b&gt;for=&quot;kids&quot;&lt;/b&gt;&gt;', // interrogate the kids property within the data
  117. '&amp;lt;p&gt;{name}&amp;lt;/p&gt;',
  118. '&amp;lt;/tpl&gt;&amp;lt;/p&gt;'
  119. );
  120. tpl.overwrite(panel.body, data); // pass the root node of the data object
  121. * &lt;/code&gt;&lt;/pre&gt;
  122. * &lt;p&gt;Flat arrays that contain values (and not objects) can be auto-rendered
  123. * using the special &lt;b&gt;&lt;tt&gt;{.}&lt;/tt&gt;&lt;/b&gt; variable inside a loop. This variable
  124. * will represent the value of the array at the current index:&lt;/p&gt;
  125. * &lt;pre&gt;&lt;code&gt;
  126. var tpl = new Ext.XTemplate(
  127. '&amp;lt;p&gt;{name}\&amp;#39;s favorite beverages:&amp;lt;/p&gt;',
  128. '&amp;lt;tpl for=&quot;drinks&quot;&gt;',
  129. '&amp;lt;div&gt; - {.}&amp;lt;/div&gt;',
  130. '&amp;lt;/tpl&gt;'
  131. );
  132. tpl.overwrite(panel.body, data);
  133. * &lt;/code&gt;&lt;/pre&gt;
  134. * &lt;p&gt;When processing a sub-template, for example while looping through a child array,
  135. * you can access the parent object's members via the &lt;b&gt;&lt;tt&gt;parent&lt;/tt&gt;&lt;/b&gt; object:&lt;/p&gt;
  136. * &lt;pre&gt;&lt;code&gt;
  137. var tpl = new Ext.XTemplate(
  138. '&amp;lt;p&gt;Name: {name}&amp;lt;/p&gt;',
  139. '&amp;lt;p&gt;Kids: ',
  140. '&amp;lt;tpl for=&quot;kids&quot;&gt;',
  141. '&amp;lt;tpl if=&quot;age &gt; 1&quot;&gt;',
  142. '&amp;lt;p&gt;{name}&amp;lt;/p&gt;',
  143. '&amp;lt;p&gt;Dad: {&lt;b&gt;parent&lt;/b&gt;.name}&amp;lt;/p&gt;',
  144. '&amp;lt;/tpl&gt;',
  145. '&amp;lt;/tpl&gt;&amp;lt;/p&gt;'
  146. );
  147. tpl.overwrite(panel.body, data);
  148. * &lt;/code&gt;&lt;/pre&gt;
  149. * &lt;/div&gt;
  150. * &lt;/li&gt;
  151. *
  152. *
  153. * &lt;li&gt;&lt;b&gt;&lt;u&gt;Conditional processing with basic comparison operators&lt;/u&gt;&lt;/b&gt;
  154. * &lt;div class=&quot;sub-desc&quot;&gt;
  155. * &lt;p&gt;The &lt;b&gt;&lt;tt&gt;tpl&lt;/tt&gt;&lt;/b&gt; tag and the &lt;b&gt;&lt;tt&gt;if&lt;/tt&gt;&lt;/b&gt; operator are used
  156. * to provide conditional checks for deciding whether or not to render specific
  157. * parts of the template. Notes:&lt;div class=&quot;sub-desc&quot;&gt;&lt;ul&gt;
  158. * &lt;li&gt;Double quotes must be encoded if used within the conditional&lt;/li&gt;
  159. * &lt;li&gt;There is no &lt;tt&gt;else&lt;/tt&gt; operator &amp;mdash; if needed, two opposite
  160. * &lt;tt&gt;if&lt;/tt&gt; statements should be used.&lt;/li&gt;
  161. * &lt;/ul&gt;&lt;/div&gt;
  162. * &lt;pre&gt;&lt;code&gt;
  163. &amp;lt;tpl if=&quot;age &amp;gt; 1 &amp;amp;&amp;amp; age &amp;lt; 10&quot;&gt;Child&amp;lt;/tpl&gt;
  164. &amp;lt;tpl if=&quot;age &gt;= 10 &amp;&amp; age &lt; 18&quot;&gt;Teenager&amp;lt;/tpl&gt;
  165. &amp;lt;tpl &lt;b&gt;if&lt;/b&gt;=&quot;this.isGirl(name)&quot;&gt;...&amp;lt;/tpl&gt;
  166. &amp;lt;tpl &lt;b&gt;if&lt;/b&gt;=&quot;id==\'download\'&quot;&gt;...&amp;lt;/tpl&gt;
  167. &amp;lt;tpl &lt;b&gt;if&lt;/b&gt;=&quot;needsIcon&quot;&gt;&amp;lt;img src=&quot;{icon}&quot; class=&quot;{iconCls}&quot;/&gt;&amp;lt;/tpl&gt;
  168. // no good:
  169. &amp;lt;tpl if=&quot;name == &quot;Jack&quot;&quot;&gt;Hello&amp;lt;/tpl&gt;
  170. // encode &amp;#34; if it is part of the condition, e.g.
  171. &amp;lt;tpl if=&quot;name == &amp;#38;quot;Jack&amp;#38;quot;&quot;&gt;Hello&amp;lt;/tpl&gt;
  172. * &lt;/code&gt;&lt;/pre&gt;
  173. * Using the sample data above:
  174. * &lt;pre&gt;&lt;code&gt;
  175. var tpl = new Ext.XTemplate(
  176. '&amp;lt;p&gt;Name: {name}&amp;lt;/p&gt;',
  177. '&amp;lt;p&gt;Kids: ',
  178. '&amp;lt;tpl for=&quot;kids&quot;&gt;',
  179. '&amp;lt;tpl if=&quot;age &gt; 1&quot;&gt;',
  180. '&amp;lt;p&gt;{name}&amp;lt;/p&gt;',
  181. '&amp;lt;/tpl&gt;',
  182. '&amp;lt;/tpl&gt;&amp;lt;/p&gt;'
  183. );
  184. tpl.overwrite(panel.body, data);
  185. * &lt;/code&gt;&lt;/pre&gt;
  186. * &lt;/div&gt;
  187. * &lt;/li&gt;
  188. *
  189. *
  190. * &lt;li&gt;&lt;b&gt;&lt;u&gt;Basic math support&lt;/u&gt;&lt;/b&gt;
  191. * &lt;div class=&quot;sub-desc&quot;&gt;
  192. * &lt;p&gt;The following basic math operators may be applied directly on numeric
  193. * data values:&lt;/p&gt;&lt;pre&gt;
  194. * + - * /
  195. * &lt;/pre&gt;
  196. * For example:
  197. * &lt;pre&gt;&lt;code&gt;
  198. var tpl = new Ext.XTemplate(
  199. '&amp;lt;p&gt;Name: {name}&amp;lt;/p&gt;',
  200. '&amp;lt;p&gt;Kids: ',
  201. '&amp;lt;tpl for=&quot;kids&quot;&gt;',
  202. '&amp;lt;tpl if=&quot;age &amp;amp;gt; 1&quot;&gt;', // &lt;-- Note that the &amp;gt; is encoded
  203. '&amp;lt;p&gt;{#}: {name}&amp;lt;/p&gt;', // &lt;-- Auto-number each item
  204. '&amp;lt;p&gt;In 5 Years: {age+5}&amp;lt;/p&gt;', // &lt;-- Basic math
  205. '&amp;lt;p&gt;Dad: {parent.name}&amp;lt;/p&gt;',
  206. '&amp;lt;/tpl&gt;',
  207. '&amp;lt;/tpl&gt;&amp;lt;/p&gt;'
  208. );
  209. tpl.overwrite(panel.body, data);
  210. &lt;/code&gt;&lt;/pre&gt;
  211. * &lt;/div&gt;
  212. * &lt;/li&gt;
  213. *
  214. *
  215. * &lt;li&gt;&lt;b&gt;&lt;u&gt;Execute arbitrary inline code with special built-in template variables&lt;/u&gt;&lt;/b&gt;
  216. * &lt;div class=&quot;sub-desc&quot;&gt;
  217. * &lt;p&gt;Anything between &lt;code&gt;{[ ... ]}&lt;/code&gt; is considered code to be executed
  218. * in the scope of the template. There are some special variables available in that code:
  219. * &lt;ul&gt;
  220. * &lt;li&gt;&lt;b&gt;&lt;tt&gt;values&lt;/tt&gt;&lt;/b&gt;: The values in the current scope. If you are using
  221. * scope changing sub-templates, you can change what &lt;tt&gt;values&lt;/tt&gt; is.&lt;/li&gt;
  222. * &lt;li&gt;&lt;b&gt;&lt;tt&gt;parent&lt;/tt&gt;&lt;/b&gt;: The scope (values) of the ancestor template.&lt;/li&gt;
  223. * &lt;li&gt;&lt;b&gt;&lt;tt&gt;xindex&lt;/tt&gt;&lt;/b&gt;: If you are in a looping template, the index of the
  224. * loop you are in (1-based).&lt;/li&gt;
  225. * &lt;li&gt;&lt;b&gt;&lt;tt&gt;xcount&lt;/tt&gt;&lt;/b&gt;: If you are in a looping template, the total length
  226. * of the array you are looping.&lt;/li&gt;
  227. * &lt;li&gt;&lt;b&gt;&lt;tt&gt;fm&lt;/tt&gt;&lt;/b&gt;: An alias for &lt;tt&gt;Ext.util.Format&lt;/tt&gt;.&lt;/li&gt;
  228. * &lt;/ul&gt;
  229. * This example demonstrates basic row striping using an inline code block and the
  230. * &lt;tt&gt;xindex&lt;/tt&gt; variable:&lt;/p&gt;
  231. * &lt;pre&gt;&lt;code&gt;
  232. var tpl = new Ext.XTemplate(
  233. '&amp;lt;p&gt;Name: {name}&amp;lt;/p&gt;',
  234. '&amp;lt;p&gt;Company: {[values.company.toUpperCase() + &quot;, &quot; + values.title]}&amp;lt;/p&gt;',
  235. '&amp;lt;p&gt;Kids: ',
  236. '&amp;lt;tpl for=&quot;kids&quot;&gt;',
  237. '&amp;lt;div class=&quot;{[xindex % 2 === 0 ? &quot;even&quot; : &quot;odd&quot;]}&quot;&gt;',
  238. '{name}',
  239. '&amp;lt;/div&gt;',
  240. '&amp;lt;/tpl&gt;&amp;lt;/p&gt;'
  241. );
  242. tpl.overwrite(panel.body, data);
  243. * &lt;/code&gt;&lt;/pre&gt;
  244. * &lt;/div&gt;
  245. * &lt;/li&gt;
  246. *
  247. * &lt;li&gt;&lt;b&gt;&lt;u&gt;Template member functions&lt;/u&gt;&lt;/b&gt;
  248. * &lt;div class=&quot;sub-desc&quot;&gt;
  249. * &lt;p&gt;One or more member functions can be specified in a configuration
  250. * object passed into the XTemplate constructor for more complex processing:&lt;/p&gt;
  251. * &lt;pre&gt;&lt;code&gt;
  252. var tpl = new Ext.XTemplate(
  253. '&amp;lt;p&gt;Name: {name}&amp;lt;/p&gt;',
  254. '&amp;lt;p&gt;Kids: ',
  255. '&amp;lt;tpl for=&quot;kids&quot;&gt;',
  256. '&amp;lt;tpl if=&quot;this.isGirl(name)&quot;&gt;',
  257. '&amp;lt;p&gt;Girl: {name} - {age}&amp;lt;/p&gt;',
  258. '&amp;lt;/tpl&gt;',
  259. // use opposite if statement to simulate 'else' processing:
  260. '&amp;lt;tpl if=&quot;this.isGirl(name) == false&quot;&gt;',
  261. '&amp;lt;p&gt;Boy: {name} - {age}&amp;lt;/p&gt;',
  262. '&amp;lt;/tpl&gt;',
  263. '&amp;lt;tpl if=&quot;this.isBaby(age)&quot;&gt;',
  264. '&amp;lt;p&gt;{name} is a baby!&amp;lt;/p&gt;',
  265. '&amp;lt;/tpl&gt;',
  266. '&amp;lt;/tpl&gt;&amp;lt;/p&gt;',
  267. {
  268. // XTemplate configuration:
  269. compiled: true,
  270. disableFormats: true,
  271. // member functions:
  272. isGirl: function(name){
  273. return name == 'Sara Grace';
  274. },
  275. isBaby: function(age){
  276. return age &lt; 1;
  277. }
  278. }
  279. );
  280. tpl.overwrite(panel.body, data);
  281. * &lt;/code&gt;&lt;/pre&gt;
  282. * &lt;/div&gt;
  283. * &lt;/li&gt;
  284. *
  285. * &lt;/ul&gt;&lt;/div&gt;
  286. *
  287. * @param {Mixed} config
  288. */
  289. Ext.XTemplate = function(){
  290. Ext.XTemplate.superclass.constructor.apply(this, arguments);
  291. var me = this,
  292. s = me.html,
  293. re = /&lt;tpl\b[^&gt;]*&gt;((?:(?=([^&lt;]+))\2|&lt;(?!tpl\b[^&gt;]*&gt;))*?)&lt;\/tpl&gt;/,
  294. nameRe = /^&lt;tpl\b[^&gt;]*?for=&quot;(.*?)&quot;/,
  295. ifRe = /^&lt;tpl\b[^&gt;]*?if=&quot;(.*?)&quot;/,
  296. execRe = /^&lt;tpl\b[^&gt;]*?exec=&quot;(.*?)&quot;/,
  297. m,
  298. id = 0,
  299. tpls = [],
  300. VALUES = 'values',
  301. PARENT = 'parent',
  302. XINDEX = 'xindex',
  303. XCOUNT = 'xcount',
  304. RETURN = 'return ',
  305. WITHVALUES = 'with(values){ ';
  306. s = ['&lt;tpl&gt;', s, '&lt;/tpl&gt;'].join('');
  307. while((m = s.match(re))){
  308. var m2 = m[0].match(nameRe),
  309. m3 = m[0].match(ifRe),
  310. m4 = m[0].match(execRe),
  311. exp = null,
  312. fn = null,
  313. exec = null,
  314. name = m2 &amp;&amp; m2[1] ? m2[1] : '';
  315. if (m3) {
  316. exp = m3 &amp;&amp; m3[1] ? m3[1] : null;
  317. if(exp){
  318. fn = new Function(VALUES, PARENT, XINDEX, XCOUNT, WITHVALUES + RETURN +(Ext.util.Format.htmlDecode(exp))+'; }');
  319. }
  320. }
  321. if (m4) {
  322. exp = m4 &amp;&amp; m4[1] ? m4[1] : null;
  323. if(exp){
  324. exec = new Function(VALUES, PARENT, XINDEX, XCOUNT, WITHVALUES +(Ext.util.Format.htmlDecode(exp))+'; }');
  325. }
  326. }
  327. if(name){
  328. switch(name){
  329. case '.': name = new Function(VALUES, PARENT, WITHVALUES + RETURN + VALUES + '; }'); break;
  330. case '..': name = new Function(VALUES, PARENT, WITHVALUES + RETURN + PARENT + '; }'); break;
  331. default: name = new Function(VALUES, PARENT, WITHVALUES + RETURN + name + '; }');
  332. }
  333. }
  334. tpls.push({
  335. id: id,
  336. target: name,
  337. exec: exec,
  338. test: fn,
  339. body: m[1]||''
  340. });
  341. s = s.replace(m[0], '{xtpl'+ id + '}');
  342. ++id;
  343. }
  344. for(var i = tpls.length-1; i &gt;= 0; --i){
  345. me.compileTpl(tpls[i]);
  346. }
  347. me.master = tpls[tpls.length-1];
  348. me.tpls = tpls;
  349. };
  350. Ext.extend(Ext.XTemplate, Ext.Template, {
  351. // private
  352. re : /\{([\w\-\.\#]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?(\s?[\+\-\*\\]\s?[\d\.\+\-\*\\\(\)]+)?\}/g,
  353. // private
  354. codeRe : /\{\[((?:\\\]|.|\n)*?)\]\}/g,
  355. // private
  356. applySubTemplate : function(id, values, parent, xindex, xcount){
  357. var me = this,
  358. len,
  359. t = me.tpls[id],
  360. vs,
  361. buf = [];
  362. if ((t.test &amp;&amp; !t.test.call(me, values, parent, xindex, xcount)) ||
  363. (t.exec &amp;&amp; t.exec.call(me, values, parent, xindex, xcount))) {
  364. return '';
  365. }
  366. vs = t.target ? t.target.call(me, values, parent) : values;
  367. len = vs.length;
  368. parent = t.target ? values : parent;
  369. if(t.target &amp;&amp; Ext.isArray(vs)){
  370. for(var i = 0, len = vs.length; i &lt; len; i++){
  371. buf[buf.length] = t.compiled.call(me, vs[i], parent, i+1, len);
  372. }
  373. return buf.join('');
  374. }
  375. return t.compiled.call(me, vs, parent, xindex, xcount);
  376. },
  377. // private
  378. compileTpl : function(tpl){
  379. var fm = Ext.util.Format,
  380. useF = this.disableFormats !== true,
  381. sep = Ext.isGecko ? &quot;+&quot; : &quot;,&quot;,
  382. body;
  383. function fn(m, name, format, args, math){
  384. if(name.substr(0, 4) == 'xtpl'){
  385. return &quot;'&quot;+ sep +'this.applySubTemplate('+name.substr(4)+', values, parent, xindex, xcount)'+sep+&quot;'&quot;;
  386. }
  387. var v;
  388. if(name === '.'){
  389. v = 'values';
  390. }else if(name === '#'){
  391. v = 'xindex';
  392. }else if(name.indexOf('.') != -1){
  393. v = name;
  394. }else{
  395. v = &quot;values['&quot; + name + &quot;']&quot;;
  396. }
  397. if(math){
  398. v = '(' + v + math + ')';
  399. }
  400. if (format &amp;&amp; useF) {
  401. args = args ? ',' + args : &quot;&quot;;
  402. if(format.substr(0, 5) != &quot;this.&quot;){
  403. format = &quot;fm.&quot; + format + '(';
  404. }else{
  405. format = 'this.call(&quot;'+ format.substr(5) + '&quot;, ';
  406. args = &quot;, values&quot;;
  407. }
  408. } else {
  409. args= ''; format = &quot;(&quot;+v+&quot; === undefined ? '' : &quot;;
  410. }
  411. return &quot;'&quot;+ sep + format + v + args + &quot;)&quot;+sep+&quot;'&quot;;
  412. }
  413. function codeFn(m, code){
  414. // Single quotes get escaped when the template is compiled, however we want to undo this when running code.
  415. return &quot;'&quot; + sep + '(' + code.replace(/\\'/g, &quot;'&quot;) + ')' + sep + &quot;'&quot;;
  416. }
  417. // branched to use + in gecko and [].join() in others
  418. if(Ext.isGecko){
  419. body = &quot;tpl.compiled = function(values, parent, xindex, xcount){ return '&quot; +
  420. tpl.body.replace(/(\r\n|\n)/g, '\\n').replace(/'/g, &quot;\\'&quot;).replace(this.re, fn).replace(this.codeRe, codeFn) +
  421. &quot;';};&quot;;
  422. }else{
  423. body = [&quot;tpl.compiled = function(values, parent, xindex, xcount){ return ['&quot;];
  424. body.push(tpl.body.replace(/(\r\n|\n)/g, '\\n').replace(/'/g, &quot;\\'&quot;).replace(this.re, fn).replace(this.codeRe, codeFn));
  425. body.push(&quot;'].join('');};&quot;);
  426. body = body.join('');
  427. }
  428. eval(body);
  429. return this;
  430. },
  431. <span id='Ext-XTemplate-method-applyTemplate'> /**
  432. </span> * Returns an HTML fragment of this template with the specified values applied.
  433. * @param {Object} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})
  434. * @return {String} The HTML fragment
  435. */
  436. applyTemplate : function(values){
  437. return this.master.compiled.call(this, values, {}, 1, 1);
  438. },
  439. <span id='Ext-XTemplate-method-compile'> /**
  440. </span> * Compile the template to a function for optimized performance. Recommended if the template will be used frequently.
  441. * @return {Function} The compiled function
  442. */
  443. compile : function(){return this;}
  444. <span id='Ext-XTemplate-property-re'> /**
  445. </span> * @property re
  446. * @hide
  447. */
  448. <span id='Ext-XTemplate-property-disableFormats'> /**
  449. </span> * @property disableFormats
  450. * @hide
  451. */
  452. <span id='Ext-XTemplate-method-set'> /**
  453. </span> * @method set
  454. * @hide
  455. */
  456. });
  457. <span id='Ext-XTemplate-method-apply'>/**
  458. </span> * Alias for {@link #applyTemplate}
  459. * Returns an HTML fragment of this template with the specified values applied.
  460. * @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'})
  461. * @return {String} The HTML fragment
  462. * @member Ext.XTemplate
  463. * @method apply
  464. */
  465. Ext.XTemplate.prototype.apply = Ext.XTemplate.prototype.applyTemplate;
  466. <span id='Ext-XTemplate-static-method-from'>/**
  467. </span> * Creates a template from the passed element's value (&lt;i&gt;display:none&lt;/i&gt; textarea, preferred) or innerHTML.
  468. * @param {String/HTMLElement} el A DOM element or its id
  469. * @return {Ext.Template} The created template
  470. * @static
  471. */
  472. Ext.XTemplate.from = function(el){
  473. el = Ext.getDom(el);
  474. return new Ext.XTemplate(el.value || el.innerHTML);
  475. };
  476. </pre>
  477. </body>
  478. </html>