AbstractElement.style.html 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  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. */
  21. (function(){
  22. // local style camelizing for speed
  23. var Element = Ext.dom.AbstractElement,
  24. view = document.defaultView,
  25. array = Ext.Array,
  26. trimRe = /^\s+|\s+$/g,
  27. wordsRe = /\w/g,
  28. spacesRe = /\s+/,
  29. transparentRe = /^(?:transparent|(?:rgba[(](?:\s*\d+\s*[,]){3}\s*0\s*[)]))$/i,
  30. hasClassList = Ext.supports.ClassList,
  31. PADDING = 'padding',
  32. MARGIN = 'margin',
  33. BORDER = 'border',
  34. LEFT_SUFFIX = '-left',
  35. RIGHT_SUFFIX = '-right',
  36. TOP_SUFFIX = '-top',
  37. BOTTOM_SUFFIX = '-bottom',
  38. WIDTH = '-width',
  39. // special markup used throughout Ext when box wrapping elements
  40. borders = {l: BORDER + LEFT_SUFFIX + WIDTH, r: BORDER + RIGHT_SUFFIX + WIDTH, t: BORDER + TOP_SUFFIX + WIDTH, b: BORDER + BOTTOM_SUFFIX + WIDTH},
  41. paddings = {l: PADDING + LEFT_SUFFIX, r: PADDING + RIGHT_SUFFIX, t: PADDING + TOP_SUFFIX, b: PADDING + BOTTOM_SUFFIX},
  42. margins = {l: MARGIN + LEFT_SUFFIX, r: MARGIN + RIGHT_SUFFIX, t: MARGIN + TOP_SUFFIX, b: MARGIN + BOTTOM_SUFFIX};
  43. Element.override({
  44. <span id='Ext-dom-AbstractElement-property-styleHooks'> /**
  45. </span> * This shared object is keyed by style name (e.g., 'margin-left' or 'marginLeft'). The
  46. * values are objects with the following properties:
  47. *
  48. * * `name` (String) : The actual name to be presented to the DOM. This is typically the value
  49. * returned by {@link #normalize}.
  50. * * `get` (Function) : A hook function that will perform the get on this style. These
  51. * functions receive &quot;(dom, el)&quot; arguments. The `dom` parameter is the DOM Element
  52. * from which to get ths tyle. The `el` argument (may be null) is the Ext.Element.
  53. * * `set` (Function) : A hook function that will perform the set on this style. These
  54. * functions receive &quot;(dom, value, el)&quot; arguments. The `dom` parameter is the DOM Element
  55. * from which to get ths tyle. The `value` parameter is the new value for the style. The
  56. * `el` argument (may be null) is the Ext.Element.
  57. *
  58. * The `this` pointer is the object that contains `get` or `set`, which means that
  59. * `this.name` can be accessed if needed. The hook functions are both optional.
  60. * @private
  61. */
  62. styleHooks: {},
  63. // private
  64. addStyles : function(sides, styles){
  65. var totalSize = 0,
  66. sidesArr = (sides || '').match(wordsRe),
  67. i,
  68. len = sidesArr.length,
  69. side,
  70. styleSides = [];
  71. if (len == 1) {
  72. totalSize = Math.abs(parseFloat(this.getStyle(styles[sidesArr[0]])) || 0);
  73. } else if (len) {
  74. for (i = 0; i &lt; len; i++) {
  75. side = sidesArr[i];
  76. styleSides.push(styles[side]);
  77. }
  78. //Gather all at once, returning a hash
  79. styleSides = this.getStyle(styleSides);
  80. for (i=0; i &lt; len; i++) {
  81. side = sidesArr[i];
  82. totalSize += Math.abs(parseFloat(styleSides[styles[side]]) || 0);
  83. }
  84. }
  85. return totalSize;
  86. },
  87. <span id='Ext-dom-AbstractElement-method-addCls'> /**
  88. </span> * Adds one or more CSS classes to the element. Duplicate classes are automatically filtered out.
  89. * @param {String/String[]} className The CSS classes to add separated by space, or an array of classes
  90. * @return {Ext.dom.Element} this
  91. * @method
  92. */
  93. addCls: hasClassList ?
  94. function (className) {
  95. //&lt;debug warn&gt;
  96. if (String(className).indexOf('undefined') &gt; -1) {
  97. Ext.Logger.warn(&quot;called with an undefined className: &quot; + className);
  98. }
  99. //&lt;/debug&gt;
  100. var me = this,
  101. dom = me.dom,
  102. classList,
  103. newCls,
  104. i,
  105. len,
  106. cls;
  107. if (typeof(className) == 'string') {
  108. // split string on spaces to make an array of className
  109. className = className.replace(trimRe, '').split(spacesRe);
  110. }
  111. // the gain we have here is that we can skip parsing className and use the
  112. // classList.contains method, so now O(M) not O(M+N)
  113. if (dom &amp;&amp; className &amp;&amp; !!(len = className.length)) {
  114. if (!dom.className) {
  115. dom.className = className.join(' ');
  116. } else {
  117. classList = dom.classList;
  118. for (i = 0; i &lt; len; ++i) {
  119. cls = className[i];
  120. if (cls) {
  121. if (!classList.contains(cls)) {
  122. if (newCls) {
  123. newCls.push(cls);
  124. } else {
  125. newCls = dom.className.replace(trimRe, '');
  126. newCls = newCls ? [newCls, cls] : [cls];
  127. }
  128. }
  129. }
  130. }
  131. if (newCls) {
  132. dom.className = newCls.join(' '); // write to DOM once
  133. }
  134. }
  135. }
  136. return me;
  137. } :
  138. function(className) {
  139. //&lt;debug warn&gt;
  140. if (String(className).indexOf('undefined') &gt; -1) {
  141. Ext.Logger.warn(&quot;called with an undefined className: '&quot; + className + &quot;'&quot;);
  142. }
  143. //&lt;/debug&gt;
  144. var me = this,
  145. dom = me.dom,
  146. changed,
  147. elClasses;
  148. if (dom &amp;&amp; className &amp;&amp; className.length) {
  149. elClasses = Ext.Element.mergeClsList(dom.className, className);
  150. if (elClasses.changed) {
  151. dom.className = elClasses.join(' '); // write to DOM once
  152. }
  153. }
  154. return me;
  155. },
  156. <span id='Ext-dom-AbstractElement-method-removeCls'> /**
  157. </span> * Removes one or more CSS classes from the element.
  158. * @param {String/String[]} className The CSS classes to remove separated by space, or an array of classes
  159. * @return {Ext.dom.Element} this
  160. */
  161. removeCls: function(className) {
  162. var me = this,
  163. dom = me.dom,
  164. len,
  165. elClasses;
  166. if (typeof(className) == 'string') {
  167. // split string on spaces to make an array of className
  168. className = className.replace(trimRe, '').split(spacesRe);
  169. }
  170. if (dom &amp;&amp; dom.className &amp;&amp; className &amp;&amp; !!(len = className.length)) {
  171. if (len == 1 &amp;&amp; hasClassList) {
  172. if (className[0]) {
  173. dom.classList.remove(className[0]); // one DOM write
  174. }
  175. } else {
  176. elClasses = Ext.Element.removeCls(dom.className, className);
  177. if (elClasses.changed) {
  178. dom.className = elClasses.join(' ');
  179. }
  180. }
  181. }
  182. return me;
  183. },
  184. <span id='Ext-dom-AbstractElement-method-radioCls'> /**
  185. </span> * Adds one or more CSS classes to this element and removes the same class(es) from all siblings.
  186. * @param {String/String[]} className The CSS class to add, or an array of classes
  187. * @return {Ext.dom.Element} this
  188. */
  189. radioCls: function(className) {
  190. var cn = this.dom.parentNode.childNodes,
  191. v,
  192. i, len;
  193. className = Ext.isArray(className) ? className: [className];
  194. for (i = 0, len = cn.length; i &lt; len; i++) {
  195. v = cn[i];
  196. if (v &amp;&amp; v.nodeType == 1) {
  197. Ext.fly(v, '_internal').removeCls(className);
  198. }
  199. }
  200. return this.addCls(className);
  201. },
  202. <span id='Ext-dom-AbstractElement-method-toggleCls'> /**
  203. </span> * Toggles the specified CSS class on this element (removes it if it already exists, otherwise adds it).
  204. * @param {String} className The CSS class to toggle
  205. * @return {Ext.dom.Element} this
  206. * @method
  207. */
  208. toggleCls: hasClassList ?
  209. function (className) {
  210. var me = this,
  211. dom = me.dom;
  212. if (dom) {
  213. className = className.replace(trimRe, '');
  214. if (className) {
  215. dom.classList.toggle(className);
  216. }
  217. }
  218. return me;
  219. } :
  220. function(className) {
  221. var me = this;
  222. return me.hasCls(className) ? me.removeCls(className) : me.addCls(className);
  223. },
  224. <span id='Ext-dom-AbstractElement-method-hasCls'> /**
  225. </span> * Checks if the specified CSS class exists on this element's DOM node.
  226. * @param {String} className The CSS class to check for
  227. * @return {Boolean} True if the class exists, else false
  228. * @method
  229. */
  230. hasCls: hasClassList ?
  231. function (className) {
  232. var dom = this.dom;
  233. return (dom &amp;&amp; className) ? dom.classList.contains(className) : false;
  234. } :
  235. function(className) {
  236. var dom = this.dom;
  237. return dom ? className &amp;&amp; (' '+dom.className+' ').indexOf(' '+className+' ') != -1 : false;
  238. },
  239. <span id='Ext-dom-AbstractElement-method-replaceCls'> /**
  240. </span> * Replaces a CSS class on the element with another. If the old name does not exist, the new name will simply be added.
  241. * @param {String} oldClassName The CSS class to replace
  242. * @param {String} newClassName The replacement CSS class
  243. * @return {Ext.dom.Element} this
  244. */
  245. replaceCls: function(oldClassName, newClassName){
  246. return this.removeCls(oldClassName).addCls(newClassName);
  247. },
  248. <span id='Ext-dom-AbstractElement-method-isStyle'> /**
  249. </span> * Checks if the current value of a style is equal to a given value.
  250. * @param {String} style property whose value is returned.
  251. * @param {String} value to check against.
  252. * @return {Boolean} true for when the current value equals the given value.
  253. */
  254. isStyle: function(style, val) {
  255. return this.getStyle(style) == val;
  256. },
  257. <span id='Ext-dom-AbstractElement-method-getStyle'> /**
  258. </span> * Returns a named style property based on computed/currentStyle (primary) and
  259. * inline-style if primary is not available.
  260. *
  261. * @param {String/String[]} property The style property (or multiple property names
  262. * in an array) whose value is returned.
  263. * @param {Boolean} [inline=false] if `true` only inline styles will be returned.
  264. * @return {String/Object} The current value of the style property for this element
  265. * (or a hash of named style values if multiple property arguments are requested).
  266. * @method
  267. */
  268. getStyle: function (property, inline) {
  269. var me = this,
  270. dom = me.dom,
  271. multiple = typeof property != 'string',
  272. hooks = me.styleHooks,
  273. prop = property,
  274. props = prop,
  275. len = 1,
  276. domStyle, camel, values, hook, out, style, i;
  277. if (multiple) {
  278. values = {};
  279. prop = props[0];
  280. i = 0;
  281. if (!(len = props.length)) {
  282. return values;
  283. }
  284. }
  285. if (!dom || dom.documentElement) {
  286. return values || '';
  287. }
  288. domStyle = dom.style;
  289. if (inline) {
  290. style = domStyle;
  291. } else {
  292. // Caution: Firefox will not render &quot;presentation&quot; (ie. computed styles) in
  293. // iframes that are display:none or those inheriting display:none. Similar
  294. // issues with legacy Safari.
  295. //
  296. style = dom.ownerDocument.defaultView.getComputedStyle(dom, null);
  297. // fallback to inline style if rendering context not available
  298. if (!style) {
  299. inline = true;
  300. style = domStyle;
  301. }
  302. }
  303. do {
  304. hook = hooks[prop];
  305. if (!hook) {
  306. hooks[prop] = hook = { name: Element.normalize(prop) };
  307. }
  308. if (hook.get) {
  309. out = hook.get(dom, me, inline, style);
  310. } else {
  311. camel = hook.name;
  312. out = style[camel];
  313. }
  314. if (!multiple) {
  315. return out;
  316. }
  317. values[prop] = out;
  318. prop = props[++i];
  319. } while (i &lt; len);
  320. return values;
  321. },
  322. getStyles: function () {
  323. var props = Ext.Array.slice(arguments),
  324. len = props.length,
  325. inline;
  326. if (len &amp;&amp; typeof props[len-1] == 'boolean') {
  327. inline = props.pop();
  328. }
  329. return this.getStyle(props, inline);
  330. },
  331. <span id='Ext-dom-AbstractElement-method-isTransparent'> /**
  332. </span> * Returns true if the value of the given property is visually transparent. This
  333. * may be due to a 'transparent' style value or an rgba value with 0 in the alpha
  334. * component.
  335. * @param {String} prop The style property whose value is to be tested.
  336. * @return {Boolean} True if the style property is visually transparent.
  337. */
  338. isTransparent: function (prop) {
  339. var value = this.getStyle(prop);
  340. return value ? transparentRe.test(value) : false;
  341. },
  342. <span id='Ext-dom-AbstractElement-method-setStyle'> /**
  343. </span> * Wrapper for setting style properties, also takes single object parameter of multiple styles.
  344. * @param {String/Object} property The style property to be set, or an object of multiple styles.
  345. * @param {String} [value] The value to apply to the given property, or null if an object was passed.
  346. * @return {Ext.dom.Element} this
  347. */
  348. setStyle: function(prop, value) {
  349. var me = this,
  350. dom = me.dom,
  351. hooks = me.styleHooks,
  352. style = dom.style,
  353. name = prop,
  354. hook;
  355. // we don't promote the 2-arg form to object-form to avoid the overhead...
  356. if (typeof name == 'string') {
  357. hook = hooks[name];
  358. if (!hook) {
  359. hooks[name] = hook = { name: Element.normalize(name) };
  360. }
  361. value = (value == null) ? '' : value;
  362. if (hook.set) {
  363. hook.set(dom, value, me);
  364. } else {
  365. style[hook.name] = value;
  366. }
  367. if (hook.afterSet) {
  368. hook.afterSet(dom, value, me);
  369. }
  370. } else {
  371. for (name in prop) {
  372. if (prop.hasOwnProperty(name)) {
  373. hook = hooks[name];
  374. if (!hook) {
  375. hooks[name] = hook = { name: Element.normalize(name) };
  376. }
  377. value = prop[name];
  378. value = (value == null) ? '' : value;
  379. if (hook.set) {
  380. hook.set(dom, value, me);
  381. } else {
  382. style[hook.name] = value;
  383. }
  384. if (hook.afterSet) {
  385. hook.afterSet(dom, value, me);
  386. }
  387. }
  388. }
  389. }
  390. return me;
  391. },
  392. <span id='Ext-dom-AbstractElement-method-getHeight'> /**
  393. </span> * Returns the offset height of the element
  394. * @param {Boolean} [contentHeight] true to get the height minus borders and padding
  395. * @return {Number} The element's height
  396. */
  397. getHeight: function(contentHeight) {
  398. var dom = this.dom,
  399. height = contentHeight ? (dom.clientHeight - this.getPadding(&quot;tb&quot;)) : dom.offsetHeight;
  400. return height &gt; 0 ? height: 0;
  401. },
  402. <span id='Ext-dom-AbstractElement-method-getWidth'> /**
  403. </span> * Returns the offset width of the element
  404. * @param {Boolean} [contentWidth] true to get the width minus borders and padding
  405. * @return {Number} The element's width
  406. */
  407. getWidth: function(contentWidth) {
  408. var dom = this.dom,
  409. width = contentWidth ? (dom.clientWidth - this.getPadding(&quot;lr&quot;)) : dom.offsetWidth;
  410. return width &gt; 0 ? width: 0;
  411. },
  412. <span id='Ext-dom-AbstractElement-method-setWidth'> /**
  413. </span> * Set the width of this Element.
  414. * @param {Number/String} width The new width. This may be one of:
  415. *
  416. * - A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels).
  417. * - A String used to set the CSS width style. Animation may **not** be used.
  418. *
  419. * @param {Boolean/Object} [animate] true for the default animation or a standard Element animation config object
  420. * @return {Ext.dom.Element} this
  421. */
  422. setWidth: function(width) {
  423. var me = this;
  424. me.dom.style.width = Element.addUnits(width);
  425. return me;
  426. },
  427. <span id='Ext-dom-AbstractElement-method-setHeight'> /**
  428. </span> * Set the height of this Element.
  429. *
  430. * // change the height to 200px and animate with default configuration
  431. * Ext.fly('elementId').setHeight(200, true);
  432. *
  433. * // change the height to 150px and animate with a custom configuration
  434. * Ext.fly('elId').setHeight(150, {
  435. * duration : 500, // animation will have a duration of .5 seconds
  436. * // will change the content to &quot;finished&quot;
  437. * callback: function(){ this.{@link #update}(&quot;finished&quot;); }
  438. * });
  439. *
  440. * @param {Number/String} height The new height. This may be one of:
  441. *
  442. * - A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels.)
  443. * - A String used to set the CSS height style. Animation may **not** be used.
  444. *
  445. * @param {Boolean/Object} [animate] true for the default animation or a standard Element animation config object
  446. * @return {Ext.dom.Element} this
  447. */
  448. setHeight: function(height) {
  449. var me = this;
  450. me.dom.style.height = Element.addUnits(height);
  451. return me;
  452. },
  453. <span id='Ext-dom-AbstractElement-method-getBorderWidth'> /**
  454. </span> * Gets the width of the border(s) for the specified side(s)
  455. * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
  456. * passing `'lr'` would get the border **l**eft width + the border **r**ight width.
  457. * @return {Number} The width of the sides passed added together
  458. */
  459. getBorderWidth: function(side){
  460. return this.addStyles(side, borders);
  461. },
  462. <span id='Ext-dom-AbstractElement-method-getPadding'> /**
  463. </span> * Gets the width of the padding(s) for the specified side(s)
  464. * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
  465. * passing `'lr'` would get the padding **l**eft + the padding **r**ight.
  466. * @return {Number} The padding of the sides passed added together
  467. */
  468. getPadding: function(side){
  469. return this.addStyles(side, paddings);
  470. },
  471. margins : margins,
  472. <span id='Ext-dom-AbstractElement-method-applyStyles'> /**
  473. </span> * More flexible version of {@link #setStyle} for setting style properties.
  474. * @param {String/Object/Function} styles A style specification string, e.g. &quot;width:100px&quot;, or object in the form {width:&quot;100px&quot;}, or
  475. * a function which returns such a specification.
  476. * @return {Ext.dom.Element} this
  477. */
  478. applyStyles: function(styles) {
  479. if (styles) {
  480. var i,
  481. len,
  482. dom = this.dom;
  483. if (typeof styles == 'function') {
  484. styles = styles.call();
  485. }
  486. if (typeof styles == 'string') {
  487. styles = Ext.util.Format.trim(styles).split(/\s*(?::|;)\s*/);
  488. for (i = 0, len = styles.length; i &lt; len;) {
  489. dom.style[Element.normalize(styles[i++])] = styles[i++];
  490. }
  491. }
  492. else if (typeof styles == 'object') {
  493. this.setStyle(styles);
  494. }
  495. }
  496. },
  497. <span id='Ext-dom-AbstractElement-method-setSize'> /**
  498. </span> * Set the size of this Element. If animation is true, both width and height will be animated concurrently.
  499. * @param {Number/String} width The new width. This may be one of:
  500. *
  501. * - A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels).
  502. * - A String used to set the CSS width style. Animation may **not** be used.
  503. * - A size object in the format `{width: widthValue, height: heightValue}`.
  504. *
  505. * @param {Number/String} height The new height. This may be one of:
  506. *
  507. * - A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels).
  508. * - A String used to set the CSS height style. Animation may **not** be used.
  509. *
  510. * @param {Boolean/Object} [animate] true for the default animation or a standard Element animation config object
  511. * @return {Ext.dom.Element} this
  512. */
  513. setSize: function(width, height) {
  514. var me = this,
  515. style = me.dom.style;
  516. if (Ext.isObject(width)) {
  517. // in case of object from getSize()
  518. height = width.height;
  519. width = width.width;
  520. }
  521. style.width = Element.addUnits(width);
  522. style.height = Element.addUnits(height);
  523. return me;
  524. },
  525. <span id='Ext-dom-AbstractElement-method-getViewSize'> /**
  526. </span> * Returns the dimensions of the element available to lay content out in.
  527. *
  528. * If the element (or any ancestor element) has CSS style `display: none`, the dimensions will be zero.
  529. *
  530. * Example:
  531. *
  532. * var vpSize = Ext.getBody().getViewSize();
  533. *
  534. * // all Windows created afterwards will have a default value of 90% height and 95% width
  535. * Ext.Window.override({
  536. * width: vpSize.width * 0.9,
  537. * height: vpSize.height * 0.95
  538. * });
  539. * // To handle window resizing you would have to hook onto onWindowResize.
  540. *
  541. * getViewSize utilizes clientHeight/clientWidth which excludes sizing of scrollbars.
  542. * To obtain the size including scrollbars, use getStyleSize
  543. *
  544. * Sizing of the document body is handled at the adapter level which handles special cases for IE and strict modes, etc.
  545. *
  546. * @return {Object} Object describing width and height.
  547. * @return {Number} return.width
  548. * @return {Number} return.height
  549. */
  550. getViewSize: function() {
  551. var doc = document,
  552. dom = this.dom;
  553. if (dom == doc || dom == doc.body) {
  554. return {
  555. width: Element.getViewportWidth(),
  556. height: Element.getViewportHeight()
  557. };
  558. }
  559. else {
  560. return {
  561. width: dom.clientWidth,
  562. height: dom.clientHeight
  563. };
  564. }
  565. },
  566. <span id='Ext-dom-AbstractElement-method-getSize'> /**
  567. </span> * Returns the size of the element.
  568. * @param {Boolean} [contentSize] true to get the width/size minus borders and padding
  569. * @return {Object} An object containing the element's size:
  570. * @return {Number} return.width
  571. * @return {Number} return.height
  572. */
  573. getSize: function(contentSize) {
  574. var dom = this.dom;
  575. return {
  576. width: Math.max(0, contentSize ? (dom.clientWidth - this.getPadding(&quot;lr&quot;)) : dom.offsetWidth),
  577. height: Math.max(0, contentSize ? (dom.clientHeight - this.getPadding(&quot;tb&quot;)) : dom.offsetHeight)
  578. };
  579. },
  580. <span id='Ext-dom-AbstractElement-method-repaint'> /**
  581. </span> * Forces the browser to repaint this element
  582. * @return {Ext.dom.Element} this
  583. */
  584. repaint: function(){
  585. var dom = this.dom;
  586. this.addCls(Ext.baseCSSPrefix + 'repaint');
  587. setTimeout(function(){
  588. Ext.fly(dom).removeCls(Ext.baseCSSPrefix + 'repaint');
  589. }, 1);
  590. return this;
  591. },
  592. <span id='Ext-dom-AbstractElement-method-getMargin'> /**
  593. </span> * Returns an object with properties top, left, right and bottom representing the margins of this element unless sides is passed,
  594. * then it returns the calculated width of the sides (see getPadding)
  595. * @param {String} [sides] Any combination of l, r, t, b to get the sum of those sides
  596. * @return {Object/Number}
  597. */
  598. getMargin: function(side){
  599. var me = this,
  600. hash = {t:&quot;top&quot;, l:&quot;left&quot;, r:&quot;right&quot;, b: &quot;bottom&quot;},
  601. key,
  602. o,
  603. margins;
  604. if (!side) {
  605. margins = [];
  606. for (key in me.margins) {
  607. if(me.margins.hasOwnProperty(key)) {
  608. margins.push(me.margins[key]);
  609. }
  610. }
  611. o = me.getStyle(margins);
  612. if(o &amp;&amp; typeof o == 'object') {
  613. //now mixin nomalized values (from hash table)
  614. for (key in me.margins) {
  615. if(me.margins.hasOwnProperty(key)) {
  616. o[hash[key]] = parseFloat(o[me.margins[key]]) || 0;
  617. }
  618. }
  619. }
  620. return o;
  621. } else {
  622. return me.addStyles.call(me, side, me.margins);
  623. }
  624. },
  625. <span id='Ext-dom-AbstractElement-method-mask'> /**
  626. </span> * Puts a mask over this element to disable user interaction. Requires core.css.
  627. * This method can only be applied to elements which accept child nodes.
  628. * @param {String} [msg] A message to display in the mask
  629. * @param {String} [msgCls] A css class to apply to the msg element
  630. */
  631. mask: function(msg, msgCls, transparent) {
  632. var me = this,
  633. dom = me.dom,
  634. data = (me.$cache || me.getCache()).data,
  635. el = data.mask,
  636. mask,
  637. size,
  638. cls = '',
  639. prefix = Ext.baseCSSPrefix;
  640. me.addCls(prefix + 'masked');
  641. if (me.getStyle(&quot;position&quot;) == &quot;static&quot;) {
  642. me.addCls(prefix + 'masked-relative');
  643. }
  644. if (el) {
  645. el.remove();
  646. }
  647. if (msgCls &amp;&amp; typeof msgCls == 'string' ) {
  648. cls = ' ' + msgCls;
  649. }
  650. else {
  651. cls = ' ' + prefix + 'mask-gray';
  652. }
  653. mask = me.createChild({
  654. cls: prefix + 'mask' + ((transparent !== false) ? '' : (' ' + prefix + 'mask-gray')),
  655. html: msg ? ('&lt;div class=&quot;' + (msgCls || (prefix + 'mask-message')) + '&quot;&gt;' + msg + '&lt;/div&gt;') : ''
  656. });
  657. size = me.getSize();
  658. data.mask = mask;
  659. if (dom === document.body) {
  660. size.height = window.innerHeight;
  661. if (me.orientationHandler) {
  662. Ext.EventManager.unOrientationChange(me.orientationHandler, me);
  663. }
  664. me.orientationHandler = function() {
  665. size = me.getSize();
  666. size.height = window.innerHeight;
  667. mask.setSize(size);
  668. };
  669. Ext.EventManager.onOrientationChange(me.orientationHandler, me);
  670. }
  671. mask.setSize(size);
  672. if (Ext.is.iPad) {
  673. Ext.repaint();
  674. }
  675. },
  676. <span id='Ext-dom-AbstractElement-method-unmask'> /**
  677. </span> * Removes a previously applied mask.
  678. */
  679. unmask: function() {
  680. var me = this,
  681. data = (me.$cache || me.getCache()).data,
  682. mask = data.mask,
  683. prefix = Ext.baseCSSPrefix;
  684. if (mask) {
  685. mask.remove();
  686. delete data.mask;
  687. }
  688. me.removeCls([prefix + 'masked', prefix + 'masked-relative']);
  689. if (me.dom === document.body) {
  690. Ext.EventManager.unOrientationChange(me.orientationHandler, me);
  691. delete me.orientationHandler;
  692. }
  693. }
  694. });
  695. <span id='Ext-dom-AbstractElement-method-populateStyleMap'> /**
  696. </span> * Creates mappings for 'margin-before' to 'marginLeft' (etc.) given the output
  697. * map and an ordering pair (e.g., ['left', 'right']). The ordering pair is in
  698. * before/after order.
  699. */
  700. Element.populateStyleMap = function (map, order) {
  701. var baseStyles = ['margin-', 'padding-', 'border-width-'],
  702. beforeAfter = ['before', 'after'],
  703. index, style, name, i;
  704. for (index = baseStyles.length; index--; ) {
  705. for (i = 2; i--; ) {
  706. style = baseStyles[index] + beforeAfter[i]; // margin-before
  707. // ex: maps margin-before and marginBefore to marginLeft
  708. map[Element.normalize(style)] = map[style] = {
  709. name: Element.normalize(baseStyles[index] + order[i])
  710. };
  711. }
  712. }
  713. };
  714. Ext.onReady(function () {
  715. var supports = Ext.supports,
  716. styleHooks,
  717. colorStyles, i, name, camel;
  718. function fixTransparent (dom, el, inline, style) {
  719. var value = style[this.name] || '';
  720. return transparentRe.test(value) ? 'transparent' : value;
  721. }
  722. function fixRightMargin (dom, el, inline, style) {
  723. var result = style.marginRight,
  724. domStyle, display;
  725. // Ignore cases when the margin is correctly reported as 0, the bug only shows
  726. // numbers larger.
  727. if (result != '0px') {
  728. domStyle = dom.style;
  729. display = domStyle.display;
  730. domStyle.display = 'inline-block';
  731. result = (inline ? style : dom.ownerDocument.defaultView.getComputedStyle(dom, null)).marginRight;
  732. domStyle.display = display;
  733. }
  734. return result;
  735. }
  736. function fixRightMarginAndInputFocus (dom, el, inline, style) {
  737. var result = style.marginRight,
  738. domStyle, cleaner, display;
  739. if (result != '0px') {
  740. domStyle = dom.style;
  741. cleaner = Element.getRightMarginFixCleaner(dom);
  742. display = domStyle.display;
  743. domStyle.display = 'inline-block';
  744. result = (inline ? style : dom.ownerDocument.defaultView.getComputedStyle(dom, '')).marginRight;
  745. domStyle.display = display;
  746. cleaner();
  747. }
  748. return result;
  749. }
  750. styleHooks = Element.prototype.styleHooks;
  751. // Populate the LTR flavors of margin-before et.al. (see Ext.rtl.AbstractElement):
  752. Element.populateStyleMap(styleHooks, ['left', 'right']);
  753. // Ext.supports needs to be initialized (we run very early in the onready sequence),
  754. // but it is OK to call Ext.supports.init() more times than necessary...
  755. if (supports.init) {
  756. supports.init();
  757. }
  758. // Fix bug caused by this: https://bugs.webkit.org/show_bug.cgi?id=13343
  759. if (!supports.RightMargin) {
  760. styleHooks.marginRight = styleHooks['margin-right'] = {
  761. name: 'marginRight',
  762. // TODO - Touch should use conditional compilation here or ensure that the
  763. // underlying Ext.supports flags are set correctly...
  764. get: (supports.DisplayChangeInputSelectionBug || supports.DisplayChangeTextAreaSelectionBug) ?
  765. fixRightMarginAndInputFocus : fixRightMargin
  766. };
  767. }
  768. if (!supports.TransparentColor) {
  769. colorStyles = ['background-color', 'border-color', 'color', 'outline-color'];
  770. for (i = colorStyles.length; i--; ) {
  771. name = colorStyles[i];
  772. camel = Element.normalize(name);
  773. styleHooks[name] = styleHooks[camel] = {
  774. name: camel,
  775. get: fixTransparent
  776. };
  777. }
  778. }
  779. });
  780. }());
  781. </pre>
  782. </body>
  783. </html>