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.

332 lines
12 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.CompositeElementLite"></div>/**
  16. * @class Ext.CompositeElementLite
  17. * <p>This class encapsulates a <i>collection</i> of DOM elements, providing methods to filter
  18. * members, or to perform collective actions upon the whole set.</p>
  19. * <p>Although they are not listed, this class supports all of the methods of {@link Ext.Element} and
  20. * {@link Ext.Fx}. The methods from these classes will be performed on all the elements in this collection.</p>
  21. * Example:<pre><code>
  22. var els = Ext.select("#some-el div.some-class");
  23. // or select directly from an existing element
  24. var el = Ext.get('some-el');
  25. el.select('div.some-class');
  26. els.setWidth(100); // all elements become 100 width
  27. els.hide(true); // all elements fade out and hide
  28. // or
  29. els.setWidth(100).hide(true);
  30. </code>
  31. */
  32. Ext.CompositeElementLite = function(els, root){
  33. <div id="prop-Ext.CompositeElementLite-elements"></div>/**
  34. * <p>The Array of DOM elements which this CompositeElement encapsulates. Read-only.</p>
  35. * <p>This will not <i>usually</i> be accessed in developers' code, but developers wishing
  36. * to augment the capabilities of the CompositeElementLite class may use it when adding
  37. * methods to the class.</p>
  38. * <p>For example to add the <code>nextAll</code> method to the class to <b>add</b> all
  39. * following siblings of selected elements, the code would be</p><code><pre>
  40. Ext.override(Ext.CompositeElementLite, {
  41. nextAll: function() {
  42. var els = this.elements, i, l = els.length, n, r = [], ri = -1;
  43. // Loop through all elements in this Composite, accumulating
  44. // an Array of all siblings.
  45. for (i = 0; i < l; i++) {
  46. for (n = els[i].nextSibling; n; n = n.nextSibling) {
  47. r[++ri] = n;
  48. }
  49. }
  50. // Add all found siblings to this Composite
  51. return this.add(r);
  52. }
  53. });</pre></code>
  54. * @type Array
  55. * @property elements
  56. */
  57. this.elements = [];
  58. this.add(els, root);
  59. this.el = new Ext.Element.Flyweight();
  60. };
  61. Ext.CompositeElementLite.prototype = {
  62. isComposite: true,
  63. // private
  64. getElement : function(el){
  65. // Set the shared flyweight dom property to the current element
  66. var e = this.el;
  67. e.dom = el;
  68. e.id = el.id;
  69. return e;
  70. },
  71. // private
  72. transformElement : function(el){
  73. return Ext.getDom(el);
  74. },
  75. <div id="method-Ext.CompositeElementLite-getCount"></div>/**
  76. * Returns the number of elements in this Composite.
  77. * @return Number
  78. */
  79. getCount : function(){
  80. return this.elements.length;
  81. },
  82. <div id="method-Ext.CompositeElementLite-add"></div>/**
  83. * Adds elements to this Composite object.
  84. * @param {Mixed} els Either an Array of DOM elements to add, or another Composite object who's elements should be added.
  85. * @return {CompositeElement} This Composite object.
  86. */
  87. add : function(els, root){
  88. var me = this,
  89. elements = me.elements;
  90. if(!els){
  91. return this;
  92. }
  93. if(typeof els == "string"){
  94. els = Ext.Element.selectorFunction(els, root);
  95. }else if(els.isComposite){
  96. els = els.elements;
  97. }else if(!Ext.isIterable(els)){
  98. els = [els];
  99. }
  100. for(var i = 0, len = els.length; i < len; ++i){
  101. elements.push(me.transformElement(els[i]));
  102. }
  103. return me;
  104. },
  105. invoke : function(fn, args){
  106. var me = this,
  107. els = me.elements,
  108. len = els.length,
  109. e,
  110. i;
  111. for(i = 0; i < len; i++) {
  112. e = els[i];
  113. if(e){
  114. Ext.Element.prototype[fn].apply(me.getElement(e), args);
  115. }
  116. }
  117. return me;
  118. },
  119. <div id="method-Ext.CompositeElementLite-item"></div>/**
  120. * Returns a flyweight Element of the dom element object at the specified index
  121. * @param {Number} index
  122. * @return {Ext.Element}
  123. */
  124. item : function(index){
  125. var me = this,
  126. el = me.elements[index],
  127. out = null;
  128. if(el){
  129. out = me.getElement(el);
  130. }
  131. return out;
  132. },
  133. // fixes scope with flyweight
  134. addListener : function(eventName, handler, scope, opt){
  135. var els = this.elements,
  136. len = els.length,
  137. i, e;
  138. for(i = 0; i<len; i++) {
  139. e = els[i];
  140. if(e) {
  141. Ext.EventManager.on(e, eventName, handler, scope || e, opt);
  142. }
  143. }
  144. return this;
  145. },
  146. <div id="method-Ext.CompositeElementLite-each"></div>/**
  147. * <p>Calls the passed function for each element in this composite.</p>
  148. * @param {Function} fn The function to call. The function is passed the following parameters:<ul>
  149. * <li><b>el</b> : Element<div class="sub-desc">The current Element in the iteration.
  150. * <b>This is the flyweight (shared) Ext.Element instance, so if you require a
  151. * a reference to the dom node, use el.dom.</b></div></li>
  152. * <li><b>c</b> : Composite<div class="sub-desc">This Composite object.</div></li>
  153. * <li><b>idx</b> : Number<div class="sub-desc">The zero-based index in the iteration.</div></li>
  154. * </ul>
  155. * @param {Object} scope (optional) The scope (<i>this</i> reference) in which the function is executed. (defaults to the Element)
  156. * @return {CompositeElement} this
  157. */
  158. each : function(fn, scope){
  159. var me = this,
  160. els = me.elements,
  161. len = els.length,
  162. i, e;
  163. for(i = 0; i<len; i++) {
  164. e = els[i];
  165. if(e){
  166. e = this.getElement(e);
  167. if(fn.call(scope || e, e, me, i) === false){
  168. break;
  169. }
  170. }
  171. }
  172. return me;
  173. },
  174. <div id="method-Ext.CompositeElementLite-fill"></div>/**
  175. * Clears this Composite and adds the elements passed.
  176. * @param {Mixed} els Either an array of DOM elements, or another Composite from which to fill this Composite.
  177. * @return {CompositeElement} this
  178. */
  179. fill : function(els){
  180. var me = this;
  181. me.elements = [];
  182. me.add(els);
  183. return me;
  184. },
  185. <div id="method-Ext.CompositeElementLite-filter"></div>/**
  186. * Filters this composite to only elements that match the passed selector.
  187. * @param {String/Function} selector A string CSS selector or a comparison function.
  188. * The comparison function will be called with the following arguments:<ul>
  189. * <li><code>el</code> : Ext.Element<div class="sub-desc">The current DOM element.</div></li>
  190. * <li><code>index</code> : Number<div class="sub-desc">The current index within the collection.</div></li>
  191. * </ul>
  192. * @return {CompositeElement} this
  193. */
  194. filter : function(selector){
  195. var els = [],
  196. me = this,
  197. fn = Ext.isFunction(selector) ? selector
  198. : function(el){
  199. return el.is(selector);
  200. };
  201. me.each(function(el, self, i) {
  202. if (fn(el, i) !== false) {
  203. els[els.length] = me.transformElement(el);
  204. }
  205. });
  206. me.elements = els;
  207. return me;
  208. },
  209. <div id="method-Ext.CompositeElementLite-indexOf"></div>/**
  210. * Find the index of the passed element within the composite collection.
  211. * @param el {Mixed} The id of an element, or an Ext.Element, or an HtmlElement to find within the composite collection.
  212. * @return Number The index of the passed Ext.Element in the composite collection, or -1 if not found.
  213. */
  214. indexOf : function(el){
  215. return this.elements.indexOf(this.transformElement(el));
  216. },
  217. <div id="method-Ext.CompositeElementLite-replaceElement"></div>/**
  218. * Replaces the specified element with the passed element.
  219. * @param {Mixed} el The id of an element, the Element itself, the index of the element in this composite
  220. * to replace.
  221. * @param {Mixed} replacement The id of an element or the Element itself.
  222. * @param {Boolean} domReplace (Optional) True to remove and replace the element in the document too.
  223. * @return {CompositeElement} this
  224. */
  225. replaceElement : function(el, replacement, domReplace){
  226. var index = !isNaN(el) ? el : this.indexOf(el),
  227. d;
  228. if(index > -1){
  229. replacement = Ext.getDom(replacement);
  230. if(domReplace){
  231. d = this.elements[index];
  232. d.parentNode.insertBefore(replacement, d);
  233. Ext.removeNode(d);
  234. }
  235. this.elements.splice(index, 1, replacement);
  236. }
  237. return this;
  238. },
  239. <div id="method-Ext.CompositeElementLite-clear"></div>/**
  240. * Removes all elements.
  241. */
  242. clear : function(){
  243. this.elements = [];
  244. }
  245. };
  246. Ext.CompositeElementLite.prototype.on = Ext.CompositeElementLite.prototype.addListener;
  247. /**
  248. * @private
  249. * Copies all of the functions from Ext.Element's prototype onto CompositeElementLite's prototype.
  250. * This is called twice - once immediately below, and once again after additional Ext.Element
  251. * are added in Ext JS
  252. */
  253. Ext.CompositeElementLite.importElementMethods = function() {
  254. var fnName,
  255. ElProto = Ext.Element.prototype,
  256. CelProto = Ext.CompositeElementLite.prototype;
  257. for (fnName in ElProto) {
  258. if (typeof ElProto[fnName] == 'function'){
  259. (function(fnName) {
  260. CelProto[fnName] = CelProto[fnName] || function() {
  261. return this.invoke(fnName, arguments);
  262. };
  263. }).call(CelProto, fnName);
  264. }
  265. }
  266. };
  267. Ext.CompositeElementLite.importElementMethods();
  268. if(Ext.DomQuery){
  269. Ext.Element.selectorFunction = Ext.DomQuery.select;
  270. }
  271. <div id="method-Ext.Element-select"></div>/**
  272. * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods
  273. * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
  274. * {@link Ext.CompositeElementLite CompositeElementLite} object.
  275. * @param {String/Array} selector The CSS selector or an array of elements
  276. * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
  277. * @return {CompositeElementLite/CompositeElement}
  278. * @member Ext.Element
  279. * @method select
  280. */
  281. Ext.Element.select = function(selector, root){
  282. var els;
  283. if(typeof selector == "string"){
  284. els = Ext.Element.selectorFunction(selector, root);
  285. }else if(selector.length !== undefined){
  286. els = selector;
  287. }else{
  288. throw "Invalid selector";
  289. }
  290. return new Ext.CompositeElementLite(els);
  291. };
  292. <div id="method-Ext-select"></div>/**
  293. * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods
  294. * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
  295. * {@link Ext.CompositeElementLite CompositeElementLite} object.
  296. * @param {String/Array} selector The CSS selector or an array of elements
  297. * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
  298. * @return {CompositeElementLite/CompositeElement}
  299. * @member Ext
  300. * @method select
  301. */
  302. Ext.select = Ext.Element.select;
  303. </pre>
  304. </body>
  305. </html>