Element.html 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502
  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-Element-method-constructor'><span id='Ext-dom-Element'>/**
  19. </span></span> * @class Ext.dom.Element
  20. * @alternateClassName Ext.Element
  21. * @alternateClassName Ext.core.Element
  22. * @extend Ext.dom.AbstractElement
  23. *
  24. * Encapsulates a DOM element, adding simple DOM manipulation facilities, normalizing for browser differences.
  25. *
  26. * All instances of this class inherit the methods of {@link Ext.fx.Anim} making visual effects easily available to all
  27. * DOM elements.
  28. *
  29. * Note that the events documented in this class are not Ext events, they encapsulate browser events. Some older browsers
  30. * may not support the full range of events. Which events are supported is beyond the control of Ext JS.
  31. *
  32. * Usage:
  33. *
  34. * // by id
  35. * var el = Ext.get(&quot;my-div&quot;);
  36. *
  37. * // by DOM element reference
  38. * var el = Ext.get(myDivElement);
  39. *
  40. * # Animations
  41. *
  42. * When an element is manipulated, by default there is no animation.
  43. *
  44. * var el = Ext.get(&quot;my-div&quot;);
  45. *
  46. * // no animation
  47. * el.setWidth(100);
  48. *
  49. * Many of the functions for manipulating an element have an optional &quot;animate&quot; parameter. This parameter can be
  50. * specified as boolean (true) for default animation effects.
  51. *
  52. * // default animation
  53. * el.setWidth(100, true);
  54. *
  55. * To configure the effects, an object literal with animation options to use as the Element animation configuration
  56. * object can also be specified. Note that the supported Element animation configuration options are a subset of the
  57. * {@link Ext.fx.Anim} animation options specific to Fx effects. The supported Element animation configuration options
  58. * are:
  59. *
  60. * Option Default Description
  61. * --------- -------- ---------------------------------------------
  62. * {@link Ext.fx.Anim#duration duration} 350 The duration of the animation in milliseconds
  63. * {@link Ext.fx.Anim#easing easing} easeOut The easing method
  64. * {@link Ext.fx.Anim#callback callback} none A function to execute when the anim completes
  65. * {@link Ext.fx.Anim#scope scope} this The scope (this) of the callback function
  66. *
  67. * Usage:
  68. *
  69. * // Element animation options object
  70. * var opt = {
  71. * {@link Ext.fx.Anim#duration duration}: 1000,
  72. * {@link Ext.fx.Anim#easing easing}: 'elasticIn',
  73. * {@link Ext.fx.Anim#callback callback}: this.foo,
  74. * {@link Ext.fx.Anim#scope scope}: this
  75. * };
  76. * // animation with some options set
  77. * el.setWidth(100, opt);
  78. *
  79. * The Element animation object being used for the animation will be set on the options object as &quot;anim&quot;, which allows
  80. * you to stop or manipulate the animation. Here is an example:
  81. *
  82. * // using the &quot;anim&quot; property to get the Anim object
  83. * if(opt.anim.isAnimated()){
  84. * opt.anim.stop();
  85. * }
  86. *
  87. * # Composite (Collections of) Elements
  88. *
  89. * For working with collections of Elements, see {@link Ext.CompositeElement}
  90. *
  91. * @constructor
  92. * Creates new Element directly.
  93. * @param {String/HTMLElement} element
  94. * @param {Boolean} [forceNew] By default the constructor checks to see if there is already an instance of this
  95. * element in the cache and if there is it returns the same instance. This will skip that check (useful for extending
  96. * this class).
  97. * @return {Object}
  98. */
  99. (function() {
  100. var HIDDEN = 'hidden',
  101. DOC = document,
  102. VISIBILITY = &quot;visibility&quot;,
  103. DISPLAY = &quot;display&quot;,
  104. NONE = &quot;none&quot;,
  105. XMASKED = Ext.baseCSSPrefix + &quot;masked&quot;,
  106. XMASKEDRELATIVE = Ext.baseCSSPrefix + &quot;masked-relative&quot;,
  107. EXTELMASKMSG = Ext.baseCSSPrefix + &quot;mask-msg&quot;,
  108. bodyRe = /^body/i,
  109. visFly,
  110. // speedy lookup for elements never to box adjust
  111. noBoxAdjust = Ext.isStrict ? {
  112. select: 1
  113. }: {
  114. input: 1,
  115. select: 1,
  116. textarea: 1
  117. },
  118. // Pseudo for use by cacheScrollValues
  119. isScrolled = function(c) {
  120. var r = [], ri = -1,
  121. i, ci;
  122. for (i = 0; ci = c[i]; i++) {
  123. if (ci.scrollTop &gt; 0 || ci.scrollLeft &gt; 0) {
  124. r[++ri] = ci;
  125. }
  126. }
  127. return r;
  128. },
  129. Element = Ext.define('Ext.dom.Element', {
  130. extend: 'Ext.dom.AbstractElement',
  131. alternateClassName: ['Ext.Element', 'Ext.core.Element'],
  132. addUnits: function() {
  133. return this.self.addUnits.apply(this.self, arguments);
  134. },
  135. <span id='Ext-dom-Element-method-focus'> /**
  136. </span> * Tries to focus the element. Any exceptions are caught and ignored.
  137. * @param {Number} [defer] Milliseconds to defer the focus
  138. * @return {Ext.dom.Element} this
  139. */
  140. focus: function(defer, /* private */ dom) {
  141. var me = this,
  142. scrollTop,
  143. body;
  144. dom = dom || me.dom;
  145. body = (dom.ownerDocument || DOC).body || DOC.body;
  146. try {
  147. if (Number(defer)) {
  148. Ext.defer(me.focus, defer, me, [null, dom]);
  149. } else {
  150. // Focusing a large element, the browser attempts to scroll as much of it into view
  151. // as possible. We need to override this behaviour.
  152. if (dom.offsetHeight &gt; Element.getViewHeight()) {
  153. scrollTop = body.scrollTop;
  154. }
  155. dom.focus();
  156. if (scrollTop !== undefined) {
  157. body.scrollTop = scrollTop;
  158. }
  159. }
  160. } catch(e) {
  161. }
  162. return me;
  163. },
  164. <span id='Ext-dom-Element-method-blur'> /**
  165. </span> * Tries to blur the element. Any exceptions are caught and ignored.
  166. * @return {Ext.dom.Element} this
  167. */
  168. blur: function() {
  169. try {
  170. this.dom.blur();
  171. } catch(e) {
  172. }
  173. return this;
  174. },
  175. <span id='Ext-dom-Element-method-isBorderBox'> /**
  176. </span> * Tests various css rules/browsers to determine if this element uses a border box
  177. * @return {Boolean}
  178. */
  179. isBorderBox: function() {
  180. var box = Ext.isBorderBox;
  181. if (box) {
  182. box = !((this.dom.tagName || &quot;&quot;).toLowerCase() in noBoxAdjust);
  183. }
  184. return box;
  185. },
  186. <span id='Ext-dom-Element-method-hover'> /**
  187. </span> * Sets up event handlers to call the passed functions when the mouse is moved into and out of the Element.
  188. * @param {Function} overFn The function to call when the mouse enters the Element.
  189. * @param {Function} outFn The function to call when the mouse leaves the Element.
  190. * @param {Object} [scope] The scope (`this` reference) in which the functions are executed. Defaults
  191. * to the Element's DOM element.
  192. * @param {Object} [options] Options for the listener. See {@link Ext.util.Observable#addListener the
  193. * options parameter}.
  194. * @return {Ext.dom.Element} this
  195. */
  196. hover: function(overFn, outFn, scope, options) {
  197. var me = this;
  198. me.on('mouseenter', overFn, scope || me.dom, options);
  199. me.on('mouseleave', outFn, scope || me.dom, options);
  200. return me;
  201. },
  202. <span id='Ext-dom-Element-method-getAttributeNS'> /**
  203. </span> * Returns the value of a namespaced attribute from the element's underlying DOM node.
  204. * @param {String} namespace The namespace in which to look for the attribute
  205. * @param {String} name The attribute name
  206. * @return {String} The attribute value
  207. */
  208. getAttributeNS: function(ns, name) {
  209. return this.getAttribute(name, ns);
  210. },
  211. getAttribute: (Ext.isIE &amp;&amp; !(Ext.isIE9 &amp;&amp; DOC.documentMode === 9)) ?
  212. function(name, ns) {
  213. var d = this.dom,
  214. type;
  215. if (ns) {
  216. type = typeof d[ns + &quot;:&quot; + name];
  217. if (type != 'undefined' &amp;&amp; type != 'unknown') {
  218. return d[ns + &quot;:&quot; + name] || null;
  219. }
  220. return null;
  221. }
  222. if (name === &quot;for&quot;) {
  223. name = &quot;htmlFor&quot;;
  224. }
  225. return d[name] || null;
  226. } : function(name, ns) {
  227. var d = this.dom;
  228. if (ns) {
  229. return d.getAttributeNS(ns, name) || d.getAttribute(ns + &quot;:&quot; + name);
  230. }
  231. return d.getAttribute(name) || d[name] || null;
  232. },
  233. <span id='Ext-dom-Element-method-cacheScrollValues'> /**
  234. </span> * When an element is moved around in the DOM, or is hidden using `display:none`, it loses layout, and therefore
  235. * all scroll positions of all descendant elements are lost.
  236. *
  237. * This function caches them, and returns a function, which when run will restore the cached positions.
  238. * In the following example, the Panel is moved from one Container to another which will cause it to lose all scroll positions:
  239. *
  240. * var restoreScroll = myPanel.el.cacheScrollValues();
  241. * myOtherContainer.add(myPanel);
  242. * restoreScroll();
  243. *
  244. * @return {Function} A function which will restore all descentant elements of this Element to their scroll
  245. * positions recorded when this function was executed. Be aware that the returned function is a closure which has
  246. * captured the scope of `cacheScrollValues`, so take care to derefence it as soon as not needed - if is it is a `var`
  247. * it will drop out of scope, and the reference will be freed.
  248. */
  249. cacheScrollValues: function() {
  250. var me = this,
  251. scrolledDescendants,
  252. el, i,
  253. scrollValues = [],
  254. result = function() {
  255. for (i = 0; i &lt; scrolledDescendants.length; i++) {
  256. el = scrolledDescendants[i];
  257. el.scrollLeft = scrollValues[i][0];
  258. el.scrollTop = scrollValues[i][1];
  259. }
  260. };
  261. if (!Ext.DomQuery.pseudos.isScrolled) {
  262. Ext.DomQuery.pseudos.isScrolled = isScrolled;
  263. }
  264. scrolledDescendants = me.query(':isScrolled');
  265. for (i = 0; i &lt; scrolledDescendants.length; i++) {
  266. el = scrolledDescendants[i];
  267. scrollValues[i] = [el.scrollLeft, el.scrollTop];
  268. }
  269. return result;
  270. },
  271. <span id='Ext-dom-Element-property-autoBoxAdjust'> /**
  272. </span> * @property {Boolean} autoBoxAdjust
  273. * True to automatically adjust width and height settings for box-model issues.
  274. */
  275. autoBoxAdjust: true,
  276. <span id='Ext-dom-Element-method-isVisible'> /**
  277. </span> * Checks whether the element is currently visible using both visibility and display properties.
  278. * @param {Boolean} [deep=false] True to walk the dom and see if parent elements are hidden.
  279. * If false, the function only checks the visibility of the element itself and it may return
  280. * `true` even though a parent is not visible.
  281. * @return {Boolean} `true` if the element is currently visible, else `false`
  282. */
  283. isVisible : function(deep) {
  284. var me = this,
  285. dom = me.dom,
  286. stopNode = dom.ownerDocument.documentElement;
  287. if (!visFly) {
  288. visFly = new Element.Fly();
  289. }
  290. while (dom !== stopNode) {
  291. // We're invisible if we hit a nonexistent parentNode or a document
  292. // fragment or computed style visibility:hidden or display:none
  293. if (!dom || dom.nodeType === 11 || (visFly.attach(dom)).isStyle(VISIBILITY, HIDDEN) || visFly.isStyle(DISPLAY, NONE)) {
  294. return false;
  295. }
  296. // Quit now unless we are being asked to check parent nodes.
  297. if (!deep) {
  298. break;
  299. }
  300. dom = dom.parentNode;
  301. }
  302. return true;
  303. },
  304. <span id='Ext-dom-Element-method-isDisplayed'> /**
  305. </span> * Returns true if display is not &quot;none&quot;
  306. * @return {Boolean}
  307. */
  308. isDisplayed : function() {
  309. return !this.isStyle(DISPLAY, NONE);
  310. },
  311. <span id='Ext-dom-Element-method-enableDisplayMode'> /**
  312. </span> * Convenience method for setVisibilityMode(Element.DISPLAY)
  313. * @param {String} [display] What to set display to when visible
  314. * @return {Ext.dom.Element} this
  315. */
  316. enableDisplayMode : function(display) {
  317. var me = this;
  318. me.setVisibilityMode(Element.DISPLAY);
  319. if (!Ext.isEmpty(display)) {
  320. (me.$cache || me.getCache()).data.originalDisplay = display;
  321. }
  322. return me;
  323. },
  324. <span id='Ext-dom-Element-method-mask'> /**
  325. </span> * Puts a mask over this element to disable user interaction. Requires core.css.
  326. * This method can only be applied to elements which accept child nodes.
  327. * @param {String} [msg] A message to display in the mask
  328. * @param {String} [msgCls] A css class to apply to the msg element
  329. * @return {Ext.dom.Element} The mask element
  330. */
  331. mask : function(msg, msgCls /* private - passed by AbstractComponent.mask to avoid the need to interrogate the DOM to get the height*/, elHeight) {
  332. var me = this,
  333. dom = me.dom,
  334. // In some cases, setExpression will exist but not be of a function type,
  335. // so we check it explicitly here to stop IE throwing errors
  336. setExpression = dom.style.setExpression,
  337. data = (me.$cache || me.getCache()).data,
  338. maskEl = data.maskEl,
  339. maskMsg = data.maskMsg;
  340. if (!(bodyRe.test(dom.tagName) &amp;&amp; me.getStyle('position') == 'static')) {
  341. me.addCls(XMASKEDRELATIVE);
  342. }
  343. // We always needs to recreate the mask since the DOM element may have been re-created
  344. if (maskEl) {
  345. maskEl.remove();
  346. }
  347. if (maskMsg) {
  348. maskMsg.remove();
  349. }
  350. Ext.DomHelper.append(dom, [{
  351. cls : Ext.baseCSSPrefix + &quot;mask&quot;
  352. }, {
  353. cls : msgCls ? EXTELMASKMSG + &quot; &quot; + msgCls : EXTELMASKMSG,
  354. cn : {
  355. tag: 'div',
  356. html: msg || ''
  357. }
  358. }]);
  359. maskMsg = Ext.get(dom.lastChild);
  360. maskEl = Ext.get(maskMsg.dom.previousSibling);
  361. data.maskMsg = maskMsg;
  362. data.maskEl = maskEl;
  363. me.addCls(XMASKED);
  364. maskEl.setDisplayed(true);
  365. if (typeof msg == 'string') {
  366. maskMsg.setDisplayed(true);
  367. maskMsg.center(me);
  368. } else {
  369. maskMsg.setDisplayed(false);
  370. }
  371. // NOTE: CSS expressions are resource intensive and to be used only as a last resort
  372. // These expressions are removed as soon as they are no longer necessary - in the unmask method.
  373. // In normal use cases an element will be masked for a limited period of time.
  374. // Fix for https://sencha.jira.com/browse/EXTJSIV-19.
  375. // IE6 strict mode and IE6-9 quirks mode takes off left+right padding when calculating width!
  376. if (!Ext.supports.IncludePaddingInWidthCalculation &amp;&amp; setExpression) {
  377. // In an occasional case setExpression will throw an exception
  378. try {
  379. maskEl.dom.style.setExpression('width', 'this.parentNode.clientWidth + &quot;px&quot;');
  380. } catch (e) {}
  381. }
  382. // Some versions and modes of IE subtract top+bottom padding when calculating height.
  383. // Different versions from those which make the same error for width!
  384. if (!Ext.supports.IncludePaddingInHeightCalculation &amp;&amp; setExpression) {
  385. // In an occasional case setExpression will throw an exception
  386. try {
  387. maskEl.dom.style.setExpression('height', 'this.parentNode.' + (dom == DOC.body ? 'scrollHeight' : 'offsetHeight') + ' + &quot;px&quot;');
  388. } catch (e) {}
  389. }
  390. // ie will not expand full height automatically
  391. else if (Ext.isIE &amp;&amp; !(Ext.isIE7 &amp;&amp; Ext.isStrict) &amp;&amp; me.getStyle('height') == 'auto') {
  392. maskEl.setSize(undefined, elHeight || me.getHeight());
  393. }
  394. return maskEl;
  395. },
  396. <span id='Ext-dom-Element-method-unmask'> /**
  397. </span> * Hides a previously applied mask.
  398. */
  399. unmask : function() {
  400. var me = this,
  401. data = (me.$cache || me.getCache()).data,
  402. maskEl = data.maskEl,
  403. maskMsg = data.maskMsg,
  404. style;
  405. if (maskEl) {
  406. style = maskEl.dom.style;
  407. // Remove resource-intensive CSS expressions as soon as they are not required.
  408. if (style.clearExpression) {
  409. style.clearExpression('width');
  410. style.clearExpression('height');
  411. }
  412. if (maskEl) {
  413. maskEl.remove();
  414. delete data.maskEl;
  415. }
  416. if (maskMsg) {
  417. maskMsg.remove();
  418. delete data.maskMsg;
  419. }
  420. me.removeCls([XMASKED, XMASKEDRELATIVE]);
  421. }
  422. },
  423. <span id='Ext-dom-Element-method-isMasked'> /**
  424. </span> * Returns true if this element is masked. Also re-centers any displayed message within the mask.
  425. * @return {Boolean}
  426. */
  427. isMasked : function() {
  428. var me = this,
  429. data = (me.$cache || me.getCache()).data,
  430. maskEl = data.maskEl,
  431. maskMsg = data.maskMsg,
  432. hasMask = false;
  433. if (maskEl &amp;&amp; maskEl.isVisible()) {
  434. if (maskMsg) {
  435. maskMsg.center(me);
  436. }
  437. hasMask = true;
  438. }
  439. return hasMask;
  440. },
  441. <span id='Ext-dom-Element-method-createShim'> /**
  442. </span> * Creates an iframe shim for this element to keep selects and other windowed objects from
  443. * showing through.
  444. * @return {Ext.dom.Element} The new shim element
  445. */
  446. createShim : function() {
  447. var el = DOC.createElement('iframe'),
  448. shim;
  449. el.frameBorder = '0';
  450. el.className = Ext.baseCSSPrefix + 'shim';
  451. el.src = Ext.SSL_SECURE_URL;
  452. shim = Ext.get(this.dom.parentNode.insertBefore(el, this.dom));
  453. shim.autoBoxAdjust = false;
  454. return shim;
  455. },
  456. <span id='Ext-dom-Element-method-addKeyListener'> /**
  457. </span> * Convenience method for constructing a KeyMap
  458. * @param {String/Number/Number[]/Object} key Either a string with the keys to listen for, the numeric key code,
  459. * array of key codes or an object with the following options:
  460. * @param {Number/Array} key.key
  461. * @param {Boolean} key.shift
  462. * @param {Boolean} key.ctrl
  463. * @param {Boolean} key.alt
  464. * @param {Function} fn The function to call
  465. * @param {Object} [scope] The scope (`this` reference) in which the specified function is executed. Defaults to this Element.
  466. * @return {Ext.util.KeyMap} The KeyMap created
  467. */
  468. addKeyListener : function(key, fn, scope){
  469. var config;
  470. if(typeof key != 'object' || Ext.isArray(key)){
  471. config = {
  472. target: this,
  473. key: key,
  474. fn: fn,
  475. scope: scope
  476. };
  477. }else{
  478. config = {
  479. target: this,
  480. key : key.key,
  481. shift : key.shift,
  482. ctrl : key.ctrl,
  483. alt : key.alt,
  484. fn: fn,
  485. scope: scope
  486. };
  487. }
  488. return new Ext.util.KeyMap(config);
  489. },
  490. <span id='Ext-dom-Element-method-addKeyMap'> /**
  491. </span> * Creates a KeyMap for this element
  492. * @param {Object} config The KeyMap config. See {@link Ext.util.KeyMap} for more details
  493. * @return {Ext.util.KeyMap} The KeyMap created
  494. */
  495. addKeyMap : function(config) {
  496. return new Ext.util.KeyMap(Ext.apply({
  497. target: this
  498. }, config));
  499. },
  500. // Mouse events
  501. <span id='Ext-dom-Element-event-click'> /**
  502. </span> * @event click
  503. * Fires when a mouse click is detected within the element.
  504. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  505. * @param {HTMLElement} t The target of the event.
  506. */
  507. <span id='Ext-dom-Element-event-contextmenu'> /**
  508. </span> * @event contextmenu
  509. * Fires when a right click is detected within the element.
  510. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  511. * @param {HTMLElement} t The target of the event.
  512. */
  513. <span id='Ext-dom-Element-event-dblclick'> /**
  514. </span> * @event dblclick
  515. * Fires when a mouse double click is detected within the element.
  516. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  517. * @param {HTMLElement} t The target of the event.
  518. */
  519. <span id='Ext-dom-Element-event-mousedown'> /**
  520. </span> * @event mousedown
  521. * Fires when a mousedown is detected within the element.
  522. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  523. * @param {HTMLElement} t The target of the event.
  524. */
  525. <span id='Ext-dom-Element-event-mouseup'> /**
  526. </span> * @event mouseup
  527. * Fires when a mouseup is detected within the element.
  528. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  529. * @param {HTMLElement} t The target of the event.
  530. */
  531. <span id='Ext-dom-Element-event-mouseover'> /**
  532. </span> * @event mouseover
  533. * Fires when a mouseover is detected within the element.
  534. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  535. * @param {HTMLElement} t The target of the event.
  536. */
  537. <span id='Ext-dom-Element-event-mousemove'> /**
  538. </span> * @event mousemove
  539. * Fires when a mousemove is detected with the element.
  540. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  541. * @param {HTMLElement} t The target of the event.
  542. */
  543. <span id='Ext-dom-Element-event-mouseout'> /**
  544. </span> * @event mouseout
  545. * Fires when a mouseout is detected with the element.
  546. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  547. * @param {HTMLElement} t The target of the event.
  548. */
  549. <span id='Ext-dom-Element-event-mouseenter'> /**
  550. </span> * @event mouseenter
  551. * Fires when the mouse enters the element.
  552. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  553. * @param {HTMLElement} t The target of the event.
  554. */
  555. <span id='Ext-dom-Element-event-mouseleave'> /**
  556. </span> * @event mouseleave
  557. * Fires when the mouse leaves the element.
  558. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  559. * @param {HTMLElement} t The target of the event.
  560. */
  561. // Keyboard events
  562. <span id='Ext-dom-Element-event-keypress'> /**
  563. </span> * @event keypress
  564. * Fires when a keypress is detected within the element.
  565. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  566. * @param {HTMLElement} t The target of the event.
  567. */
  568. <span id='Ext-dom-Element-event-keydown'> /**
  569. </span> * @event keydown
  570. * Fires when a keydown is detected within the element.
  571. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  572. * @param {HTMLElement} t The target of the event.
  573. */
  574. <span id='Ext-dom-Element-event-keyup'> /**
  575. </span> * @event keyup
  576. * Fires when a keyup is detected within the element.
  577. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  578. * @param {HTMLElement} t The target of the event.
  579. */
  580. // HTML frame/object events
  581. <span id='Ext-dom-Element-event-load'> /**
  582. </span> * @event load
  583. * Fires when the user agent finishes loading all content within the element. Only supported by window, frames,
  584. * objects and images.
  585. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  586. * @param {HTMLElement} t The target of the event.
  587. */
  588. <span id='Ext-dom-Element-event-unload'> /**
  589. </span> * @event unload
  590. * Fires when the user agent removes all content from a window or frame. For elements, it fires when the target
  591. * element or any of its content has been removed.
  592. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  593. * @param {HTMLElement} t The target of the event.
  594. */
  595. <span id='Ext-dom-Element-event-abort'> /**
  596. </span> * @event abort
  597. * Fires when an object/image is stopped from loading before completely loaded.
  598. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  599. * @param {HTMLElement} t The target of the event.
  600. */
  601. <span id='Ext-dom-Element-event-error'> /**
  602. </span> * @event error
  603. * Fires when an object/image/frame cannot be loaded properly.
  604. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  605. * @param {HTMLElement} t The target of the event.
  606. */
  607. <span id='Ext-dom-Element-event-resize'> /**
  608. </span> * @event resize
  609. * Fires when a document view is resized.
  610. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  611. * @param {HTMLElement} t The target of the event.
  612. */
  613. <span id='Ext-dom-Element-event-scroll'> /**
  614. </span> * @event scroll
  615. * Fires when a document view is scrolled.
  616. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  617. * @param {HTMLElement} t The target of the event.
  618. */
  619. // Form events
  620. <span id='Ext-dom-Element-event-select'> /**
  621. </span> * @event select
  622. * Fires when a user selects some text in a text field, including input and textarea.
  623. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  624. * @param {HTMLElement} t The target of the event.
  625. */
  626. <span id='Ext-dom-Element-event-change'> /**
  627. </span> * @event change
  628. * Fires when a control loses the input focus and its value has been modified since gaining focus.
  629. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  630. * @param {HTMLElement} t The target of the event.
  631. */
  632. <span id='Ext-dom-Element-event-submit'> /**
  633. </span> * @event submit
  634. * Fires when a form is submitted.
  635. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  636. * @param {HTMLElement} t The target of the event.
  637. */
  638. <span id='Ext-dom-Element-event-reset'> /**
  639. </span> * @event reset
  640. * Fires when a form is reset.
  641. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  642. * @param {HTMLElement} t The target of the event.
  643. */
  644. <span id='Ext-dom-Element-event-focus'> /**
  645. </span> * @event focus
  646. * Fires when an element receives focus either via the pointing device or by tab navigation.
  647. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  648. * @param {HTMLElement} t The target of the event.
  649. */
  650. <span id='Ext-dom-Element-event-blur'> /**
  651. </span> * @event blur
  652. * Fires when an element loses focus either via the pointing device or by tabbing navigation.
  653. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  654. * @param {HTMLElement} t The target of the event.
  655. */
  656. // User Interface events
  657. <span id='Ext-dom-Element-event-DOMFocusIn'> /**
  658. </span> * @event DOMFocusIn
  659. * Where supported. Similar to HTML focus event, but can be applied to any focusable element.
  660. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  661. * @param {HTMLElement} t The target of the event.
  662. */
  663. <span id='Ext-dom-Element-event-DOMFocusOut'> /**
  664. </span> * @event DOMFocusOut
  665. * Where supported. Similar to HTML blur event, but can be applied to any focusable element.
  666. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  667. * @param {HTMLElement} t The target of the event.
  668. */
  669. <span id='Ext-dom-Element-event-DOMActivate'> /**
  670. </span> * @event DOMActivate
  671. * Where supported. Fires when an element is activated, for instance, through a mouse click or a keypress.
  672. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  673. * @param {HTMLElement} t The target of the event.
  674. */
  675. // DOM Mutation events
  676. <span id='Ext-dom-Element-event-DOMSubtreeModified'> /**
  677. </span> * @event DOMSubtreeModified
  678. * Where supported. Fires when the subtree is modified.
  679. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  680. * @param {HTMLElement} t The target of the event.
  681. */
  682. <span id='Ext-dom-Element-event-DOMNodeInserted'> /**
  683. </span> * @event DOMNodeInserted
  684. * Where supported. Fires when a node has been added as a child of another node.
  685. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  686. * @param {HTMLElement} t The target of the event.
  687. */
  688. <span id='Ext-dom-Element-event-DOMNodeRemoved'> /**
  689. </span> * @event DOMNodeRemoved
  690. * Where supported. Fires when a descendant node of the element is removed.
  691. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  692. * @param {HTMLElement} t The target of the event.
  693. */
  694. <span id='Ext-dom-Element-event-DOMNodeRemovedFromDocument'> /**
  695. </span> * @event DOMNodeRemovedFromDocument
  696. * Where supported. Fires when a node is being removed from a document.
  697. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  698. * @param {HTMLElement} t The target of the event.
  699. */
  700. <span id='Ext-dom-Element-event-DOMNodeInsertedIntoDocument'> /**
  701. </span> * @event DOMNodeInsertedIntoDocument
  702. * Where supported. Fires when a node is being inserted into a document.
  703. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  704. * @param {HTMLElement} t The target of the event.
  705. */
  706. <span id='Ext-dom-Element-event-DOMAttrModified'> /**
  707. </span> * @event DOMAttrModified
  708. * Where supported. Fires when an attribute has been modified.
  709. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  710. * @param {HTMLElement} t The target of the event.
  711. */
  712. <span id='Ext-dom-Element-event-DOMCharacterDataModified'> /**
  713. </span> * @event DOMCharacterDataModified
  714. * Where supported. Fires when the character data has been modified.
  715. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  716. * @param {HTMLElement} t The target of the event.
  717. */
  718. <span id='Ext-dom-Element-method-on'> /**
  719. </span> * Appends an event handler to this element.
  720. *
  721. * @param {String} eventName The name of event to handle.
  722. *
  723. * @param {Function} fn The handler function the event invokes. This function is passed the following parameters:
  724. *
  725. * - **evt** : EventObject
  726. *
  727. * The {@link Ext.EventObject EventObject} describing the event.
  728. *
  729. * - **el** : HtmlElement
  730. *
  731. * The DOM element which was the target of the event. Note that this may be filtered by using the delegate option.
  732. *
  733. * - **o** : Object
  734. *
  735. * The options object from the call that setup the listener.
  736. *
  737. * @param {Object} scope (optional) The scope (**this** reference) in which the handler function is executed. **If
  738. * omitted, defaults to this Element.**
  739. *
  740. * @param {Object} options (optional) An object containing handler configuration properties. This may contain any of
  741. * the following properties:
  742. *
  743. * - **scope** Object :
  744. *
  745. * The scope (**this** reference) in which the handler function is executed. **If omitted, defaults to this
  746. * Element.**
  747. *
  748. * - **delegate** String:
  749. *
  750. * A simple selector to filter the target or look for a descendant of the target. See below for additional details.
  751. *
  752. * - **stopEvent** Boolean:
  753. *
  754. * True to stop the event. That is stop propagation, and prevent the default action.
  755. *
  756. * - **preventDefault** Boolean:
  757. *
  758. * True to prevent the default action
  759. *
  760. * - **stopPropagation** Boolean:
  761. *
  762. * True to prevent event propagation
  763. *
  764. * - **normalized** Boolean:
  765. *
  766. * False to pass a browser event to the handler function instead of an Ext.EventObject
  767. *
  768. * - **target** Ext.dom.Element:
  769. *
  770. * Only call the handler if the event was fired on the target Element, _not_ if the event was bubbled up from a
  771. * child node.
  772. *
  773. * - **delay** Number:
  774. *
  775. * The number of milliseconds to delay the invocation of the handler after the event fires.
  776. *
  777. * - **single** Boolean:
  778. *
  779. * True to add a handler to handle just the next firing of the event, and then remove itself.
  780. *
  781. * - **buffer** Number:
  782. *
  783. * Causes the handler to be scheduled to run in an {@link Ext.util.DelayedTask} delayed by the specified number of
  784. * milliseconds. If the event fires again within that time, the original handler is _not_ invoked, but the new
  785. * handler is scheduled in its place.
  786. *
  787. * **Combining Options**
  788. *
  789. * Using the options argument, it is possible to combine different types of listeners:
  790. *
  791. * A delayed, one-time listener that auto stops the event and adds a custom argument (forumId) to the options
  792. * object. The options object is available as the third parameter in the handler function.
  793. *
  794. * Code:
  795. *
  796. * el.on('click', this.onClick, this, {
  797. * single: true,
  798. * delay: 100,
  799. * stopEvent : true,
  800. * forumId: 4
  801. * });
  802. *
  803. * **Attaching multiple handlers in 1 call**
  804. *
  805. * The method also allows for a single argument to be passed which is a config object containing properties which
  806. * specify multiple handlers.
  807. *
  808. * Code:
  809. *
  810. * el.on({
  811. * 'click' : {
  812. * fn: this.onClick,
  813. * scope: this,
  814. * delay: 100
  815. * },
  816. * 'mouseover' : {
  817. * fn: this.onMouseOver,
  818. * scope: this
  819. * },
  820. * 'mouseout' : {
  821. * fn: this.onMouseOut,
  822. * scope: this
  823. * }
  824. * });
  825. *
  826. * Or a shorthand syntax:
  827. *
  828. * Code:
  829. *
  830. * el.on({
  831. * 'click' : this.onClick,
  832. * 'mouseover' : this.onMouseOver,
  833. * 'mouseout' : this.onMouseOut,
  834. * scope: this
  835. * });
  836. *
  837. * **delegate**
  838. *
  839. * This is a configuration option that you can pass along when registering a handler for an event to assist with
  840. * event delegation. Event delegation is a technique that is used to reduce memory consumption and prevent exposure
  841. * to memory-leaks. By registering an event for a container element as opposed to each element within a container.
  842. * By setting this configuration option to a simple selector, the target element will be filtered to look for a
  843. * descendant of the target. For example:
  844. *
  845. * // using this markup:
  846. * &lt;div id='elId'&gt;
  847. * &lt;p id='p1'&gt;paragraph one&lt;/p&gt;
  848. * &lt;p id='p2' class='clickable'&gt;paragraph two&lt;/p&gt;
  849. * &lt;p id='p3'&gt;paragraph three&lt;/p&gt;
  850. * &lt;/div&gt;
  851. *
  852. * // utilize event delegation to registering just one handler on the container element:
  853. * el = Ext.get('elId');
  854. * el.on(
  855. * 'click',
  856. * function(e,t) {
  857. * // handle click
  858. * console.info(t.id); // 'p2'
  859. * },
  860. * this,
  861. * {
  862. * // filter the target element to be a descendant with the class 'clickable'
  863. * delegate: '.clickable'
  864. * }
  865. * );
  866. *
  867. * @return {Ext.dom.Element} this
  868. */
  869. on: function(eventName, fn, scope, options) {
  870. Ext.EventManager.on(this, eventName, fn, scope || this, options);
  871. return this;
  872. },
  873. <span id='Ext-dom-Element-method-un'> /**
  874. </span> * Removes an event handler from this element.
  875. *
  876. * **Note**: if a *scope* was explicitly specified when {@link #on adding} the listener,
  877. * the same scope must be specified here.
  878. *
  879. * Example:
  880. *
  881. * el.un('click', this.handlerFn);
  882. * // or
  883. * el.removeListener('click', this.handlerFn);
  884. *
  885. * @param {String} eventName The name of the event from which to remove the handler.
  886. * @param {Function} fn The handler function to remove. **This must be a reference to the function passed into the
  887. * {@link #on} call.**
  888. * @param {Object} scope If a scope (**this** reference) was specified when the listener was added, then this must
  889. * refer to the same object.
  890. * @return {Ext.dom.Element} this
  891. */
  892. un: function(eventName, fn, scope) {
  893. Ext.EventManager.un(this, eventName, fn, scope || this);
  894. return this;
  895. },
  896. <span id='Ext-dom-Element-method-removeAllListeners'> /**
  897. </span> * Removes all previous added listeners from this element
  898. * @return {Ext.dom.Element} this
  899. */
  900. removeAllListeners: function() {
  901. Ext.EventManager.removeAll(this);
  902. return this;
  903. },
  904. <span id='Ext-dom-Element-method-purgeAllListeners'> /**
  905. </span> * Recursively removes all previous added listeners from this element and its children
  906. * @return {Ext.dom.Element} this
  907. */
  908. purgeAllListeners: function() {
  909. Ext.EventManager.purgeElement(this);
  910. return this;
  911. }
  912. }, function() {
  913. var EC = Ext.cache,
  914. El = this,
  915. AbstractElement = Ext.dom.AbstractElement,
  916. focusRe = /a|button|embed|iframe|img|input|object|select|textarea/i,
  917. nonSpaceRe = /\S/,
  918. scriptTagRe = /(?:&lt;script([^&gt;]*)?&gt;)((\n|\r|.)*?)(?:&lt;\/script&gt;)/ig,
  919. replaceScriptTagRe = /(?:&lt;script.*?&gt;)((\n|\r|.)*?)(?:&lt;\/script&gt;)/ig,
  920. srcRe = /\ssrc=([\'\&quot;])(.*?)\1/i,
  921. typeRe = /\stype=([\'\&quot;])(.*?)\1/i,
  922. useDocForId = !(Ext.isIE6 || Ext.isIE7 || Ext.isIE8);
  923. El.boxMarkup = '&lt;div class=&quot;{0}-tl&quot;&gt;&lt;div class=&quot;{0}-tr&quot;&gt;&lt;div class=&quot;{0}-tc&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;{0}-ml&quot;&gt;&lt;div class=&quot;{0}-mr&quot;&gt;&lt;div class=&quot;{0}-mc&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;{0}-bl&quot;&gt;&lt;div class=&quot;{0}-br&quot;&gt;&lt;div class=&quot;{0}-bc&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;';
  924. //&lt;/!if&gt;
  925. // private
  926. // Garbage collection - uncache elements/purge listeners on orphaned elements
  927. // so we don't hold a reference and cause the browser to retain them
  928. function garbageCollect() {
  929. if (!Ext.enableGarbageCollector) {
  930. clearInterval(El.collectorThreadId);
  931. } else {
  932. var eid,
  933. d,
  934. o,
  935. t;
  936. for (eid in EC) {
  937. if (!EC.hasOwnProperty(eid)) {
  938. continue;
  939. }
  940. o = EC[eid];
  941. // Skip document and window elements
  942. if (o.skipGarbageCollection) {
  943. continue;
  944. }
  945. d = o.dom;
  946. //&lt;debug&gt;
  947. // Should always have a DOM node
  948. if (!d) {
  949. Ext.Error.raise('Missing DOM node in element garbage collection: ' + eid);
  950. }
  951. // Check that document and window elements haven't got through
  952. if (d &amp;&amp; (d.getElementById || d.navigator)) {
  953. Ext.Error.raise('Unexpected document or window element in element garbage collection');
  954. }
  955. //&lt;/debug&gt;
  956. // -------------------------------------------------------
  957. // Determining what is garbage:
  958. // -------------------------------------------------------
  959. // !d.parentNode
  960. // no parentNode == direct orphan, definitely garbage
  961. // -------------------------------------------------------
  962. // !d.offsetParent &amp;&amp; !document.getElementById(eid)
  963. // display none elements have no offsetParent so we will
  964. // also try to look it up by it's id. However, check
  965. // offsetParent first so we don't do unneeded lookups.
  966. // This enables collection of elements that are not orphans
  967. // directly, but somewhere up the line they have an orphan
  968. // parent.
  969. // -------------------------------------------------------
  970. if (!d.parentNode || (!d.offsetParent &amp;&amp; !Ext.getElementById(eid))) {
  971. if (d &amp;&amp; Ext.enableListenerCollection) {
  972. Ext.EventManager.removeAll(d);
  973. }
  974. delete EC[eid];
  975. }
  976. }
  977. // Cleanup IE Object leaks
  978. if (Ext.isIE) {
  979. t = {};
  980. for (eid in EC) {
  981. if (!EC.hasOwnProperty(eid)) {
  982. continue;
  983. }
  984. t[eid] = EC[eid];
  985. }
  986. EC = Ext.cache = t;
  987. }
  988. }
  989. }
  990. El.collectorThreadId = setInterval(garbageCollect, 30000);
  991. //Stuff from Element-more.js
  992. El.addMethods({
  993. <span id='Ext-dom-Element-method-monitorMouseLeave'> /**
  994. </span> * Monitors this Element for the mouse leaving. Calls the function after the specified delay only if
  995. * the mouse was not moved back into the Element within the delay. If the mouse *was* moved
  996. * back in, the function is not called.
  997. * @param {Number} delay The delay **in milliseconds** to wait for possible mouse re-entry before calling the handler function.
  998. * @param {Function} handler The function to call if the mouse remains outside of this Element for the specified time.
  999. * @param {Object} [scope] The scope (`this` reference) in which the handler function executes. Defaults to this Element.
  1000. * @return {Object} The listeners object which was added to this element so that monitoring can be stopped. Example usage:
  1001. *
  1002. * // Hide the menu if the mouse moves out for 250ms or more
  1003. * this.mouseLeaveMonitor = this.menuEl.monitorMouseLeave(250, this.hideMenu, this);
  1004. *
  1005. * ...
  1006. * // Remove mouseleave monitor on menu destroy
  1007. * this.menuEl.un(this.mouseLeaveMonitor);
  1008. *
  1009. */
  1010. monitorMouseLeave: function(delay, handler, scope) {
  1011. var me = this,
  1012. timer,
  1013. listeners = {
  1014. mouseleave: function(e) {
  1015. timer = setTimeout(Ext.Function.bind(handler, scope||me, [e]), delay);
  1016. },
  1017. mouseenter: function() {
  1018. clearTimeout(timer);
  1019. },
  1020. freezeEvent: true
  1021. };
  1022. me.on(listeners);
  1023. return listeners;
  1024. },
  1025. <span id='Ext-dom-Element-method-swallowEvent'> /**
  1026. </span> * Stops the specified event(s) from bubbling and optionally prevents the default action
  1027. * @param {String/String[]} eventName an event / array of events to stop from bubbling
  1028. * @param {Boolean} [preventDefault] true to prevent the default action too
  1029. * @return {Ext.dom.Element} this
  1030. */
  1031. swallowEvent : function(eventName, preventDefault) {
  1032. var me = this,
  1033. e, eLen;
  1034. function fn(e) {
  1035. e.stopPropagation();
  1036. if (preventDefault) {
  1037. e.preventDefault();
  1038. }
  1039. }
  1040. if (Ext.isArray(eventName)) {
  1041. eLen = eventName.length;
  1042. for (e = 0; e &lt; eLen; e++) {
  1043. me.on(eventName[e], fn);
  1044. }
  1045. return me;
  1046. }
  1047. me.on(eventName, fn);
  1048. return me;
  1049. },
  1050. <span id='Ext-dom-Element-method-relayEvent'> /**
  1051. </span> * Create an event handler on this element such that when the event fires and is handled by this element,
  1052. * it will be relayed to another object (i.e., fired again as if it originated from that object instead).
  1053. * @param {String} eventName The type of event to relay
  1054. * @param {Object} observable Any object that extends {@link Ext.util.Observable} that will provide the context
  1055. * for firing the relayed event
  1056. */
  1057. relayEvent : function(eventName, observable) {
  1058. this.on(eventName, function(e) {
  1059. observable.fireEvent(eventName, e);
  1060. });
  1061. },
  1062. <span id='Ext-dom-Element-method-clean'> /**
  1063. </span> * Removes Empty, or whitespace filled text nodes. Combines adjacent text nodes.
  1064. * @param {Boolean} [forceReclean=false] By default the element keeps track if it has been cleaned already
  1065. * so you can call this over and over. However, if you update the element and need to force a reclean, you
  1066. * can pass true.
  1067. */
  1068. clean : function(forceReclean) {
  1069. var me = this,
  1070. dom = me.dom,
  1071. data = (me.$cache || me.getCache()).data,
  1072. n = dom.firstChild,
  1073. ni = -1,
  1074. nx;
  1075. if (data.isCleaned &amp;&amp; forceReclean !== true) {
  1076. return me;
  1077. }
  1078. while (n) {
  1079. nx = n.nextSibling;
  1080. if (n.nodeType == 3) {
  1081. // Remove empty/whitespace text nodes
  1082. if (!(nonSpaceRe.test(n.nodeValue))) {
  1083. dom.removeChild(n);
  1084. // Combine adjacent text nodes
  1085. } else if (nx &amp;&amp; nx.nodeType == 3) {
  1086. n.appendData(Ext.String.trim(nx.data));
  1087. dom.removeChild(nx);
  1088. nx = n.nextSibling;
  1089. n.nodeIndex = ++ni;
  1090. }
  1091. } else {
  1092. // Recursively clean
  1093. Ext.fly(n).clean();
  1094. n.nodeIndex = ++ni;
  1095. }
  1096. n = nx;
  1097. }
  1098. data.isCleaned = true;
  1099. return me;
  1100. },
  1101. <span id='Ext-dom-Element-method-load'> /**
  1102. </span> * Direct access to the Ext.ElementLoader {@link Ext.ElementLoader#method-load} method. The method takes the same object
  1103. * parameter as {@link Ext.ElementLoader#method-load}
  1104. * @return {Ext.dom.Element} this
  1105. */
  1106. load : function(options) {
  1107. this.getLoader().load(options);
  1108. return this;
  1109. },
  1110. <span id='Ext-dom-Element-method-getLoader'> /**
  1111. </span> * Gets this element's {@link Ext.ElementLoader ElementLoader}
  1112. * @return {Ext.ElementLoader} The loader
  1113. */
  1114. getLoader : function() {
  1115. var me = this,
  1116. data = (me.$cache || me.getCache()).data,
  1117. loader = data.loader;
  1118. if (!loader) {
  1119. data.loader = loader = new Ext.ElementLoader({
  1120. target: me
  1121. });
  1122. }
  1123. return loader;
  1124. },
  1125. <span id='Ext-dom-Element-method-syncContent'> /**
  1126. </span> * @private.
  1127. * Currently used for updating grid cells without modifying DOM structure
  1128. *
  1129. * Synchronizes content of this Element with the content of the passed element.
  1130. *
  1131. * Style and CSS class are copied from source into this Element, and contents are synched
  1132. * recursively. If a child node is a text node, the textual data is copied.
  1133. */
  1134. syncContent: function(source) {
  1135. source = Ext.getDom(source);
  1136. var me = this,
  1137. sourceNodes = source.childNodes,
  1138. sourceLen = sourceNodes.length,
  1139. dest = me.dom,
  1140. destNodes = dest.childNodes,
  1141. destLen = destNodes.length,
  1142. i, destNode, sourceNode,
  1143. nodeType;
  1144. // Copy top node's style and CSS class
  1145. dest.style.cssText = source.style.cssText;
  1146. dest.className = source.className;
  1147. // If the number of child nodes does not match, fall back to replacing innerHTML
  1148. if (sourceLen !== destLen) {
  1149. source.innerHTML = dest.innerHTML;
  1150. return;
  1151. }
  1152. // Loop through source nodes.
  1153. // If there are fewer, we must remove excess
  1154. for (i = 0; i &lt; sourceLen; i++) {
  1155. sourceNode = sourceNodes[i];
  1156. destNode = destNodes[i];
  1157. nodeType = sourceNode.nodeType;
  1158. // If node structure is out of sync, just drop innerHTML in and return
  1159. if (nodeType !== destNode.nodeType || (nodeType === 1 &amp;&amp; sourceNode.tagName !== destNode.tagName)) {
  1160. dest.innerHTML = source.innerHTML;
  1161. return;
  1162. }
  1163. // Update text node
  1164. if (nodeType === 3) {
  1165. destNode.data = sourceNode.data;
  1166. }
  1167. // Sync element content
  1168. else {
  1169. if (sourceNode.id &amp;&amp; destNode.id !== sourceNode.id) {
  1170. destNode.id = sourceNode.id;
  1171. }
  1172. destNode.style.cssText = sourceNode.style.cssText;
  1173. destNode.className = sourceNode.className;
  1174. Ext.fly(destNode).syncContent(sourceNode);
  1175. }
  1176. }
  1177. },
  1178. <span id='Ext-dom-Element-method-update'> /**
  1179. </span> * Updates the innerHTML of this element, optionally searching for and processing scripts.
  1180. * @param {String} html The new HTML
  1181. * @param {Boolean} [loadScripts] True to look for and process scripts (defaults to false)
  1182. * @param {Function} [callback] For async script loading you can be notified when the update completes
  1183. * @return {Ext.dom.Element} this
  1184. */
  1185. update : function(html, loadScripts, callback) {
  1186. var me = this,
  1187. id,
  1188. dom,
  1189. interval;
  1190. if (!me.dom) {
  1191. return me;
  1192. }
  1193. html = html || '';
  1194. dom = me.dom;
  1195. if (loadScripts !== true) {
  1196. dom.innerHTML = html;
  1197. Ext.callback(callback, me);
  1198. return me;
  1199. }
  1200. id = Ext.id();
  1201. html += '&lt;span id=&quot;' + id + '&quot;&gt;&lt;/span&gt;';
  1202. interval = setInterval(function() {
  1203. var hd,
  1204. match,
  1205. attrs,
  1206. srcMatch,
  1207. typeMatch,
  1208. el,
  1209. s;
  1210. if (!(el = DOC.getElementById(id))) {
  1211. return false;
  1212. }
  1213. clearInterval(interval);
  1214. Ext.removeNode(el);
  1215. hd = Ext.getHead().dom;
  1216. while ((match = scriptTagRe.exec(html))) {
  1217. attrs = match[1];
  1218. srcMatch = attrs ? attrs.match(srcRe) : false;
  1219. if (srcMatch &amp;&amp; srcMatch[2]) {
  1220. s = DOC.createElement(&quot;script&quot;);
  1221. s.src = srcMatch[2];
  1222. typeMatch = attrs.match(typeRe);
  1223. if (typeMatch &amp;&amp; typeMatch[2]) {
  1224. s.type = typeMatch[2];
  1225. }
  1226. hd.appendChild(s);
  1227. } else if (match[2] &amp;&amp; match[2].length &gt; 0) {
  1228. if (window.execScript) {
  1229. window.execScript(match[2]);
  1230. } else {
  1231. window.eval(match[2]);
  1232. }
  1233. }
  1234. }
  1235. Ext.callback(callback, me);
  1236. }, 20);
  1237. dom.innerHTML = html.replace(replaceScriptTagRe, '');
  1238. return me;
  1239. },
  1240. // inherit docs, overridden so we can add removeAnchor
  1241. removeAllListeners : function() {
  1242. this.removeAnchor();
  1243. Ext.EventManager.removeAll(this.dom);
  1244. return this;
  1245. },
  1246. <span id='Ext-dom-Element-method-createProxy'> /**
  1247. </span> * Creates a proxy element of this element
  1248. * @param {String/Object} config The class name of the proxy element or a DomHelper config object
  1249. * @param {String/HTMLElement} [renderTo] The element or element id to render the proxy to. Defaults to: document.body.
  1250. * @param {Boolean} [matchBox=false] True to align and size the proxy to this element now.
  1251. * @return {Ext.dom.Element} The new proxy element
  1252. */
  1253. createProxy : function(config, renderTo, matchBox) {
  1254. config = (typeof config == 'object') ? config : {tag : &quot;div&quot;, cls: config};
  1255. var me = this,
  1256. proxy = renderTo ? Ext.DomHelper.append(renderTo, config, true) :
  1257. Ext.DomHelper.insertBefore(me.dom, config, true);
  1258. proxy.setVisibilityMode(Element.DISPLAY);
  1259. proxy.hide();
  1260. if (matchBox &amp;&amp; me.setBox &amp;&amp; me.getBox) { // check to make sure Element.position.js is loaded
  1261. proxy.setBox(me.getBox());
  1262. }
  1263. return proxy;
  1264. },
  1265. <span id='Ext-dom-Element-method-getScopeParent'> /**
  1266. </span> * Gets the parent node of the current element taking into account Ext.scopeResetCSS
  1267. * @protected
  1268. * @return {HTMLElement} The parent element
  1269. */
  1270. getScopeParent: function() {
  1271. var parent = this.dom.parentNode;
  1272. if (Ext.scopeResetCSS) {
  1273. // If it's a normal reset, we will be wrapped in a single x-reset element, so grab the parent
  1274. parent = parent.parentNode;
  1275. if (!Ext.supports.CSS3LinearGradient || !Ext.supports.CSS3BorderRadius) {
  1276. // In the cases where we have nbr or nlg, it will be wrapped in a second element,
  1277. // so we need to go and get the parent again.
  1278. parent = parent.parentNode;
  1279. }
  1280. }
  1281. return parent;
  1282. },
  1283. <span id='Ext-dom-Element-method-needsTabIndex'> /**
  1284. </span> * Returns true if this element needs an explicit tabIndex to make it focusable. Input fields, text areas, buttons
  1285. * anchors elements **with an href** etc do not need a tabIndex, but structural elements do.
  1286. */
  1287. needsTabIndex: function() {
  1288. if (this.dom) {
  1289. if ((this.dom.nodeName === 'a') &amp;&amp; (!this.dom.href)) {
  1290. return true;
  1291. }
  1292. return !focusRe.test(this.dom.nodeName);
  1293. }
  1294. },
  1295. <span id='Ext-dom-Element-method-focusable'> /**
  1296. </span> * Checks whether this element can be focused.
  1297. * @return {Boolean} True if the element is focusable
  1298. */
  1299. focusable: function () {
  1300. var dom = this.dom,
  1301. nodeName = dom.nodeName,
  1302. canFocus = false;
  1303. if (!dom.disabled) {
  1304. if (focusRe.test(nodeName)) {
  1305. if ((nodeName !== 'a') || dom.href) {
  1306. canFocus = true;
  1307. }
  1308. } else {
  1309. canFocus = !isNaN(dom.tabIndex);
  1310. }
  1311. }
  1312. return canFocus &amp;&amp; this.isVisible(true);
  1313. }
  1314. });
  1315. if (Ext.isIE) {
  1316. El.prototype.getById = function (id, asDom) {
  1317. var dom = this.dom,
  1318. cacheItem, el, ret;
  1319. if (dom) {
  1320. // for normal elements getElementById is the best solution, but if the el is
  1321. // not part of the document.body, we need to use all[]
  1322. el = (useDocForId &amp;&amp; DOC.getElementById(id)) || dom.all[id];
  1323. if (el) {
  1324. if (asDom) {
  1325. ret = el;
  1326. } else {
  1327. // calling El.get here is a real hit (2x slower) because it has to
  1328. // redetermine that we are giving it a dom el.
  1329. cacheItem = EC[id];
  1330. if (cacheItem &amp;&amp; cacheItem.el) {
  1331. ret = Ext.updateCacheEntry(cacheItem, el).el;
  1332. } else {
  1333. ret = new Element(el);
  1334. }
  1335. }
  1336. return ret;
  1337. }
  1338. }
  1339. return asDom ? Ext.getDom(id) : El.get(id);
  1340. };
  1341. }
  1342. El.createAlias({
  1343. <span id='Ext-dom-Element-method-addListener'> /**
  1344. </span> * @method
  1345. * @inheritdoc Ext.dom.Element#on
  1346. * Shorthand for {@link #on}.
  1347. */
  1348. addListener: 'on',
  1349. <span id='Ext-dom-Element-method-removeListener'> /**
  1350. </span> * @method
  1351. * @inheritdoc Ext.dom.Element#un
  1352. * Shorthand for {@link #un}.
  1353. */
  1354. removeListener: 'un',
  1355. <span id='Ext-dom-Element-method-clearListeners'> /**
  1356. </span> * @method
  1357. * @inheritdoc Ext.dom.Element#removeAllListeners
  1358. * Alias for {@link #removeAllListeners}.
  1359. */
  1360. clearListeners: 'removeAllListeners'
  1361. });
  1362. El.Fly = AbstractElement.Fly = new Ext.Class({
  1363. extend: El,
  1364. constructor: function(dom) {
  1365. this.dom = dom;
  1366. },
  1367. attach: AbstractElement.Fly.prototype.attach
  1368. });
  1369. if (Ext.isIE) {
  1370. Ext.getElementById = function (id) {
  1371. var el = DOC.getElementById(id),
  1372. detachedBodyEl;
  1373. if (!el &amp;&amp; (detachedBodyEl = AbstractElement.detachedBodyEl)) {
  1374. el = detachedBodyEl.dom.all[id];
  1375. }
  1376. return el;
  1377. };
  1378. } else if (!DOC.querySelector) {
  1379. Ext.getDetachedBody = Ext.getBody;
  1380. Ext.getElementById = function (id) {
  1381. return DOC.getElementById(id);
  1382. };
  1383. }
  1384. });
  1385. }());
  1386. </pre>
  1387. </body>
  1388. </html>