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.

151 lines
6.0 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-Template'>/**
  19. </span> * @class Ext.Template
  20. */
  21. Ext.apply(Ext.Template.prototype, {
  22. <span id='Ext-Template-cfg-disableFormats'> /**
  23. </span> * @cfg {Boolean} disableFormats Specify &lt;tt&gt;true&lt;/tt&gt; to disable format
  24. * functions in the template. If the template does not contain
  25. * {@link Ext.util.Format format functions}, setting &lt;code&gt;disableFormats&lt;/code&gt;
  26. * to true will reduce &lt;code&gt;{@link #apply}&lt;/code&gt; time. Defaults to &lt;tt&gt;false&lt;/tt&gt;.
  27. * &lt;pre&gt;&lt;code&gt;
  28. var t = new Ext.Template(
  29. '&amp;lt;div name=&quot;{id}&quot;&amp;gt;',
  30. '&amp;lt;span class=&quot;{cls}&quot;&amp;gt;{name} {value}&amp;lt;/span&amp;gt;',
  31. '&amp;lt;/div&amp;gt;',
  32. {
  33. compiled: true, // {@link #compile} immediately
  34. disableFormats: true // reduce &lt;code&gt;{@link #apply}&lt;/code&gt; time since no formatting
  35. }
  36. );
  37. * &lt;/code&gt;&lt;/pre&gt;
  38. * For a list of available format functions, see {@link Ext.util.Format}.
  39. */
  40. disableFormats : false,
  41. <span id='Ext-Template-property-disableFormats'> /**
  42. </span> * See &lt;code&gt;{@link #disableFormats}&lt;/code&gt;.
  43. * @type Boolean
  44. * @property disableFormats
  45. */
  46. <span id='Ext-Template-property-re'> /**
  47. </span> * The regular expression used to match template variables
  48. * @type RegExp
  49. * @property
  50. * @hide repeat doc
  51. */
  52. re : /\{([\w\-]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g,
  53. argsRe : /^\s*['&quot;](.*)[&quot;']\s*$/,
  54. compileARe : /\\/g,
  55. compileBRe : /(\r\n|\n)/g,
  56. compileCRe : /'/g,
  57. <span id='Ext-Template-method-applyTemplate'> /**
  58. </span> * Returns an HTML fragment of this template with the specified values applied.
  59. * @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'})
  60. * @return {String} The HTML fragment
  61. * @hide repeat doc
  62. */
  63. applyTemplate : function(values){
  64. var me = this,
  65. useF = me.disableFormats !== true,
  66. fm = Ext.util.Format,
  67. tpl = me;
  68. if(me.compiled){
  69. return me.compiled(values);
  70. }
  71. function fn(m, name, format, args){
  72. if (format &amp;&amp; useF) {
  73. if (format.substr(0, 5) == &quot;this.&quot;) {
  74. return tpl.call(format.substr(5), values[name], values);
  75. } else {
  76. if (args) {
  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
  80. var re = me.argsRe;
  81. args = args.split(',');
  82. for(var i = 0, len = args.length; i &lt; len; i++){
  83. args[i] = args[i].replace(re, &quot;$1&quot;);
  84. }
  85. args = [values[name]].concat(args);
  86. } else {
  87. args = [values[name]];
  88. }
  89. return fm[format].apply(fm, args);
  90. }
  91. } else {
  92. return values[name] !== undefined ? values[name] : &quot;&quot;;
  93. }
  94. }
  95. return me.html.replace(me.re, fn);
  96. },
  97. <span id='Ext-Template-method-compile'> /**
  98. </span> * Compiles the template into an internal function, eliminating the RegEx overhead.
  99. * @return {Ext.Template} this
  100. * @hide repeat doc
  101. */
  102. compile : function(){
  103. var me = this,
  104. fm = Ext.util.Format,
  105. useF = me.disableFormats !== true,
  106. sep = Ext.isGecko ? &quot;+&quot; : &quot;,&quot;,
  107. body;
  108. function fn(m, name, format, args){
  109. if(format &amp;&amp; useF){
  110. args = args ? ',' + args : &quot;&quot;;
  111. if(format.substr(0, 5) != &quot;this.&quot;){
  112. format = &quot;fm.&quot; + format + '(';
  113. }else{
  114. format = 'this.call(&quot;'+ format.substr(5) + '&quot;, ';
  115. args = &quot;, values&quot;;
  116. }
  117. }else{
  118. args= ''; format = &quot;(values['&quot; + name + &quot;'] == undefined ? '' : &quot;;
  119. }
  120. return &quot;'&quot;+ sep + format + &quot;values['&quot; + name + &quot;']&quot; + args + &quot;)&quot;+sep+&quot;'&quot;;
  121. }
  122. // branched to use + in gecko and [].join() in others
  123. if(Ext.isGecko){
  124. body = &quot;this.compiled = function(values){ return '&quot; +
  125. me.html.replace(me.compileARe, '\\\\').replace(me.compileBRe, '\\n').replace(me.compileCRe, &quot;\\'&quot;).replace(me.re, fn) +
  126. &quot;';};&quot;;
  127. }else{
  128. body = [&quot;this.compiled = function(values){ return ['&quot;];
  129. body.push(me.html.replace(me.compileARe, '\\\\').replace(me.compileBRe, '\\n').replace(me.compileCRe, &quot;\\'&quot;).replace(me.re, fn));
  130. body.push(&quot;'].join('');};&quot;);
  131. body = body.join('');
  132. }
  133. eval(body);
  134. return me;
  135. },
  136. // private function used to call members
  137. call : function(fnName, value, allValues){
  138. return this[fnName](value, allValues);
  139. }
  140. });
  141. Ext.Template.prototype.apply = Ext.Template.prototype.applyTemplate;
  142. </pre>
  143. </body>
  144. </html>