PageRenderTime 910ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 1ms

/ext-4.0.7/docs/source/Element.style.html

https://bitbucket.org/srogerf/javascript
HTML | 1141 lines | 1040 code | 101 blank | 0 comment | 0 complexity | d741833c5720b5a2893f0444b3b3df07 MD5 | raw file
  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-Element'>/**
  19. </span> * @class Ext.Element
  20. */
  21. (function(){
  22. // local style camelizing for speed
  23. var ELEMENT = Ext.Element,
  24. supports = Ext.supports,
  25. view = document.defaultView,
  26. opacityRe = /alpha\(opacity=(.*)\)/i,
  27. trimRe = /^\s+|\s+$/g,
  28. spacesRe = /\s+/,
  29. wordsRe = /\w/g,
  30. adjustDirect2DTableRe = /table-row|table-.*-group/,
  31. INTERNAL = '_internal',
  32. PADDING = 'padding',
  33. MARGIN = 'margin',
  34. BORDER = 'border',
  35. LEFT = '-left',
  36. RIGHT = '-right',
  37. TOP = '-top',
  38. BOTTOM = '-bottom',
  39. WIDTH = '-width',
  40. MATH = Math,
  41. HIDDEN = 'hidden',
  42. ISCLIPPED = 'isClipped',
  43. OVERFLOW = 'overflow',
  44. OVERFLOWX = 'overflow-x',
  45. OVERFLOWY = 'overflow-y',
  46. ORIGINALCLIP = 'originalClip',
  47. // special markup used throughout Ext when box wrapping elements
  48. borders = {l: BORDER + LEFT + WIDTH, r: BORDER + RIGHT + WIDTH, t: BORDER + TOP + WIDTH, b: BORDER + BOTTOM + WIDTH},
  49. paddings = {l: PADDING + LEFT, r: PADDING + RIGHT, t: PADDING + TOP, b: PADDING + BOTTOM},
  50. margins = {l: MARGIN + LEFT, r: MARGIN + RIGHT, t: MARGIN + TOP, b: MARGIN + BOTTOM},
  51. data = ELEMENT.data;
  52. ELEMENT.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;';
  53. // These property values are read from the parentNode if they cannot be read
  54. // from the child:
  55. ELEMENT.inheritedProps = {
  56. fontSize: 1,
  57. fontStyle: 1,
  58. opacity: 1
  59. };
  60. Ext.override(ELEMENT, {
  61. <span id='Ext-Element-method-adjustWidth'> /**
  62. </span> * TODO: Look at this
  63. */
  64. // private ==&gt; used by Fx
  65. adjustWidth : function(width) {
  66. var me = this,
  67. isNum = (typeof width == 'number');
  68. if(isNum &amp;&amp; me.autoBoxAdjust &amp;&amp; !me.isBorderBox()){
  69. width -= (me.getBorderWidth(&quot;lr&quot;) + me.getPadding(&quot;lr&quot;));
  70. }
  71. return (isNum &amp;&amp; width &lt; 0) ? 0 : width;
  72. },
  73. // private ==&gt; used by Fx
  74. adjustHeight : function(height) {
  75. var me = this,
  76. isNum = (typeof height == &quot;number&quot;);
  77. if(isNum &amp;&amp; me.autoBoxAdjust &amp;&amp; !me.isBorderBox()){
  78. height -= (me.getBorderWidth(&quot;tb&quot;) + me.getPadding(&quot;tb&quot;));
  79. }
  80. return (isNum &amp;&amp; height &lt; 0) ? 0 : height;
  81. },
  82. <span id='Ext-Element-method-addCls'> /**
  83. </span> * Adds one or more CSS classes to the element. Duplicate classes are automatically filtered out.
  84. * @param {String/String[]} className The CSS classes to add separated by space, or an array of classes
  85. * @return {Ext.Element} this
  86. */
  87. addCls : function(className){
  88. var me = this,
  89. cls = [],
  90. space = ((me.dom.className.replace(trimRe, '') == '') ? &quot;&quot; : &quot; &quot;),
  91. i, len, v;
  92. if (className === undefined) {
  93. return me;
  94. }
  95. // Separate case is for speed
  96. if (Object.prototype.toString.call(className) !== '[object Array]') {
  97. if (typeof className === 'string') {
  98. className = className.replace(trimRe, '').split(spacesRe);
  99. if (className.length === 1) {
  100. className = className[0];
  101. if (!me.hasCls(className)) {
  102. me.dom.className += space + className;
  103. }
  104. } else {
  105. this.addCls(className);
  106. }
  107. }
  108. } else {
  109. for (i = 0, len = className.length; i &lt; len; i++) {
  110. v = className[i];
  111. if (typeof v == 'string' &amp;&amp; (' ' + me.dom.className + ' ').indexOf(' ' + v + ' ') == -1) {
  112. cls.push(v);
  113. }
  114. }
  115. if (cls.length) {
  116. me.dom.className += space + cls.join(&quot; &quot;);
  117. }
  118. }
  119. return me;
  120. },
  121. <span id='Ext-Element-method-removeCls'> /**
  122. </span> * Removes one or more CSS classes from the element.
  123. * @param {String/String[]} className The CSS classes to remove separated by space, or an array of classes
  124. * @return {Ext.Element} this
  125. */
  126. removeCls : function(className){
  127. var me = this,
  128. i, idx, len, cls, elClasses;
  129. if (className === undefined) {
  130. return me;
  131. }
  132. if (Object.prototype.toString.call(className) !== '[object Array]') {
  133. className = className.replace(trimRe, '').split(spacesRe);
  134. }
  135. if (me.dom &amp;&amp; me.dom.className) {
  136. elClasses = me.dom.className.replace(trimRe, '').split(spacesRe);
  137. for (i = 0, len = className.length; i &lt; len; i++) {
  138. cls = className[i];
  139. if (typeof cls == 'string') {
  140. cls = cls.replace(trimRe, '');
  141. idx = Ext.Array.indexOf(elClasses, cls);
  142. if (idx != -1) {
  143. Ext.Array.erase(elClasses, idx, 1);
  144. }
  145. }
  146. }
  147. me.dom.className = elClasses.join(&quot; &quot;);
  148. }
  149. return me;
  150. },
  151. <span id='Ext-Element-method-radioCls'> /**
  152. </span> * Adds one or more CSS classes to this element and removes the same class(es) from all siblings.
  153. * @param {String/String[]} className The CSS class to add, or an array of classes
  154. * @return {Ext.Element} this
  155. */
  156. radioCls : function(className){
  157. var cn = this.dom.parentNode.childNodes,
  158. v, i, len;
  159. className = Ext.isArray(className) ? className : [className];
  160. for (i = 0, len = cn.length; i &lt; len; i++) {
  161. v = cn[i];
  162. if (v &amp;&amp; v.nodeType == 1) {
  163. Ext.fly(v, '_internal').removeCls(className);
  164. }
  165. }
  166. return this.addCls(className);
  167. },
  168. <span id='Ext-Element-method-toggleCls'> /**
  169. </span> * Toggles the specified CSS class on this element (removes it if it already exists, otherwise adds it).
  170. * @param {String} className The CSS class to toggle
  171. * @return {Ext.Element} this
  172. * @method
  173. */
  174. toggleCls : Ext.supports.ClassList ?
  175. function(className) {
  176. this.dom.classList.toggle(Ext.String.trim(className));
  177. return this;
  178. } :
  179. function(className) {
  180. return this.hasCls(className) ? this.removeCls(className) : this.addCls(className);
  181. },
  182. <span id='Ext-Element-method-hasCls'> /**
  183. </span> * Checks if the specified CSS class exists on this element's DOM node.
  184. * @param {String} className The CSS class to check for
  185. * @return {Boolean} True if the class exists, else false
  186. * @method
  187. */
  188. hasCls : Ext.supports.ClassList ?
  189. function(className) {
  190. if (!className) {
  191. return false;
  192. }
  193. className = className.split(spacesRe);
  194. var ln = className.length,
  195. i = 0;
  196. for (; i &lt; ln; i++) {
  197. if (className[i] &amp;&amp; this.dom.classList.contains(className[i])) {
  198. return true;
  199. }
  200. }
  201. return false;
  202. } :
  203. function(className){
  204. return className &amp;&amp; (' ' + this.dom.className + ' ').indexOf(' ' + className + ' ') != -1;
  205. },
  206. <span id='Ext-Element-method-replaceCls'> /**
  207. </span> * Replaces a CSS class on the element with another. If the old name does not exist, the new name will simply be added.
  208. * @param {String} oldClassName The CSS class to replace
  209. * @param {String} newClassName The replacement CSS class
  210. * @return {Ext.Element} this
  211. */
  212. replaceCls : function(oldClassName, newClassName){
  213. return this.removeCls(oldClassName).addCls(newClassName);
  214. },
  215. isStyle : function(style, val) {
  216. return this.getStyle(style) == val;
  217. },
  218. <span id='Ext-Element-method-getStyle'> /**
  219. </span> * Normalizes currentStyle and computedStyle.
  220. * @param {String} property The style property whose value is returned.
  221. * @return {String} The current value of the style property for this element.
  222. * @method
  223. */
  224. getStyle : function() {
  225. return view &amp;&amp; view.getComputedStyle ?
  226. function(prop){
  227. var el = this.dom,
  228. v, cs, out, display, cleaner;
  229. if(el == document){
  230. return null;
  231. }
  232. prop = ELEMENT.normalize(prop);
  233. out = (v = el.style[prop]) ? v :
  234. (cs = view.getComputedStyle(el, &quot;&quot;)) ? cs[prop] : null;
  235. // Ignore cases when the margin is correctly reported as 0, the bug only shows
  236. // numbers larger.
  237. if(prop == 'marginRight' &amp;&amp; out != '0px' &amp;&amp; !supports.RightMargin){
  238. cleaner = ELEMENT.getRightMarginFixCleaner(el);
  239. display = this.getStyle('display');
  240. el.style.display = 'inline-block';
  241. out = view.getComputedStyle(el, '').marginRight;
  242. el.style.display = display;
  243. cleaner();
  244. }
  245. if(prop == 'backgroundColor' &amp;&amp; out == 'rgba(0, 0, 0, 0)' &amp;&amp; !supports.TransparentColor){
  246. out = 'transparent';
  247. }
  248. return out;
  249. } :
  250. function (prop) {
  251. var el = this.dom,
  252. m, cs;
  253. if (el == document) {
  254. return null;
  255. }
  256. prop = ELEMENT.normalize(prop);
  257. do {
  258. if (prop == 'opacity') {
  259. if (el.style.filter.match) {
  260. m = el.style.filter.match(opacityRe);
  261. if(m){
  262. var fv = parseFloat(m[1]);
  263. if(!isNaN(fv)){
  264. return fv ? fv / 100 : 0;
  265. }
  266. }
  267. }
  268. return 1;
  269. }
  270. // the try statement does have a cost, so we avoid it unless we are
  271. // on IE6
  272. if (!Ext.isIE6) {
  273. return el.style[prop] || ((cs = el.currentStyle) ? cs[prop] : null);
  274. }
  275. try {
  276. return el.style[prop] || ((cs = el.currentStyle) ? cs[prop] : null);
  277. } catch (e) {
  278. // in some cases, IE6 will throw Invalid Argument for properties
  279. // like fontSize (see in /examples/tabs/tabs.html).
  280. }
  281. if (!ELEMENT.inheritedProps[prop]) {
  282. break;
  283. }
  284. el = el.parentNode;
  285. // this is _not_ perfect, but we can only hope that the style we
  286. // need is inherited from a parentNode. If not and since IE won't
  287. // give us the info we need, we are never going to be 100% right.
  288. } while (el);
  289. //&lt;debug&gt;
  290. Ext.log({
  291. level: 'warn',
  292. msg: 'Failed to get ' + this.dom.id + '.currentStyle.' + prop
  293. });
  294. //&lt;/debug&gt;
  295. return null;
  296. }
  297. }(),
  298. <span id='Ext-Element-method-getColor'> /**
  299. </span> * Return the CSS color for the specified CSS attribute. rgb, 3 digit (like #fff) and valid values
  300. * are convert to standard 6 digit hex color.
  301. * @param {String} attr The css attribute
  302. * @param {String} defaultValue The default value to use when a valid color isn't found
  303. * @param {String} prefix (optional) defaults to #. Use an empty string when working with
  304. * color anims.
  305. */
  306. getColor : function(attr, defaultValue, prefix){
  307. var v = this.getStyle(attr),
  308. color = prefix || prefix === '' ? prefix : '#',
  309. h;
  310. if(!v || (/transparent|inherit/.test(v))) {
  311. return defaultValue;
  312. }
  313. if(/^r/.test(v)){
  314. Ext.each(v.slice(4, v.length -1).split(','), function(s){
  315. h = parseInt(s, 10);
  316. color += (h &lt; 16 ? '0' : '') + h.toString(16);
  317. });
  318. }else{
  319. v = v.replace('#', '');
  320. color += v.length == 3 ? v.replace(/^(\w)(\w)(\w)$/, '$1$1$2$2$3$3') : v;
  321. }
  322. return(color.length &gt; 5 ? color.toLowerCase() : defaultValue);
  323. },
  324. <span id='Ext-Element-method-setStyle'> /**
  325. </span> * Wrapper for setting style properties, also takes single object parameter of multiple styles.
  326. * @param {String/Object} property The style property to be set, or an object of multiple styles.
  327. * @param {String} value (optional) The value to apply to the given property, or null if an object was passed.
  328. * @return {Ext.Element} this
  329. */
  330. setStyle : function(prop, value){
  331. var me = this,
  332. tmp, style;
  333. if (!me.dom) {
  334. return me;
  335. }
  336. if (typeof prop === 'string') {
  337. tmp = {};
  338. tmp[prop] = value;
  339. prop = tmp;
  340. }
  341. for (style in prop) {
  342. if (prop.hasOwnProperty(style)) {
  343. value = Ext.value(prop[style], '');
  344. if (style == 'opacity') {
  345. me.setOpacity(value);
  346. }
  347. else {
  348. me.dom.style[ELEMENT.normalize(style)] = value;
  349. }
  350. }
  351. }
  352. return me;
  353. },
  354. <span id='Ext-Element-method-setOpacity'> /**
  355. </span> * Set the opacity of the element
  356. * @param {Number} opacity The new opacity. 0 = transparent, .5 = 50% visibile, 1 = fully visible, etc
  357. * @param {Boolean/Object} animate (optional) a standard Element animation config object or &lt;tt&gt;true&lt;/tt&gt; for
  358. * the default animation (&lt;tt&gt;{duration: .35, easing: 'easeIn'}&lt;/tt&gt;)
  359. * @return {Ext.Element} this
  360. */
  361. setOpacity: function(opacity, animate) {
  362. var me = this,
  363. dom = me.dom,
  364. val,
  365. style;
  366. if (!me.dom) {
  367. return me;
  368. }
  369. style = me.dom.style;
  370. if (!animate || !me.anim) {
  371. if (!Ext.supports.Opacity) {
  372. opacity = opacity &lt; 1 ? 'alpha(opacity=' + opacity * 100 + ')': '';
  373. val = style.filter.replace(opacityRe, '').replace(trimRe, '');
  374. style.zoom = 1;
  375. style.filter = val + (val.length &gt; 0 ? ' ': '') + opacity;
  376. }
  377. else {
  378. style.opacity = opacity;
  379. }
  380. }
  381. else {
  382. if (!Ext.isObject(animate)) {
  383. animate = {
  384. duration: 350,
  385. easing: 'ease-in'
  386. };
  387. }
  388. me.animate(Ext.applyIf({
  389. to: {
  390. opacity: opacity
  391. }
  392. },
  393. animate));
  394. }
  395. return me;
  396. },
  397. <span id='Ext-Element-method-clearOpacity'> /**
  398. </span> * Clears any opacity settings from this element. Required in some cases for IE.
  399. * @return {Ext.Element} this
  400. */
  401. clearOpacity : function(){
  402. var style = this.dom.style;
  403. if(!Ext.supports.Opacity){
  404. if(!Ext.isEmpty(style.filter)){
  405. style.filter = style.filter.replace(opacityRe, '').replace(trimRe, '');
  406. }
  407. }else{
  408. style.opacity = style['-moz-opacity'] = style['-khtml-opacity'] = '';
  409. }
  410. return this;
  411. },
  412. <span id='Ext-Element-method-adjustDirect2DDimension'> /**
  413. </span> * @private
  414. * Returns 1 if the browser returns the subpixel dimension rounded to the lowest pixel.
  415. * @return {Number} 0 or 1
  416. */
  417. adjustDirect2DDimension: function(dimension) {
  418. var me = this,
  419. dom = me.dom,
  420. display = me.getStyle('display'),
  421. inlineDisplay = dom.style['display'],
  422. inlinePosition = dom.style['position'],
  423. originIndex = dimension === 'width' ? 0 : 1,
  424. floating;
  425. if (display === 'inline') {
  426. dom.style['display'] = 'inline-block';
  427. }
  428. dom.style['position'] = display.match(adjustDirect2DTableRe) ? 'absolute' : 'static';
  429. // floating will contain digits that appears after the decimal point
  430. // if height or width are set to auto we fallback to msTransformOrigin calculation
  431. floating = (parseFloat(me.getStyle(dimension)) || parseFloat(dom.currentStyle.msTransformOrigin.split(' ')[originIndex]) * 2) % 1;
  432. dom.style['position'] = inlinePosition;
  433. if (display === 'inline') {
  434. dom.style['display'] = inlineDisplay;
  435. }
  436. return floating;
  437. },
  438. <span id='Ext-Element-method-getHeight'> /**
  439. </span> * Returns the offset height of the element
  440. * @param {Boolean} contentHeight (optional) true to get the height minus borders and padding
  441. * @return {Number} The element's height
  442. */
  443. getHeight: function(contentHeight, preciseHeight) {
  444. var me = this,
  445. dom = me.dom,
  446. hidden = Ext.isIE &amp;&amp; me.isStyle('display', 'none'),
  447. height, overflow, style, floating;
  448. // IE Quirks mode acts more like a max-size measurement unless overflow is hidden during measurement.
  449. // We will put the overflow back to it's original value when we are done measuring.
  450. if (Ext.isIEQuirks) {
  451. style = dom.style;
  452. overflow = style.overflow;
  453. me.setStyle({ overflow: 'hidden'});
  454. }
  455. height = dom.offsetHeight;
  456. height = MATH.max(height, hidden ? 0 : dom.clientHeight) || 0;
  457. // IE9 Direct2D dimension rounding bug
  458. if (!hidden &amp;&amp; Ext.supports.Direct2DBug) {
  459. floating = me.adjustDirect2DDimension('height');
  460. if (preciseHeight) {
  461. height += floating;
  462. }
  463. else if (floating &gt; 0 &amp;&amp; floating &lt; 0.5) {
  464. height++;
  465. }
  466. }
  467. if (contentHeight) {
  468. height -= (me.getBorderWidth(&quot;tb&quot;) + me.getPadding(&quot;tb&quot;));
  469. }
  470. if (Ext.isIEQuirks) {
  471. me.setStyle({ overflow: overflow});
  472. }
  473. if (height &lt; 0) {
  474. height = 0;
  475. }
  476. return height;
  477. },
  478. <span id='Ext-Element-method-getWidth'> /**
  479. </span> * Returns the offset width of the element
  480. * @param {Boolean} contentWidth (optional) true to get the width minus borders and padding
  481. * @return {Number} The element's width
  482. */
  483. getWidth: function(contentWidth, preciseWidth) {
  484. var me = this,
  485. dom = me.dom,
  486. hidden = Ext.isIE &amp;&amp; me.isStyle('display', 'none'),
  487. rect, width, overflow, style, floating, parentPosition;
  488. // IE Quirks mode acts more like a max-size measurement unless overflow is hidden during measurement.
  489. // We will put the overflow back to it's original value when we are done measuring.
  490. if (Ext.isIEQuirks) {
  491. style = dom.style;
  492. overflow = style.overflow;
  493. me.setStyle({overflow: 'hidden'});
  494. }
  495. // Fix Opera 10.5x width calculation issues
  496. if (Ext.isOpera10_5) {
  497. if (dom.parentNode.currentStyle.position === 'relative') {
  498. parentPosition = dom.parentNode.style.position;
  499. dom.parentNode.style.position = 'static';
  500. width = dom.offsetWidth;
  501. dom.parentNode.style.position = parentPosition;
  502. }
  503. width = Math.max(width || 0, dom.offsetWidth);
  504. // Gecko will in some cases report an offsetWidth that is actually less than the width of the
  505. // text contents, because it measures fonts with sub-pixel precision but rounds the calculated
  506. // value down. Using getBoundingClientRect instead of offsetWidth allows us to get the precise
  507. // subpixel measurements so we can force them to always be rounded up. See
  508. // https://bugzilla.mozilla.org/show_bug.cgi?id=458617
  509. } else if (Ext.supports.BoundingClientRect) {
  510. rect = dom.getBoundingClientRect();
  511. width = rect.right - rect.left;
  512. width = preciseWidth ? width : Math.ceil(width);
  513. } else {
  514. width = dom.offsetWidth;
  515. }
  516. width = MATH.max(width, hidden ? 0 : dom.clientWidth) || 0;
  517. // IE9 Direct2D dimension rounding bug
  518. if (!hidden &amp;&amp; Ext.supports.Direct2DBug) {
  519. floating = me.adjustDirect2DDimension('width');
  520. if (preciseWidth) {
  521. width += floating;
  522. }
  523. else if (floating &gt; 0 &amp;&amp; floating &lt; 0.5) {
  524. width++;
  525. }
  526. }
  527. if (contentWidth) {
  528. width -= (me.getBorderWidth(&quot;lr&quot;) + me.getPadding(&quot;lr&quot;));
  529. }
  530. if (Ext.isIEQuirks) {
  531. me.setStyle({ overflow: overflow});
  532. }
  533. if (width &lt; 0) {
  534. width = 0;
  535. }
  536. return width;
  537. },
  538. <span id='Ext-Element-method-setWidth'> /**
  539. </span> * Set the width of this Element.
  540. * @param {Number/String} width The new width. This may be one of:&lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  541. * &lt;li&gt;A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels).&lt;/li&gt;
  542. * &lt;li&gt;A String used to set the CSS width style. Animation may &lt;b&gt;not&lt;/b&gt; be used.
  543. * &lt;/ul&gt;&lt;/div&gt;
  544. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  545. * @return {Ext.Element} this
  546. */
  547. setWidth : function(width, animate){
  548. var me = this;
  549. width = me.adjustWidth(width);
  550. if (!animate || !me.anim) {
  551. me.dom.style.width = me.addUnits(width);
  552. }
  553. else {
  554. if (!Ext.isObject(animate)) {
  555. animate = {};
  556. }
  557. me.animate(Ext.applyIf({
  558. to: {
  559. width: width
  560. }
  561. }, animate));
  562. }
  563. return me;
  564. },
  565. <span id='Ext-Element-method-setHeight'> /**
  566. </span> * Set the height of this Element.
  567. * &lt;pre&gt;&lt;code&gt;
  568. // change the height to 200px and animate with default configuration
  569. Ext.fly('elementId').setHeight(200, true);
  570. // change the height to 150px and animate with a custom configuration
  571. Ext.fly('elId').setHeight(150, {
  572. duration : .5, // animation will have a duration of .5 seconds
  573. // will change the content to &quot;finished&quot;
  574. callback: function(){ this.{@link #update}(&quot;finished&quot;); }
  575. });
  576. * &lt;/code&gt;&lt;/pre&gt;
  577. * @param {Number/String} height The new height. This may be one of:&lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  578. * &lt;li&gt;A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels.)&lt;/li&gt;
  579. * &lt;li&gt;A String used to set the CSS height style. Animation may &lt;b&gt;not&lt;/b&gt; be used.&lt;/li&gt;
  580. * &lt;/ul&gt;&lt;/div&gt;
  581. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  582. * @return {Ext.Element} this
  583. */
  584. setHeight : function(height, animate){
  585. var me = this;
  586. height = me.adjustHeight(height);
  587. if (!animate || !me.anim) {
  588. me.dom.style.height = me.addUnits(height);
  589. }
  590. else {
  591. if (!Ext.isObject(animate)) {
  592. animate = {};
  593. }
  594. me.animate(Ext.applyIf({
  595. to: {
  596. height: height
  597. }
  598. }, animate));
  599. }
  600. return me;
  601. },
  602. <span id='Ext-Element-method-getBorderWidth'> /**
  603. </span> * Gets the width of the border(s) for the specified side(s)
  604. * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
  605. * passing &lt;tt&gt;'lr'&lt;/tt&gt; would get the border &lt;b&gt;&lt;u&gt;l&lt;/u&gt;&lt;/b&gt;eft width + the border &lt;b&gt;&lt;u&gt;r&lt;/u&gt;&lt;/b&gt;ight width.
  606. * @return {Number} The width of the sides passed added together
  607. */
  608. getBorderWidth : function(side){
  609. return this.addStyles(side, borders);
  610. },
  611. <span id='Ext-Element-method-getPadding'> /**
  612. </span> * Gets the width of the padding(s) for the specified side(s)
  613. * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
  614. * passing &lt;tt&gt;'lr'&lt;/tt&gt; would get the padding &lt;b&gt;&lt;u&gt;l&lt;/u&gt;&lt;/b&gt;eft + the padding &lt;b&gt;&lt;u&gt;r&lt;/u&gt;&lt;/b&gt;ight.
  615. * @return {Number} The padding of the sides passed added together
  616. */
  617. getPadding : function(side){
  618. return this.addStyles(side, paddings);
  619. },
  620. <span id='Ext-Element-method-clip'> /**
  621. </span> * Store the current overflow setting and clip overflow on the element - use &lt;tt&gt;{@link #unclip}&lt;/tt&gt; to remove
  622. * @return {Ext.Element} this
  623. */
  624. clip : function(){
  625. var me = this,
  626. dom = me.dom;
  627. if(!data(dom, ISCLIPPED)){
  628. data(dom, ISCLIPPED, true);
  629. data(dom, ORIGINALCLIP, {
  630. o: me.getStyle(OVERFLOW),
  631. x: me.getStyle(OVERFLOWX),
  632. y: me.getStyle(OVERFLOWY)
  633. });
  634. me.setStyle(OVERFLOW, HIDDEN);
  635. me.setStyle(OVERFLOWX, HIDDEN);
  636. me.setStyle(OVERFLOWY, HIDDEN);
  637. }
  638. return me;
  639. },
  640. <span id='Ext-Element-method-unclip'> /**
  641. </span> * Return clipping (overflow) to original clipping before &lt;tt&gt;{@link #clip}&lt;/tt&gt; was called
  642. * @return {Ext.Element} this
  643. */
  644. unclip : function(){
  645. var me = this,
  646. dom = me.dom,
  647. clip;
  648. if(data(dom, ISCLIPPED)){
  649. data(dom, ISCLIPPED, false);
  650. clip = data(dom, ORIGINALCLIP);
  651. if(clip.o){
  652. me.setStyle(OVERFLOW, clip.o);
  653. }
  654. if(clip.x){
  655. me.setStyle(OVERFLOWX, clip.x);
  656. }
  657. if(clip.y){
  658. me.setStyle(OVERFLOWY, clip.y);
  659. }
  660. }
  661. return me;
  662. },
  663. // private
  664. addStyles : function(sides, styles){
  665. var totalSize = 0,
  666. sidesArr = sides.match(wordsRe),
  667. i = 0,
  668. len = sidesArr.length,
  669. side, size;
  670. for (; i &lt; len; i++) {
  671. side = sidesArr[i];
  672. size = side &amp;&amp; parseInt(this.getStyle(styles[side]), 10);
  673. if (size) {
  674. totalSize += MATH.abs(size);
  675. }
  676. }
  677. return totalSize;
  678. },
  679. margins : margins,
  680. <span id='Ext-Element-method-applyStyles'> /**
  681. </span> * More flexible version of {@link #setStyle} for setting style properties.
  682. * @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
  683. * a function which returns such a specification.
  684. * @return {Ext.Element} this
  685. */
  686. applyStyles : function(style){
  687. Ext.DomHelper.applyStyles(this.dom, style);
  688. return this;
  689. },
  690. <span id='Ext-Element-method-getStyles'> /**
  691. </span> * Returns an object with properties matching the styles requested.
  692. * For example, el.getStyles('color', 'font-size', 'width') might return
  693. * {'color': '#FFFFFF', 'font-size': '13px', 'width': '100px'}.
  694. * @param {String} style1 A style name
  695. * @param {String} style2 A style name
  696. * @param {String} etc.
  697. * @return {Object} The style object
  698. */
  699. getStyles : function(){
  700. var styles = {},
  701. len = arguments.length,
  702. i = 0, style;
  703. for(; i &lt; len; ++i) {
  704. style = arguments[i];
  705. styles[style] = this.getStyle(style);
  706. }
  707. return styles;
  708. },
  709. <span id='Ext-Element-method-boxWrap'> /**
  710. </span> * &lt;p&gt;Wraps the specified element with a special 9 element markup/CSS block that renders by default as
  711. * a gray container with a gradient background, rounded corners and a 4-way shadow.&lt;/p&gt;
  712. * &lt;p&gt;This special markup is used throughout Ext when box wrapping elements ({@link Ext.button.Button},
  713. * {@link Ext.panel.Panel} when &lt;tt&gt;{@link Ext.panel.Panel#frame frame=true}&lt;/tt&gt;, {@link Ext.window.Window}). The markup
  714. * is of this form:&lt;/p&gt;
  715. * &lt;pre&gt;&lt;code&gt;
  716. Ext.Element.boxMarkup =
  717. &amp;#39;&amp;lt;div class=&quot;{0}-tl&quot;&gt;&amp;lt;div class=&quot;{0}-tr&quot;&gt;&amp;lt;div class=&quot;{0}-tc&quot;&gt;&amp;lt;/div&gt;&amp;lt;/div&gt;&amp;lt;/div&gt;
  718. &amp;lt;div class=&quot;{0}-ml&quot;&gt;&amp;lt;div class=&quot;{0}-mr&quot;&gt;&amp;lt;div class=&quot;{0}-mc&quot;&gt;&amp;lt;/div&gt;&amp;lt;/div&gt;&amp;lt;/div&gt;
  719. &amp;lt;div class=&quot;{0}-bl&quot;&gt;&amp;lt;div class=&quot;{0}-br&quot;&gt;&amp;lt;div class=&quot;{0}-bc&quot;&gt;&amp;lt;/div&gt;&amp;lt;/div&gt;&amp;lt;/div&gt;&amp;#39;;
  720. * &lt;/code&gt;&lt;/pre&gt;
  721. * &lt;p&gt;Example usage:&lt;/p&gt;
  722. * &lt;pre&gt;&lt;code&gt;
  723. // Basic box wrap
  724. Ext.get(&quot;foo&quot;).boxWrap();
  725. // You can also add a custom class and use CSS inheritance rules to customize the box look.
  726. // 'x-box-blue' is a built-in alternative -- look at the related CSS definitions as an example
  727. // for how to create a custom box wrap style.
  728. Ext.get(&quot;foo&quot;).boxWrap().addCls(&quot;x-box-blue&quot;);
  729. * &lt;/code&gt;&lt;/pre&gt;
  730. * @param {String} class (optional) A base CSS class to apply to the containing wrapper element
  731. * (defaults to &lt;tt&gt;'x-box'&lt;/tt&gt;). Note that there are a number of CSS rules that are dependent on
  732. * this name to make the overall effect work, so if you supply an alternate base class, make sure you
  733. * also supply all of the necessary rules.
  734. * @return {Ext.Element} The outermost wrapping element of the created box structure.
  735. */
  736. boxWrap : function(cls){
  737. cls = cls || Ext.baseCSSPrefix + 'box';
  738. var el = Ext.get(this.insertHtml(&quot;beforeBegin&quot;, &quot;&lt;div class='&quot; + cls + &quot;'&gt;&quot; + Ext.String.format(ELEMENT.boxMarkup, cls) + &quot;&lt;/div&gt;&quot;));
  739. Ext.DomQuery.selectNode('.' + cls + '-mc', el.dom).appendChild(this.dom);
  740. return el;
  741. },
  742. <span id='Ext-Element-method-setSize'> /**
  743. </span> * Set the size of this Element. If animation is true, both width and height will be animated concurrently.
  744. * @param {Number/String} width The new width. This may be one of:&lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  745. * &lt;li&gt;A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels).&lt;/li&gt;
  746. * &lt;li&gt;A String used to set the CSS width style. Animation may &lt;b&gt;not&lt;/b&gt; be used.
  747. * &lt;li&gt;A size object in the format &lt;code&gt;{width: widthValue, height: heightValue}&lt;/code&gt;.&lt;/li&gt;
  748. * &lt;/ul&gt;&lt;/div&gt;
  749. * @param {Number/String} height The new height. This may be one of:&lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  750. * &lt;li&gt;A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels).&lt;/li&gt;
  751. * &lt;li&gt;A String used to set the CSS height style. Animation may &lt;b&gt;not&lt;/b&gt; be used.&lt;/li&gt;
  752. * &lt;/ul&gt;&lt;/div&gt;
  753. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  754. * @return {Ext.Element} this
  755. */
  756. setSize : function(width, height, animate){
  757. var me = this;
  758. if (Ext.isObject(width)) { // in case of object from getSize()
  759. animate = height;
  760. height = width.height;
  761. width = width.width;
  762. }
  763. width = me.adjustWidth(width);
  764. height = me.adjustHeight(height);
  765. if(!animate || !me.anim){
  766. // Must touch some property before setting style.width/height on non-quirk IE6,7, or the
  767. // properties will not reflect the changes on the style immediately
  768. if (!Ext.isIEQuirks &amp;&amp; (Ext.isIE6 || Ext.isIE7)) {
  769. me.dom.offsetTop;
  770. }
  771. me.dom.style.width = me.addUnits(width);
  772. me.dom.style.height = me.addUnits(height);
  773. }
  774. else {
  775. if (animate === true) {
  776. animate = {};
  777. }
  778. me.animate(Ext.applyIf({
  779. to: {
  780. width: width,
  781. height: height
  782. }
  783. }, animate));
  784. }
  785. return me;
  786. },
  787. <span id='Ext-Element-method-getComputedHeight'> /**
  788. </span> * Returns either the offsetHeight or the height of this element based on CSS height adjusted by padding or borders
  789. * when needed to simulate offsetHeight when offsets aren't available. This may not work on display:none elements
  790. * if a height has not been set using CSS.
  791. * @return {Number}
  792. */
  793. getComputedHeight : function(){
  794. var me = this,
  795. h = Math.max(me.dom.offsetHeight, me.dom.clientHeight);
  796. if(!h){
  797. h = parseFloat(me.getStyle('height')) || 0;
  798. if(!me.isBorderBox()){
  799. h += me.getFrameWidth('tb');
  800. }
  801. }
  802. return h;
  803. },
  804. <span id='Ext-Element-method-getComputedWidth'> /**
  805. </span> * Returns either the offsetWidth or the width of this element based on CSS width adjusted by padding or borders
  806. * when needed to simulate offsetWidth when offsets aren't available. This may not work on display:none elements
  807. * if a width has not been set using CSS.
  808. * @return {Number}
  809. */
  810. getComputedWidth : function(){
  811. var me = this,
  812. w = Math.max(me.dom.offsetWidth, me.dom.clientWidth);
  813. if(!w){
  814. w = parseFloat(me.getStyle('width')) || 0;
  815. if(!me.isBorderBox()){
  816. w += me.getFrameWidth('lr');
  817. }
  818. }
  819. return w;
  820. },
  821. <span id='Ext-Element-method-getFrameWidth'> /**
  822. </span> * Returns the sum width of the padding and borders for the passed &quot;sides&quot;. See getBorderWidth()
  823. for more information about the sides.
  824. * @param {String} sides
  825. * @return {Number}
  826. */
  827. getFrameWidth : function(sides, onlyContentBox){
  828. return onlyContentBox &amp;&amp; this.isBorderBox() ? 0 : (this.getPadding(sides) + this.getBorderWidth(sides));
  829. },
  830. <span id='Ext-Element-method-addClsOnOver'> /**
  831. </span> * Sets up event handlers to add and remove a css class when the mouse is over this element
  832. * @param {String} className
  833. * @return {Ext.Element} this
  834. */
  835. addClsOnOver : function(className){
  836. var dom = this.dom;
  837. this.hover(
  838. function(){
  839. Ext.fly(dom, INTERNAL).addCls(className);
  840. },
  841. function(){
  842. Ext.fly(dom, INTERNAL).removeCls(className);
  843. }
  844. );
  845. return this;
  846. },
  847. <span id='Ext-Element-method-addClsOnFocus'> /**
  848. </span> * Sets up event handlers to add and remove a css class when this element has the focus
  849. * @param {String} className
  850. * @return {Ext.Element} this
  851. */
  852. addClsOnFocus : function(className){
  853. var me = this,
  854. dom = me.dom;
  855. me.on(&quot;focus&quot;, function(){
  856. Ext.fly(dom, INTERNAL).addCls(className);
  857. });
  858. me.on(&quot;blur&quot;, function(){
  859. Ext.fly(dom, INTERNAL).removeCls(className);
  860. });
  861. return me;
  862. },
  863. <span id='Ext-Element-method-addClsOnClick'> /**
  864. </span> * Sets up event handlers to add and remove a css class when the mouse is down and then up on this element (a click effect)
  865. * @param {String} className
  866. * @return {Ext.Element} this
  867. */
  868. addClsOnClick : function(className){
  869. var dom = this.dom;
  870. this.on(&quot;mousedown&quot;, function(){
  871. Ext.fly(dom, INTERNAL).addCls(className);
  872. var d = Ext.getDoc(),
  873. fn = function(){
  874. Ext.fly(dom, INTERNAL).removeCls(className);
  875. d.removeListener(&quot;mouseup&quot;, fn);
  876. };
  877. d.on(&quot;mouseup&quot;, fn);
  878. });
  879. return this;
  880. },
  881. <span id='Ext-Element-method-getViewSize'> /**
  882. </span> * &lt;p&gt;Returns the dimensions of the element available to lay content out in.&lt;p&gt;
  883. * &lt;p&gt;If the element (or any ancestor element) has CSS style &lt;code&gt;display : none&lt;/code&gt;, the dimensions will be zero.&lt;/p&gt;
  884. * example:&lt;pre&gt;&lt;code&gt;
  885. var vpSize = Ext.getBody().getViewSize();
  886. // all Windows created afterwards will have a default value of 90% height and 95% width
  887. Ext.Window.override({
  888. width: vpSize.width * 0.9,
  889. height: vpSize.height * 0.95
  890. });
  891. // To handle window resizing you would have to hook onto onWindowResize.
  892. * &lt;/code&gt;&lt;/pre&gt;
  893. *
  894. * getViewSize utilizes clientHeight/clientWidth which excludes sizing of scrollbars.
  895. * To obtain the size including scrollbars, use getStyleSize
  896. *
  897. * Sizing of the document body is handled at the adapter level which handles special cases for IE and strict modes, etc.
  898. */
  899. getViewSize : function(){
  900. var me = this,
  901. dom = me.dom,
  902. isDoc = (dom == Ext.getDoc().dom || dom == Ext.getBody().dom),
  903. style, overflow, ret;
  904. // If the body, use static methods
  905. if (isDoc) {
  906. ret = {
  907. width : ELEMENT.getViewWidth(),
  908. height : ELEMENT.getViewHeight()
  909. };
  910. // Else use clientHeight/clientWidth
  911. }
  912. else {
  913. // IE 6 &amp; IE Quirks mode acts more like a max-size measurement unless overflow is hidden during measurement.
  914. // We will put the overflow back to it's original value when we are done measuring.
  915. if (Ext.isIE6 || Ext.isIEQuirks) {
  916. style = dom.style;
  917. overflow = style.overflow;
  918. me.setStyle({ overflow: 'hidden'});
  919. }
  920. ret = {
  921. width : dom.clientWidth,
  922. height : dom.clientHeight
  923. };
  924. if (Ext.isIE6 || Ext.isIEQuirks) {
  925. me.setStyle({ overflow: overflow });
  926. }
  927. }
  928. return ret;
  929. },
  930. <span id='Ext-Element-method-getStyleSize'> /**
  931. </span> * &lt;p&gt;Returns the dimensions of the element available to lay content out in.&lt;p&gt;
  932. *
  933. * getStyleSize utilizes prefers style sizing if present, otherwise it chooses the larger of offsetHeight/clientHeight and offsetWidth/clientWidth.
  934. * To obtain the size excluding scrollbars, use getViewSize
  935. *
  936. * Sizing of the document body is handled at the adapter level which handles special cases for IE and strict modes, etc.
  937. */
  938. getStyleSize : function(){
  939. var me = this,
  940. doc = document,
  941. d = this.dom,
  942. isDoc = (d == doc || d == doc.body),
  943. s = d.style,
  944. w, h;
  945. // If the body, use static methods
  946. if (isDoc) {
  947. return {
  948. width : ELEMENT.getViewWidth(),
  949. height : ELEMENT.getViewHeight()
  950. };
  951. }
  952. // Use Styles if they are set
  953. if(s.width &amp;&amp; s.width != 'auto'){
  954. w = parseFloat(s.width);
  955. if(me.isBorderBox()){
  956. w -= me.getFrameWidth('lr');
  957. }
  958. }
  959. // Use Styles if they are set
  960. if(s.height &amp;&amp; s.height != 'auto'){
  961. h = parseFloat(s.height);
  962. if(me.isBorderBox()){
  963. h -= me.getFrameWidth('tb');
  964. }
  965. }
  966. // Use getWidth/getHeight if style not set.
  967. return {width: w || me.getWidth(true), height: h || me.getHeight(true)};
  968. },
  969. <span id='Ext-Element-method-getSize'> /**
  970. </span> * Returns the size of the element.
  971. * @param {Boolean} contentSize (optional) true to get the width/size minus borders and padding
  972. * @return {Object} An object containing the element's size {width: (element width), height: (element height)}
  973. */
  974. getSize : function(contentSize){
  975. return {width: this.getWidth(contentSize), height: this.getHeight(contentSize)};
  976. },
  977. <span id='Ext-Element-method-repaint'> /**
  978. </span> * Forces the browser to repaint this element
  979. * @return {Ext.Element} this
  980. */
  981. repaint : function(){
  982. var dom = this.dom;
  983. this.addCls(Ext.baseCSSPrefix + 'repaint');
  984. setTimeout(function(){
  985. Ext.fly(dom).removeCls(Ext.baseCSSPrefix + 'repaint');
  986. }, 1);
  987. return this;
  988. },
  989. <span id='Ext-Element-method-selectable'> /**
  990. </span> * Enable text selection for this element (normalized across browsers)
  991. * @return {Ext.Element} this
  992. */
  993. selectable : function() {
  994. var me = this;
  995. me.dom.unselectable = &quot;off&quot;;
  996. // Prevent it from bubles up and enables it to be selectable
  997. me.on('selectstart', function (e) {
  998. e.stopPropagation();
  999. return true;
  1000. });
  1001. me.applyStyles(&quot;-moz-user-select: text; -khtml-user-select: text;&quot;);
  1002. me.removeCls(Ext.baseCSSPrefix + 'unselectable');
  1003. return me;
  1004. },
  1005. <span id='Ext-Element-method-unselectable'> /**
  1006. </span> * Disables text selection for this element (normalized across browsers)
  1007. * @return {Ext.Element} this
  1008. */
  1009. unselectable : function(){
  1010. var me = this;
  1011. me.dom.unselectable = &quot;on&quot;;
  1012. me.swallowEvent(&quot;selectstart&quot;, true);
  1013. me.applyStyles(&quot;-moz-user-select:-moz-none;-khtml-user-select:none;&quot;);
  1014. me.addCls(Ext.baseCSSPrefix + 'unselectable');
  1015. return me;
  1016. },
  1017. <span id='Ext-Element-method-getMargin'> /**
  1018. </span> * Returns an object with properties top, left, right and bottom representing the margins of this element unless sides is passed,
  1019. * then it returns the calculated width of the sides (see getPadding)
  1020. * @param {String} sides (optional) Any combination of l, r, t, b to get the sum of those sides
  1021. * @return {Object/Number}
  1022. */
  1023. getMargin : function(side){
  1024. var me = this,
  1025. hash = {t:&quot;top&quot;, l:&quot;left&quot;, r:&quot;right&quot;, b: &quot;bottom&quot;},
  1026. o = {},
  1027. key;
  1028. if (!side) {
  1029. for (key in me.margins){
  1030. o[hash[key]] = parseFloat(me.getStyle(me.margins[key])) || 0;
  1031. }
  1032. return o;
  1033. } else {
  1034. return me.addStyles.call(me, side, me.margins);
  1035. }
  1036. }
  1037. });
  1038. })();</pre>
  1039. </body>
  1040. </html>