AbstractElement.html 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  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-dom-AbstractElement'>/**
  19. </span> * @class Ext.dom.AbstractElement
  20. * @extend Ext.Base
  21. * @private
  22. */
  23. (function() {
  24. var document = window.document,
  25. trimRe = /^\s+|\s+$/g,
  26. whitespaceRe = /\s/;
  27. if (!Ext.cache){
  28. Ext.cache = {};
  29. }
  30. Ext.define('Ext.dom.AbstractElement', {
  31. inheritableStatics: {
  32. <span id='Ext-dom-AbstractElement-static-method-get'> /**
  33. </span> * Retrieves Ext.dom.Element objects. {@link Ext#get} is alias for {@link Ext.dom.Element#get}.
  34. *
  35. * **This method does not retrieve {@link Ext.Component Component}s.** This method retrieves Ext.dom.Element
  36. * objects which encapsulate DOM elements. To retrieve a Component by its ID, use {@link Ext.ComponentManager#get}.
  37. *
  38. * Uses simple caching to consistently return the same object. Automatically fixes if an object was recreated with
  39. * the same id via AJAX or DOM.
  40. *
  41. * @param {String/HTMLElement/Ext.Element} el The id of the node, a DOM Node or an existing Element.
  42. * @return {Ext.dom.Element} The Element object (or null if no matching element was found)
  43. * @static
  44. * @inheritable
  45. */
  46. get: function(el) {
  47. var me = this,
  48. El = Ext.dom.Element,
  49. cacheItem,
  50. extEl,
  51. dom,
  52. id;
  53. if (!el) {
  54. return null;
  55. }
  56. if (typeof el == &quot;string&quot;) { // element id
  57. if (el == Ext.windowId) {
  58. return El.get(window);
  59. } else if (el == Ext.documentId) {
  60. return El.get(document);
  61. }
  62. cacheItem = Ext.cache[el];
  63. // This code is here to catch the case where we've got a reference to a document of an iframe
  64. // It getElementById will fail because it's not part of the document, so if we're skipping
  65. // GC it means it's a window/document object that isn't the default window/document, which we have
  66. // already handled above
  67. if (cacheItem &amp;&amp; cacheItem.skipGarbageCollection) {
  68. extEl = cacheItem.el;
  69. return extEl;
  70. }
  71. if (!(dom = document.getElementById(el))) {
  72. return null;
  73. }
  74. if (cacheItem &amp;&amp; cacheItem.el) {
  75. extEl = Ext.updateCacheEntry(cacheItem, dom).el;
  76. } else {
  77. // Force new element if there's a cache but no el attached
  78. extEl = new El(dom, !!cacheItem);
  79. }
  80. return extEl;
  81. } else if (el.tagName) { // dom element
  82. if (!(id = el.id)) {
  83. id = Ext.id(el);
  84. }
  85. cacheItem = Ext.cache[id];
  86. if (cacheItem &amp;&amp; cacheItem.el) {
  87. extEl = Ext.updateCacheEntry(cacheItem, el).el;
  88. } else {
  89. // Force new element if there's a cache but no el attached
  90. extEl = new El(el, !!cacheItem);
  91. }
  92. return extEl;
  93. } else if (el instanceof me) {
  94. if (el != me.docEl &amp;&amp; el != me.winEl) {
  95. id = el.id;
  96. // refresh dom element in case no longer valid,
  97. // catch case where it hasn't been appended
  98. cacheItem = Ext.cache[id];
  99. if (cacheItem) {
  100. Ext.updateCacheEntry(cacheItem, document.getElementById(id) || el.dom);
  101. }
  102. }
  103. return el;
  104. } else if (el.isComposite) {
  105. return el;
  106. } else if (Ext.isArray(el)) {
  107. return me.select(el);
  108. } else if (el === document) {
  109. // create a bogus element object representing the document object
  110. if (!me.docEl) {
  111. me.docEl = Ext.Object.chain(El.prototype);
  112. me.docEl.dom = document;
  113. me.docEl.id = Ext.id(document);
  114. me.addToCache(me.docEl);
  115. }
  116. return me.docEl;
  117. } else if (el === window) {
  118. if (!me.winEl) {
  119. me.winEl = Ext.Object.chain(El.prototype);
  120. me.winEl.dom = window;
  121. me.winEl.id = Ext.id(window);
  122. me.addToCache(me.winEl);
  123. }
  124. return me.winEl;
  125. }
  126. return null;
  127. },
  128. addToCache: function(el, id) {
  129. if (el) {
  130. Ext.addCacheEntry(id, el);
  131. }
  132. return el;
  133. },
  134. addMethods: function() {
  135. this.override.apply(this, arguments);
  136. },
  137. <span id='Ext-dom-AbstractElement-static-method-mergeClsList'> /**
  138. </span> * &lt;p&gt;Returns an array of unique class names based upon the input strings, or string arrays.&lt;/p&gt;
  139. * &lt;p&gt;The number of parameters is unlimited.&lt;/p&gt;
  140. * &lt;p&gt;Example&lt;/p&gt;&lt;code&gt;&lt;pre&gt;
  141. // Add x-invalid and x-mandatory classes, do not duplicate
  142. myElement.dom.className = Ext.core.Element.mergeClsList(this.initialClasses, 'x-invalid x-mandatory');
  143. &lt;/pre&gt;&lt;/code&gt;
  144. * @param {Mixed} clsList1 A string of class names, or an array of class names.
  145. * @param {Mixed} clsList2 A string of class names, or an array of class names.
  146. * @return {Array} An array of strings representing remaining unique, merged class names. If class names were added to the first list, the &lt;code&gt;changed&lt;/code&gt; property will be &lt;code&gt;true&lt;/code&gt;.
  147. * @static
  148. * @inheritable
  149. */
  150. mergeClsList: function() {
  151. var clsList, clsHash = {},
  152. i, length, j, listLength, clsName, result = [],
  153. changed = false;
  154. for (i = 0, length = arguments.length; i &lt; length; i++) {
  155. clsList = arguments[i];
  156. if (Ext.isString(clsList)) {
  157. clsList = clsList.replace(trimRe, '').split(whitespaceRe);
  158. }
  159. if (clsList) {
  160. for (j = 0, listLength = clsList.length; j &lt; listLength; j++) {
  161. clsName = clsList[j];
  162. if (!clsHash[clsName]) {
  163. if (i) {
  164. changed = true;
  165. }
  166. clsHash[clsName] = true;
  167. }
  168. }
  169. }
  170. }
  171. for (clsName in clsHash) {
  172. result.push(clsName);
  173. }
  174. result.changed = changed;
  175. return result;
  176. },
  177. <span id='Ext-dom-AbstractElement-static-method-removeCls'> /**
  178. </span> * &lt;p&gt;Returns an array of unique class names deom the first parameter with all class names
  179. * from the second parameter removed.&lt;/p&gt;
  180. * &lt;p&gt;Example&lt;/p&gt;&lt;code&gt;&lt;pre&gt;
  181. // Remove x-invalid and x-mandatory classes if present.
  182. myElement.dom.className = Ext.core.Element.removeCls(this.initialClasses, 'x-invalid x-mandatory');
  183. &lt;/pre&gt;&lt;/code&gt;
  184. * @param {Mixed} existingClsList A string of class names, or an array of class names.
  185. * @param {Mixed} removeClsList A string of class names, or an array of class names to remove from &lt;code&gt;existingClsList&lt;/code&gt;.
  186. * @return {Array} An array of strings representing remaining class names. If class names were removed, the &lt;code&gt;changed&lt;/code&gt; property will be &lt;code&gt;true&lt;/code&gt;.
  187. * @static
  188. * @inheritable
  189. */
  190. removeCls: function(existingClsList, removeClsList) {
  191. var clsHash = {},
  192. i, length, clsName, result = [],
  193. changed = false;
  194. if (existingClsList) {
  195. if (Ext.isString(existingClsList)) {
  196. existingClsList = existingClsList.replace(trimRe, '').split(whitespaceRe);
  197. }
  198. for (i = 0, length = existingClsList.length; i &lt; length; i++) {
  199. clsHash[existingClsList[i]] = true;
  200. }
  201. }
  202. if (removeClsList) {
  203. if (Ext.isString(removeClsList)) {
  204. removeClsList = removeClsList.split(whitespaceRe);
  205. }
  206. for (i = 0, length = removeClsList.length; i &lt; length; i++) {
  207. clsName = removeClsList[i];
  208. if (clsHash[clsName]) {
  209. changed = true;
  210. delete clsHash[clsName];
  211. }
  212. }
  213. }
  214. for (clsName in clsHash) {
  215. result.push(clsName);
  216. }
  217. result.changed = changed;
  218. return result;
  219. },
  220. <span id='Ext-dom-AbstractElement-static-property-VISIBILITY'> /**
  221. </span> * @property
  222. * Visibility mode constant for use with {@link Ext.dom.Element#setVisibilityMode}.
  223. * Use the CSS 'visibility' property to hide the element.
  224. *
  225. * Note that in this mode, {@link Ext.dom.Element#isVisible isVisible} may return true
  226. * for an element even though it actually has a parent element that is hidden. For this
  227. * reason, and in most cases, using the {@link #OFFSETS} mode is a better choice.
  228. * @static
  229. * @inheritable
  230. */
  231. VISIBILITY: 1,
  232. <span id='Ext-dom-AbstractElement-static-property-DISPLAY'> /**
  233. </span> * @property
  234. * Visibility mode constant for use with {@link Ext.dom.Element#setVisibilityMode}.
  235. * Use the CSS 'display' property to hide the element.
  236. * @static
  237. * @inheritable
  238. */
  239. DISPLAY: 2,
  240. <span id='Ext-dom-AbstractElement-static-property-OFFSETS'> /**
  241. </span> * @property
  242. * Visibility mode constant for use with {@link Ext.dom.Element#setVisibilityMode}.
  243. * Use CSS absolute positioning and top/left offsets to hide the element.
  244. * @static
  245. * @inheritable
  246. */
  247. OFFSETS: 3,
  248. <span id='Ext-dom-AbstractElement-static-property-ASCLASS'> /**
  249. </span> * @property
  250. * Visibility mode constant for use with {@link Ext.dom.Element#setVisibilityMode}.
  251. * Add or remove the {@link Ext.Layer#visibilityCls} class to hide the element.
  252. * @static
  253. * @inheritable
  254. */
  255. ASCLASS: 4
  256. },
  257. constructor: function(element, forceNew) {
  258. var me = this,
  259. dom = typeof element == 'string'
  260. ? document.getElementById(element)
  261. : element,
  262. id;
  263. if (!dom) {
  264. return null;
  265. }
  266. id = dom.id;
  267. if (!forceNew &amp;&amp; id &amp;&amp; Ext.cache[id]) {
  268. // element object already exists
  269. return Ext.cache[id].el;
  270. }
  271. <span id='Ext-dom-AbstractElement-property-dom'> /**
  272. </span> * @property {HTMLElement} dom
  273. * The DOM element
  274. */
  275. me.dom = dom;
  276. <span id='Ext-dom-AbstractElement-property-id'> /**
  277. </span> * @property {String} id
  278. * The DOM element ID
  279. */
  280. me.id = id || Ext.id(dom);
  281. me.self.addToCache(me);
  282. },
  283. <span id='Ext-dom-AbstractElement-method-set'> /**
  284. </span> * Sets the passed attributes as attributes of this element (a style attribute can be a string, object or function)
  285. * @param {Object} o The object with the attributes
  286. * @param {Boolean} [useSet=true] false to override the default setAttribute to use expandos.
  287. * @return {Ext.dom.Element} this
  288. */
  289. set: function(o, useSet) {
  290. var el = this.dom,
  291. attr,
  292. value;
  293. for (attr in o) {
  294. if (o.hasOwnProperty(attr)) {
  295. value = o[attr];
  296. if (attr == 'style') {
  297. this.applyStyles(value);
  298. }
  299. else if (attr == 'cls') {
  300. el.className = value;
  301. }
  302. else if (useSet !== false) {
  303. if (value === undefined) {
  304. el.removeAttribute(attr);
  305. } else {
  306. el.setAttribute(attr, value);
  307. }
  308. }
  309. else {
  310. el[attr] = value;
  311. }
  312. }
  313. }
  314. return this;
  315. },
  316. <span id='Ext-dom-AbstractElement-property-defaultUnit'> /**
  317. </span> * @property {String} defaultUnit
  318. * The default unit to append to CSS values where a unit isn't provided.
  319. */
  320. defaultUnit: &quot;px&quot;,
  321. <span id='Ext-dom-AbstractElement-method-is'> /**
  322. </span> * Returns true if this element matches the passed simple selector (e.g. div.some-class or span:first-child)
  323. * @param {String} selector The simple selector to test
  324. * @return {Boolean} True if this element matches the selector, else false
  325. */
  326. is: function(simpleSelector) {
  327. return Ext.DomQuery.is(this.dom, simpleSelector);
  328. },
  329. <span id='Ext-dom-AbstractElement-method-getValue'> /**
  330. </span> * Returns the value of the &quot;value&quot; attribute
  331. * @param {Boolean} asNumber true to parse the value as a number
  332. * @return {String/Number}
  333. */
  334. getValue: function(asNumber) {
  335. var val = this.dom.value;
  336. return asNumber ? parseInt(val, 10) : val;
  337. },
  338. <span id='Ext-dom-AbstractElement-method-remove'> /**
  339. </span> * Removes this element's dom reference. Note that event and cache removal is handled at {@link Ext#removeNode
  340. * Ext.removeNode}
  341. */
  342. remove: function() {
  343. var me = this,
  344. dom = me.dom;
  345. if (dom) {
  346. Ext.removeNode(dom);
  347. delete me.dom;
  348. }
  349. },
  350. <span id='Ext-dom-AbstractElement-method-contains'> /**
  351. </span> * Returns true if this element is an ancestor of the passed element
  352. * @param {HTMLElement/String} el The element to check
  353. * @return {Boolean} True if this element is an ancestor of el, else false
  354. */
  355. contains: function(el) {
  356. if (!el) {
  357. return false;
  358. }
  359. var me = this,
  360. dom = el.dom || el;
  361. // we need el-contains-itself logic here because isAncestor does not do that:
  362. return (dom === me.dom) || Ext.dom.AbstractElement.isAncestor(me.dom, dom);
  363. },
  364. <span id='Ext-dom-AbstractElement-method-getAttribute'> /**
  365. </span> * Returns the value of an attribute from the element's underlying DOM node.
  366. * @param {String} name The attribute name
  367. * @param {String} [namespace] The namespace in which to look for the attribute
  368. * @return {String} The attribute value
  369. */
  370. getAttribute: function(name, ns) {
  371. var dom = this.dom;
  372. return dom.getAttributeNS(ns, name) || dom.getAttribute(ns + &quot;:&quot; + name) || dom.getAttribute(name) || dom[name];
  373. },
  374. <span id='Ext-dom-AbstractElement-method-update'> /**
  375. </span> * Update the innerHTML of this element
  376. * @param {String} html The new HTML
  377. * @return {Ext.dom.Element} this
  378. */
  379. update: function(html) {
  380. if (this.dom) {
  381. this.dom.innerHTML = html;
  382. }
  383. return this;
  384. },
  385. <span id='Ext-dom-AbstractElement-method-setHTML'> /**
  386. </span> * Set the innerHTML of this element
  387. * @param {String} html The new HTML
  388. * @return {Ext.Element} this
  389. */
  390. setHTML: function(html) {
  391. if(this.dom) {
  392. this.dom.innerHTML = html;
  393. }
  394. return this;
  395. },
  396. <span id='Ext-dom-AbstractElement-method-getHTML'> /**
  397. </span> * Returns the innerHTML of an Element or an empty string if the element's
  398. * dom no longer exists.
  399. */
  400. getHTML: function() {
  401. return this.dom ? this.dom.innerHTML : '';
  402. },
  403. <span id='Ext-dom-AbstractElement-method-hide'> /**
  404. </span> * Hide this element - Uses display mode to determine whether to use &quot;display&quot; or &quot;visibility&quot;. See {@link #setVisible}.
  405. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  406. * @return {Ext.Element} this
  407. */
  408. hide: function() {
  409. this.setVisible(false);
  410. return this;
  411. },
  412. <span id='Ext-dom-AbstractElement-method-show'> /**
  413. </span> * Show this element - Uses display mode to determine whether to use &quot;display&quot; or &quot;visibility&quot;. See {@link #setVisible}.
  414. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  415. * @return {Ext.Element} this
  416. */
  417. show: function() {
  418. this.setVisible(true);
  419. return this;
  420. },
  421. <span id='Ext-dom-AbstractElement-method-setVisible'> /**
  422. </span> * Sets the visibility of the element (see details). If the visibilityMode is set to Element.DISPLAY, it will use
  423. * the display property to hide the element, otherwise it uses visibility. The default is to hide and show using the visibility property.
  424. * @param {Boolean} visible Whether the element is visible
  425. * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
  426. * @return {Ext.Element} this
  427. */
  428. setVisible: function(visible, animate) {
  429. var me = this,
  430. statics = me.self,
  431. mode = me.getVisibilityMode(),
  432. prefix = Ext.baseCSSPrefix;
  433. switch (mode) {
  434. case statics.VISIBILITY:
  435. me.removeCls([prefix + 'hidden-display', prefix + 'hidden-offsets']);
  436. me[visible ? 'removeCls' : 'addCls'](prefix + 'hidden-visibility');
  437. break;
  438. case statics.DISPLAY:
  439. me.removeCls([prefix + 'hidden-visibility', prefix + 'hidden-offsets']);
  440. me[visible ? 'removeCls' : 'addCls'](prefix + 'hidden-display');
  441. break;
  442. case statics.OFFSETS:
  443. me.removeCls([prefix + 'hidden-visibility', prefix + 'hidden-display']);
  444. me[visible ? 'removeCls' : 'addCls'](prefix + 'hidden-offsets');
  445. break;
  446. }
  447. return me;
  448. },
  449. getVisibilityMode: function() {
  450. // Only flyweights won't have a $cache object, by calling getCache the cache
  451. // will be created for future accesses. As such, we're eliminating the method
  452. // call since it's mostly redundant
  453. var data = (this.$cache || this.getCache()).data,
  454. visMode = data.visibilityMode;
  455. if (visMode === undefined) {
  456. data.visibilityMode = visMode = this.self.DISPLAY;
  457. }
  458. return visMode;
  459. },
  460. <span id='Ext-dom-AbstractElement-method-setVisibilityMode'> /**
  461. </span> * Use this to change the visibility mode between {@link #VISIBILITY}, {@link #DISPLAY}, {@link #OFFSETS} or {@link #ASCLASS}.
  462. */
  463. setVisibilityMode: function(mode) {
  464. (this.$cache || this.getCache()).data.visibilityMode = mode;
  465. return this;
  466. },
  467. getCache: function() {
  468. var me = this,
  469. id = me.dom.id || Ext.id(me.dom);
  470. // Note that we do not assign an ID to the calling object here.
  471. // An Ext.dom.Element will have one assigned at construction, and an Ext.dom.AbstractElement.Fly must not have one.
  472. // We assign an ID to the DOM element if it does not have one.
  473. me.$cache = Ext.cache[id] || Ext.addCacheEntry(id, null, me.dom);
  474. return me.$cache;
  475. }
  476. }, function() {
  477. var AbstractElement = this;
  478. <span id='Ext-method-getDetachedBody'> /**
  479. </span> * @private
  480. * @member Ext
  481. */
  482. Ext.getDetachedBody = function () {
  483. var detachedEl = AbstractElement.detachedBodyEl;
  484. if (!detachedEl) {
  485. detachedEl = document.createElement('div');
  486. AbstractElement.detachedBodyEl = detachedEl = new AbstractElement.Fly(detachedEl);
  487. detachedEl.isDetachedBody = true;
  488. }
  489. return detachedEl;
  490. };
  491. <span id='Ext-method-getElementById'> /**
  492. </span> * @private
  493. * @member Ext
  494. */
  495. Ext.getElementById = function (id) {
  496. var el = document.getElementById(id),
  497. detachedBodyEl;
  498. if (!el &amp;&amp; (detachedBodyEl = AbstractElement.detachedBodyEl)) {
  499. el = detachedBodyEl.dom.querySelector('#' + Ext.escapeId(id));
  500. }
  501. return el;
  502. };
  503. <span id='Ext-method-get'> /**
  504. </span> * @member Ext
  505. * @method get
  506. * @inheritdoc Ext.dom.Element#get
  507. */
  508. Ext.get = function(el) {
  509. return Ext.dom.Element.get(el);
  510. };
  511. this.addStatics({
  512. <span id='Ext-dom-AbstractElement-Fly'> /**
  513. </span> * @class Ext.dom.AbstractElement.Fly
  514. * @extends Ext.dom.AbstractElement
  515. *
  516. * A non-persistent wrapper for a DOM element which may be used to execute methods of {@link Ext.dom.Element}
  517. * upon a DOM element without creating an instance of {@link Ext.dom.Element}.
  518. *
  519. * A **singleton** instance of this class is returned when you use {@link Ext#fly}
  520. *
  521. * Because it is a singleton, this Flyweight does not have an ID, and must be used and discarded in a single line.
  522. * You should not keep and use the reference to this singleton over multiple lines because methods that you call
  523. * may themselves make use of {@link Ext#fly} and may change the DOM element to which the instance refers.
  524. */
  525. Fly: new Ext.Class({
  526. extend: AbstractElement,
  527. <span id='Ext-dom-AbstractElement-Fly-property-isFly'> /**
  528. </span> * @property {Boolean} isFly
  529. * This is `true` to identify Element flyweights
  530. */
  531. isFly: true,
  532. constructor: function(dom) {
  533. this.dom = dom;
  534. },
  535. <span id='Ext-dom-AbstractElement-Fly-method-attach'> /**
  536. </span> * @private
  537. * Attach this fliyweight instance to the passed DOM element.
  538. *
  539. * Note that a flightweight does **not** have an ID, and does not acquire the ID of the DOM element.
  540. */
  541. attach: function (dom) {
  542. // Attach to the passed DOM element. The same code as in Ext.Fly
  543. this.dom = dom;
  544. // Use cached data if there is existing cached data for the referenced DOM element,
  545. // otherwise it will be created when needed by getCache.
  546. this.$cache = dom.id ? Ext.cache[dom.id] : null;
  547. return this;
  548. }
  549. }),
  550. _flyweights: {},
  551. <span id='Ext-dom-AbstractElement-static-method-fly'> /**
  552. </span> * Gets the singleton {@link Ext.dom.AbstractElement.Fly flyweight} element, with the passed node as the active element.
  553. *
  554. * Because it is a singleton, this Flyweight does not have an ID, and must be used and discarded in a single line.
  555. * You may not keep and use the reference to this singleton over multiple lines because methods that you call
  556. * may themselves make use of {@link Ext#fly} and may change the DOM element to which the instance refers.
  557. *
  558. * {@link Ext#fly} is alias for {@link Ext.dom.AbstractElement#fly}.
  559. *
  560. * Use this to make one-time references to DOM elements which are not going to be accessed again either by
  561. * application code, or by Ext's classes. If accessing an element which will be processed regularly, then {@link
  562. * Ext#get Ext.get} will be more appropriate to take advantage of the caching provided by the Ext.dom.Element
  563. * class.
  564. *
  565. * @param {String/HTMLElement} dom The dom node or id
  566. * @param {String} [named] Allows for creation of named reusable flyweights to prevent conflicts (e.g.
  567. * internally Ext uses &quot;_global&quot;)
  568. * @return {Ext.dom.AbstractElement.Fly} The singleton flyweight object (or null if no matching element was found)
  569. * @static
  570. * @member Ext.dom.AbstractElement
  571. */
  572. fly: function(dom, named) {
  573. var fly = null,
  574. _flyweights = AbstractElement._flyweights;
  575. named = named || '_global';
  576. dom = Ext.getDom(dom);
  577. if (dom) {
  578. fly = _flyweights[named] || (_flyweights[named] = new AbstractElement.Fly());
  579. // Attach to the passed DOM element.
  580. // This code performs the same function as Fly.attach, but inline it for efficiency
  581. fly.dom = dom;
  582. // Use cached data if there is existing cached data for the referenced DOM element,
  583. // otherwise it will be created when needed by getCache.
  584. fly.$cache = dom.id ? Ext.cache[dom.id] : null;
  585. }
  586. return fly;
  587. }
  588. });
  589. <span id='Ext-method-fly'> /**
  590. </span> * @member Ext
  591. * @method fly
  592. * @inheritdoc Ext.dom.AbstractElement#fly
  593. */
  594. Ext.fly = function() {
  595. return AbstractElement.fly.apply(AbstractElement, arguments);
  596. };
  597. (function (proto) {
  598. <span id='Ext-dom-AbstractElement-method-destroy'> /**
  599. </span> * @method destroy
  600. * @member Ext.dom.AbstractElement
  601. * @inheritdoc Ext.dom.AbstractElement#remove
  602. * Alias to {@link #remove}.
  603. */
  604. proto.destroy = proto.remove;
  605. <span id='Ext-dom-AbstractElement-method-getById'> /**
  606. </span> * Returns a child element of this element given its `id`.
  607. * @method getById
  608. * @member Ext.dom.AbstractElement
  609. * @param {String} id The id of the desired child element.
  610. * @param {Boolean} [asDom=false] True to return the DOM element, false to return a
  611. * wrapped Element object.
  612. */
  613. if (document.querySelector) {
  614. proto.getById = function (id, asDom) {
  615. // for normal elements getElementById is the best solution, but if the el is
  616. // not part of the document.body, we have to resort to querySelector
  617. var dom = document.getElementById(id) ||
  618. this.dom.querySelector('#'+Ext.escapeId(id));
  619. return asDom ? dom : (dom ? Ext.get(dom) : null);
  620. };
  621. } else {
  622. proto.getById = function (id, asDom) {
  623. var dom = document.getElementById(id);
  624. return asDom ? dom : (dom ? Ext.get(dom) : null);
  625. };
  626. }
  627. }(this.prototype));
  628. });
  629. }());
  630. </pre>
  631. </body>
  632. </html>