Web Interface For Lite Argus Control modules
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.

256 lines
10 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <html>
  2. <head>
  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>
  7. </head>
  8. <body onload="prettyPrint();">
  9. <pre class="prettyprint lang-js">/*!
  10. * Ext JS Library 3.3.1
  11. * Copyright(c) 2006-2010 Sencha Inc.
  12. * licensing@sencha.com
  13. * http://www.sencha.com/license
  14. */
  15. <div id="cls-Ext.Template"></div>/**
  16. * @class Ext.Template
  17. * <p>Represents an HTML fragment template. Templates may be {@link #compile precompiled}
  18. * for greater performance.</p>
  19. * <p>For example usage {@link #Template see the constructor}.</p>
  20. *
  21. * @constructor
  22. * An instance of this class may be created by passing to the constructor either
  23. * a single argument, or multiple arguments:
  24. * <div class="mdetail-params"><ul>
  25. * <li><b>single argument</b> : String/Array
  26. * <div class="sub-desc">
  27. * The single argument may be either a String or an Array:<ul>
  28. * <li><tt>String</tt> : </li><pre><code>
  29. var t = new Ext.Template("&lt;div>Hello {0}.&lt;/div>");
  30. t.{@link #append}('some-element', ['foo']);
  31. * </code></pre>
  32. * <li><tt>Array</tt> : </li>
  33. * An Array will be combined with <code>join('')</code>.
  34. <pre><code>
  35. var t = new Ext.Template([
  36. '&lt;div name="{id}"&gt;',
  37. '&lt;span class="{cls}"&gt;{name:trim} {value:ellipsis(10)}&lt;/span&gt;',
  38. '&lt;/div&gt;',
  39. ]);
  40. t.{@link #compile}();
  41. t.{@link #append}('some-element', {id: 'myid', cls: 'myclass', name: 'foo', value: 'bar'});
  42. </code></pre>
  43. * </ul></div></li>
  44. * <li><b>multiple arguments</b> : String, Object, Array, ...
  45. * <div class="sub-desc">
  46. * Multiple arguments will be combined with <code>join('')</code>.
  47. * <pre><code>
  48. var t = new Ext.Template(
  49. '&lt;div name="{id}"&gt;',
  50. '&lt;span class="{cls}"&gt;{name} {value}&lt;/span&gt;',
  51. '&lt;/div&gt;',
  52. // a configuration object:
  53. {
  54. compiled: true, // {@link #compile} immediately
  55. disableFormats: true // See Notes below.
  56. }
  57. );
  58. * </code></pre>
  59. * <p><b>Notes</b>:</p>
  60. * <div class="mdetail-params"><ul>
  61. * <li>Formatting and <code>disableFormats</code> are not applicable for Ext Core.</li>
  62. * <li>For a list of available format functions, see {@link Ext.util.Format}.</li>
  63. * <li><code>disableFormats</code> reduces <code>{@link #apply}</code> time
  64. * when no formatting is required.</li>
  65. * </ul></div>
  66. * </div></li>
  67. * </ul></div>
  68. * @param {Mixed} config
  69. */
  70. Ext.Template = function(html){
  71. var me = this,
  72. a = arguments,
  73. buf = [],
  74. v;
  75. if (Ext.isArray(html)) {
  76. html = html.join("");
  77. } else if (a.length > 1) {
  78. for(var i = 0, len = a.length; i < len; i++){
  79. v = a[i];
  80. if(typeof v == 'object'){
  81. Ext.apply(me, v);
  82. } else {
  83. buf.push(v);
  84. }
  85. };
  86. html = buf.join('');
  87. }
  88. /**@private*/
  89. me.html = html;
  90. <div id="cfg-Ext.Template-compiled"></div>/**
  91. * @cfg {Boolean} compiled Specify <tt>true</tt> to compile the template
  92. * immediately (see <code>{@link #compile}</code>).
  93. * Defaults to <tt>false</tt>.
  94. */
  95. if (me.compiled) {
  96. me.compile();
  97. }
  98. };
  99. Ext.Template.prototype = {
  100. <div id="cfg-Ext.Template-re"></div>/**
  101. * @cfg {RegExp} re The regular expression used to match template variables.
  102. * Defaults to:<pre><code>
  103. * re : /\{([\w-]+)\}/g // for Ext Core
  104. * re : /\{([\w-]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g // for Ext JS
  105. * </code></pre>
  106. */
  107. re : /\{([\w-]+)\}/g,
  108. <div id="prop-Ext.Template-re"></div>/**
  109. * See <code>{@link #re}</code>.
  110. * @type RegExp
  111. * @property re
  112. */
  113. <div id="method-Ext.Template-applyTemplate"></div>/**
  114. * Returns an HTML fragment of this template with the specified <code>values</code> applied.
  115. * @param {Object/Array} values
  116. * The template values. Can be an array if the params are numeric (i.e. <code>{0}</code>)
  117. * or an object (i.e. <code>{foo: 'bar'}</code>).
  118. * @return {String} The HTML fragment
  119. */
  120. applyTemplate : function(values){
  121. var me = this;
  122. return me.compiled ?
  123. me.compiled(values) :
  124. me.html.replace(me.re, function(m, name){
  125. return values[name] !== undefined ? values[name] : "";
  126. });
  127. },
  128. <div id="method-Ext.Template-set"></div>/**
  129. * Sets the HTML used as the template and optionally compiles it.
  130. * @param {String} html
  131. * @param {Boolean} compile (optional) True to compile the template (defaults to undefined)
  132. * @return {Ext.Template} this
  133. */
  134. set : function(html, compile){
  135. var me = this;
  136. me.html = html;
  137. me.compiled = null;
  138. return compile ? me.compile() : me;
  139. },
  140. <div id="method-Ext.Template-compile"></div>/**
  141. * Compiles the template into an internal function, eliminating the RegEx overhead.
  142. * @return {Ext.Template} this
  143. */
  144. compile : function(){
  145. var me = this,
  146. sep = Ext.isGecko ? "+" : ",";
  147. function fn(m, name){
  148. name = "values['" + name + "']";
  149. return "'"+ sep + '(' + name + " == undefined ? '' : " + name + ')' + sep + "'";
  150. }
  151. eval("this.compiled = function(values){ return " + (Ext.isGecko ? "'" : "['") +
  152. me.html.replace(/\\/g, '\\\\').replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn) +
  153. (Ext.isGecko ? "';};" : "'].join('');};"));
  154. return me;
  155. },
  156. <div id="method-Ext.Template-insertFirst"></div>/**
  157. * Applies the supplied values to the template and inserts the new node(s) as the first child of el.
  158. * @param {Mixed} el The context element
  159. * @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'})
  160. * @param {Boolean} returnElement (optional) true to return a Ext.Element (defaults to undefined)
  161. * @return {HTMLElement/Ext.Element} The new node or Element
  162. */
  163. insertFirst: function(el, values, returnElement){
  164. return this.doInsert('afterBegin', el, values, returnElement);
  165. },
  166. <div id="method-Ext.Template-insertBefore"></div>/**
  167. * Applies the supplied values to the template and inserts the new node(s) before el.
  168. * @param {Mixed} el The context element
  169. * @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'})
  170. * @param {Boolean} returnElement (optional) true to return a Ext.Element (defaults to undefined)
  171. * @return {HTMLElement/Ext.Element} The new node or Element
  172. */
  173. insertBefore: function(el, values, returnElement){
  174. return this.doInsert('beforeBegin', el, values, returnElement);
  175. },
  176. <div id="method-Ext.Template-insertAfter"></div>/**
  177. * Applies the supplied values to the template and inserts the new node(s) after el.
  178. * @param {Mixed} el The context element
  179. * @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'})
  180. * @param {Boolean} returnElement (optional) true to return a Ext.Element (defaults to undefined)
  181. * @return {HTMLElement/Ext.Element} The new node or Element
  182. */
  183. insertAfter : function(el, values, returnElement){
  184. return this.doInsert('afterEnd', el, values, returnElement);
  185. },
  186. <div id="method-Ext.Template-append"></div>/**
  187. * Applies the supplied <code>values</code> to the template and appends
  188. * the new node(s) to the specified <code>el</code>.
  189. * <p>For example usage {@link #Template see the constructor}.</p>
  190. * @param {Mixed} el The context element
  191. * @param {Object/Array} values
  192. * The template values. Can be an array if the params are numeric (i.e. <code>{0}</code>)
  193. * or an object (i.e. <code>{foo: 'bar'}</code>).
  194. * @param {Boolean} returnElement (optional) true to return an Ext.Element (defaults to undefined)
  195. * @return {HTMLElement/Ext.Element} The new node or Element
  196. */
  197. append : function(el, values, returnElement){
  198. return this.doInsert('beforeEnd', el, values, returnElement);
  199. },
  200. doInsert : function(where, el, values, returnEl){
  201. el = Ext.getDom(el);
  202. var newNode = Ext.DomHelper.insertHtml(where, el, this.applyTemplate(values));
  203. return returnEl ? Ext.get(newNode, true) : newNode;
  204. },
  205. <div id="method-Ext.Template-overwrite"></div>/**
  206. * Applies the supplied values to the template and overwrites the content of el with the new node(s).
  207. * @param {Mixed} el The context element
  208. * @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'})
  209. * @param {Boolean} returnElement (optional) true to return a Ext.Element (defaults to undefined)
  210. * @return {HTMLElement/Ext.Element} The new node or Element
  211. */
  212. overwrite : function(el, values, returnElement){
  213. el = Ext.getDom(el);
  214. el.innerHTML = this.applyTemplate(values);
  215. return returnElement ? Ext.get(el.firstChild, true) : el.firstChild;
  216. }
  217. };
  218. <div id="method-Ext.Template-apply"></div>/**
  219. * Alias for {@link #applyTemplate}
  220. * Returns an HTML fragment of this template with the specified <code>values</code> applied.
  221. * @param {Object/Array} values
  222. * The template values. Can be an array if the params are numeric (i.e. <code>{0}</code>)
  223. * or an object (i.e. <code>{foo: 'bar'}</code>).
  224. * @return {String} The HTML fragment
  225. * @member Ext.Template
  226. * @method apply
  227. */
  228. Ext.Template.prototype.apply = Ext.Template.prototype.applyTemplate;
  229. <div id="method-Ext.Template-Template.from"></div>/**
  230. * Creates a template from the passed element's value (<i>display:none</i> textarea, preferred) or innerHTML.
  231. * @param {String/HTMLElement} el A DOM element or its id
  232. * @param {Object} config A configuration object
  233. * @return {Ext.Template} The created template
  234. * @static
  235. */
  236. Ext.Template.from = function(el, config){
  237. el = Ext.getDom(el);
  238. return new Ext.Template(el.value || el.innerHTML, config || '');
  239. };
  240. </pre>
  241. </body>
  242. </html>