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.

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