4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-core-Element'>/**
19 </span> * @class Ext.core.Element
22 Ext.core.Element.boxMarkup = '<div class="{0}-tl"><div class="{0}-tr"><div class="{0}-tc"></div></div></div><div class="{0}-ml"><div class="{0}-mr"><div class="{0}-mc"></div></div></div><div class="{0}-bl"><div class="{0}-br"><div class="{0}-bc"></div></div></div>';
23 // local style camelizing for speed
24 var supports = Ext.supports,
25 view = document.defaultView,
26 opacityRe = /alpha\(opacity=(.*)\)/i,
27 trimRe = /^\s+|\s+$/g,
30 adjustDirect2DTableRe = /table-row|table-.*-group/,
31 INTERNAL = '_internal',
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 = Ext.core.Element.data;
53 Ext.override(Ext.core.Element, {
55 <span id='Ext-core-Element-method-adjustWidth'> /**
56 </span> * TODO: Look at this
58 // private ==> used by Fx
59 adjustWidth : function(width) {
61 isNum = (typeof width == 'number');
63 if(isNum && me.autoBoxAdjust && !me.isBorderBox()){
64 width -= (me.getBorderWidth("lr") + me.getPadding("lr"));
66 return (isNum && width < 0) ? 0 : width;
69 // private ==> used by Fx
70 adjustHeight : function(height) {
72 isNum = (typeof height == "number");
74 if(isNum && me.autoBoxAdjust && !me.isBorderBox()){
75 height -= (me.getBorderWidth("tb") + me.getPadding("tb"));
77 return (isNum && height < 0) ? 0 : height;
81 <span id='Ext-core-Element-method-addCls'> /**
82 </span> * Adds one or more CSS classes to the element. Duplicate classes are automatically filtered out.
83 * @param {String/Array} className The CSS classes to add separated by space, or an array of classes
84 * @return {Ext.core.Element} this
86 addCls : function(className){
89 space = ((me.dom.className.replace(trimRe, '') == '') ? "" : " "),
91 if (className === undefined) {
94 // Separate case is for speed
95 if (Object.prototype.toString.call(className) !== '[object Array]') {
96 if (typeof className === 'string') {
97 className = className.replace(trimRe, '').split(spacesRe);
98 if (className.length === 1) {
99 className = className[0];
100 if (!me.hasCls(className)) {
101 me.dom.className += space + className;
104 this.addCls(className);
108 for (i = 0, len = className.length; i < len; i++) {
110 if (typeof v == 'string' && (' ' + me.dom.className + ' ').indexOf(' ' + v + ' ') == -1) {
115 me.dom.className += space + cls.join(" ");
121 <span id='Ext-core-Element-method-removeCls'> /**
122 </span> * Removes one or more CSS classes from the element.
123 * @param {String/Array} className The CSS classes to remove separated by space, or an array of classes
124 * @return {Ext.core.Element} this
126 removeCls : function(className){
128 i, idx, len, cls, elClasses;
129 if (className === undefined) {
132 if (Object.prototype.toString.call(className) !== '[object Array]') {
133 className = className.replace(trimRe, '').split(spacesRe);
135 if (me.dom && me.dom.className) {
136 elClasses = me.dom.className.replace(trimRe, '').split(spacesRe);
137 for (i = 0, len = className.length; i < len; i++) {
139 if (typeof cls == 'string') {
140 cls = cls.replace(trimRe, '');
141 idx = Ext.Array.indexOf(elClasses, cls);
143 Ext.Array.erase(elClasses, idx, 1);
147 me.dom.className = elClasses.join(" ");
152 <span id='Ext-core-Element-method-radioCls'> /**
153 </span> * Adds one or more CSS classes to this element and removes the same class(es) from all siblings.
154 * @param {String/Array} className The CSS class to add, or an array of classes
155 * @return {Ext.core.Element} this
157 radioCls : function(className){
158 var cn = this.dom.parentNode.childNodes,
160 className = Ext.isArray(className) ? className : [className];
161 for (i = 0, len = cn.length; i < len; i++) {
163 if (v && v.nodeType == 1) {
164 Ext.fly(v, '_internal').removeCls(className);
167 return this.addCls(className);
170 <span id='Ext-core-Element-method-toggleCls'> /**
171 </span> * Toggles the specified CSS class on this element (removes it if it already exists, otherwise adds it).
172 * @param {String} className The CSS class to toggle
173 * @return {Ext.core.Element} this
176 toggleCls : Ext.supports.ClassList ?
177 function(className) {
178 this.dom.classList.toggle(Ext.String.trim(className));
181 function(className) {
182 return this.hasCls(className) ? this.removeCls(className) : this.addCls(className);
185 <span id='Ext-core-Element-method-hasCls'> /**
186 </span> * Checks if the specified CSS class exists on this element's DOM node.
187 * @param {String} className The CSS class to check for
188 * @return {Boolean} True if the class exists, else false
191 hasCls : Ext.supports.ClassList ?
192 function(className) {
196 className = className.split(spacesRe);
197 var ln = className.length,
199 for (; i < ln; i++) {
200 if (className[i] && this.dom.classList.contains(className[i])) {
207 return className && (' ' + this.dom.className + ' ').indexOf(' ' + className + ' ') != -1;
210 <span id='Ext-core-Element-method-replaceCls'> /**
211 </span> * Replaces a CSS class on the element with another. If the old name does not exist, the new name will simply be added.
212 * @param {String} oldClassName The CSS class to replace
213 * @param {String} newClassName The replacement CSS class
214 * @return {Ext.core.Element} this
216 replaceCls : function(oldClassName, newClassName){
217 return this.removeCls(oldClassName).addCls(newClassName);
220 isStyle : function(style, val) {
221 return this.getStyle(style) == val;
224 <span id='Ext-core-Element-method-getStyle'> /**
225 </span> * Normalizes currentStyle and computedStyle.
226 * @param {String} property The style property whose value is returned.
227 * @return {String} The current value of the style property for this element.
230 getStyle : function(){
231 return view && view.getComputedStyle ?
234 v, cs, out, display, cleaner;
239 prop = Ext.core.Element.normalize(prop);
240 out = (v = el.style[prop]) ? v :
241 (cs = view.getComputedStyle(el, "")) ? cs[prop] : null;
243 // Ignore cases when the margin is correctly reported as 0, the bug only shows
245 if(prop == 'marginRight' && out != '0px' && !supports.RightMargin){
246 cleaner = Ext.core.Element.getRightMarginFixCleaner(el);
247 display = this.getStyle('display');
248 el.style.display = 'inline-block';
249 out = view.getComputedStyle(el, '').marginRight;
250 el.style.display = display;
254 if(prop == 'backgroundColor' && out == 'rgba(0, 0, 0, 0)' && !supports.TransparentColor){
263 if (el == document) {
267 if (prop == 'opacity') {
268 if (el.style.filter.match) {
269 m = el.style.filter.match(opacityRe);
271 var fv = parseFloat(m[1]);
273 return fv ? fv / 100 : 0;
279 prop = Ext.core.Element.normalize(prop);
280 return el.style[prop] || ((cs = el.currentStyle) ? cs[prop] : null);
284 <span id='Ext-core-Element-method-getColor'> /**
285 </span> * Return the CSS color for the specified CSS attribute. rgb, 3 digit (like #fff) and valid values
286 * are convert to standard 6 digit hex color.
287 * @param {String} attr The css attribute
288 * @param {String} defaultValue The default value to use when a valid color isn't found
289 * @param {String} prefix (optional) defaults to #. Use an empty string when working with
292 getColor : function(attr, defaultValue, prefix){
293 var v = this.getStyle(attr),
294 color = prefix || prefix === '' ? prefix : '#',
297 if(!v || (/transparent|inherit/.test(v))) {
301 Ext.each(v.slice(4, v.length -1).split(','), function(s){
303 color += (h < 16 ? '0' : '') + h.toString(16);
306 v = v.replace('#', '');
307 color += v.length == 3 ? v.replace(/^(\w)(\w)(\w)$/, '$1$1$2$2$3$3') : v;
309 return(color.length > 5 ? color.toLowerCase() : defaultValue);
312 <span id='Ext-core-Element-method-setStyle'> /**
313 </span> * Wrapper for setting style properties, also takes single object parameter of multiple styles.
314 * @param {String/Object} property The style property to be set, or an object of multiple styles.
315 * @param {String} value (optional) The value to apply to the given property, or null if an object was passed.
316 * @return {Ext.core.Element} this
318 setStyle : function(prop, value){
325 if (typeof prop === 'string') {
330 for (style in prop) {
331 if (prop.hasOwnProperty(style)) {
332 value = Ext.value(prop[style], '');
333 if (style == 'opacity') {
334 me.setOpacity(value);
337 me.dom.style[Ext.core.Element.normalize(style)] = value;
344 <span id='Ext-core-Element-method-setOpacity'> /**
345 </span> * Set the opacity of the element
346 * @param {Float} opacity The new opacity. 0 = transparent, .5 = 50% visibile, 1 = fully visible, etc
347 * @param {Boolean/Object} animate (optional) a standard Element animation config object or <tt>true</tt> for
348 * the default animation (<tt>{duration: .35, easing: 'easeIn'}</tt>)
349 * @return {Ext.core.Element} this
351 setOpacity: function(opacity, animate) {
361 style = me.dom.style;
363 if (!animate || !me.anim) {
364 if (!Ext.supports.Opacity) {
365 opacity = opacity < 1 ? 'alpha(opacity=' + opacity * 100 + ')': '';
366 val = style.filter.replace(opacityRe, '').replace(trimRe, '');
369 style.filter = val + (val.length > 0 ? ' ': '') + opacity;
372 style.opacity = opacity;
376 if (!Ext.isObject(animate)) {
382 me.animate(Ext.applyIf({
393 <span id='Ext-core-Element-method-clearOpacity'> /**
394 </span> * Clears any opacity settings from this element. Required in some cases for IE.
395 * @return {Ext.core.Element} this
397 clearOpacity : function(){
398 var style = this.dom.style;
399 if(!Ext.supports.Opacity){
400 if(!Ext.isEmpty(style.filter)){
401 style.filter = style.filter.replace(opacityRe, '').replace(trimRe, '');
404 style.opacity = style['-moz-opacity'] = style['-khtml-opacity'] = '';
409 <span id='Ext-core-Element-method-adjustDirect2DDimension'> /**
411 * Returns 1 if the browser returns the subpixel dimension rounded to the lowest pixel.
412 * @return {Number} 0 or 1
414 adjustDirect2DDimension: function(dimension) {
417 display = me.getStyle('display'),
418 inlineDisplay = dom.style['display'],
419 inlinePosition = dom.style['position'],
420 originIndex = dimension === 'width' ? 0 : 1,
423 if (display === 'inline') {
424 dom.style['display'] = 'inline-block';
427 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;
433 dom.style['position'] = inlinePosition;
435 if (display === 'inline') {
436 dom.style['display'] = inlineDisplay;
442 <span id='Ext-core-Element-method-getHeight'> /**
443 </span> * Returns the offset height of the element
444 * @param {Boolean} contentHeight (optional) true to get the height minus borders and padding
445 * @return {Number} The element's height
447 getHeight: function(contentHeight, preciseHeight) {
450 hidden = Ext.isIE && me.isStyle('display', 'none'),
451 height, overflow, style, floating;
453 // IE Quirks mode acts more like a max-size measurement unless overflow is hidden during measurement.
454 // We will put the overflow back to it's original value when we are done measuring.
455 if (Ext.isIEQuirks) {
457 overflow = style.overflow;
458 me.setStyle({ overflow: 'hidden'});
461 height = dom.offsetHeight;
463 height = MATH.max(height, hidden ? 0 : dom.clientHeight) || 0;
465 // IE9 Direct2D dimension rounding bug
466 if (!hidden && Ext.supports.Direct2DBug) {
467 floating = me.adjustDirect2DDimension('height');
471 else if (floating > 0 && floating < 0.5) {
477 height -= (me.getBorderWidth("tb") + me.getPadding("tb"));
480 if (Ext.isIEQuirks) {
481 me.setStyle({ overflow: overflow});
490 <span id='Ext-core-Element-method-getWidth'> /**
491 </span> * Returns the offset width of the element
492 * @param {Boolean} contentWidth (optional) true to get the width minus borders and padding
493 * @return {Number} The element's width
495 getWidth: function(contentWidth, preciseWidth) {
498 hidden = Ext.isIE && me.isStyle('display', 'none'),
499 rect, width, overflow, style, floating, parentPosition;
501 // IE Quirks mode acts more like a max-size measurement unless overflow is hidden during measurement.
502 // We will put the overflow back to it's original value when we are done measuring.
503 if (Ext.isIEQuirks) {
505 overflow = style.overflow;
506 me.setStyle({overflow: 'hidden'});
509 // Fix Opera 10.5x width calculation issues
510 if (Ext.isOpera10_5) {
511 if (dom.parentNode.currentStyle.position === 'relative') {
512 parentPosition = dom.parentNode.style.position;
513 dom.parentNode.style.position = 'static';
514 width = dom.offsetWidth;
515 dom.parentNode.style.position = parentPosition;
517 width = Math.max(width || 0, dom.offsetWidth);
519 // Gecko will in some cases report an offsetWidth that is actually less than the width of the
520 // text contents, because it measures fonts with sub-pixel precision but rounds the calculated
521 // value down. Using getBoundingClientRect instead of offsetWidth allows us to get the precise
522 // subpixel measurements so we can force them to always be rounded up. See
523 // https://bugzilla.mozilla.org/show_bug.cgi?id=458617
524 } else if (Ext.supports.BoundingClientRect) {
525 rect = dom.getBoundingClientRect();
526 width = rect.right - rect.left;
527 width = preciseWidth ? width : Math.ceil(width);
529 width = dom.offsetWidth;
532 width = MATH.max(width, hidden ? 0 : dom.clientWidth) || 0;
534 // IE9 Direct2D dimension rounding bug
535 if (!hidden && Ext.supports.Direct2DBug) {
536 floating = me.adjustDirect2DDimension('width');
540 else if (floating > 0 && floating < 0.5) {
546 width -= (me.getBorderWidth("lr") + me.getPadding("lr"));
549 if (Ext.isIEQuirks) {
550 me.setStyle({ overflow: overflow});
559 <span id='Ext-core-Element-method-setWidth'> /**
560 </span> * Set the width of this Element.
561 * @param {Mixed} width The new width. This may be one of:<div class="mdetail-params"><ul>
562 * <li>A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels).</li>
563 * <li>A String used to set the CSS width style. Animation may <b>not</b> be used.
564 * </ul></div>
565 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
566 * @return {Ext.core.Element} this
568 setWidth : function(width, animate){
570 width = me.adjustWidth(width);
571 if (!animate || !me.anim) {
572 me.dom.style.width = me.addUnits(width);
575 if (!Ext.isObject(animate)) {
578 me.animate(Ext.applyIf({
587 <span id='Ext-core-Element-method-setHeight'> /**
588 </span> * Set the height of this Element.
589 * <pre><code>
590 // change the height to 200px and animate with default configuration
591 Ext.fly('elementId').setHeight(200, true);
593 // change the height to 150px and animate with a custom configuration
594 Ext.fly('elId').setHeight(150, {
595 duration : .5, // animation will have a duration of .5 seconds
596 // will change the content to "finished"
597 callback: function(){ this.{@link #update}("finished"); }
599 * </code></pre>
600 * @param {Mixed} height The new height. This may be one of:<div class="mdetail-params"><ul>
601 * <li>A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels.)</li>
602 * <li>A String used to set the CSS height style. Animation may <b>not</b> be used.</li>
603 * </ul></div>
604 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
605 * @return {Ext.core.Element} this
607 setHeight : function(height, animate){
609 height = me.adjustHeight(height);
610 if (!animate || !me.anim) {
611 me.dom.style.height = me.addUnits(height);
614 if (!Ext.isObject(animate)) {
617 me.animate(Ext.applyIf({
626 <span id='Ext-core-Element-method-getBorderWidth'> /**
627 </span> * Gets the width of the border(s) for the specified side(s)
628 * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
629 * passing <tt>'lr'</tt> would get the border <b><u>l</u></b>eft width + the border <b><u>r</u></b>ight width.
630 * @return {Number} The width of the sides passed added together
632 getBorderWidth : function(side){
633 return this.addStyles(side, borders);
636 <span id='Ext-core-Element-method-getPadding'> /**
637 </span> * Gets the width of the padding(s) for the specified side(s)
638 * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
639 * passing <tt>'lr'</tt> would get the padding <b><u>l</u></b>eft + the padding <b><u>r</u></b>ight.
640 * @return {Number} The padding of the sides passed added together
642 getPadding : function(side){
643 return this.addStyles(side, paddings);
646 <span id='Ext-core-Element-method-clip'> /**
647 </span> * Store the current overflow setting and clip overflow on the element - use <tt>{@link #unclip}</tt> to remove
648 * @return {Ext.core.Element} this
654 if(!data(dom, ISCLIPPED)){
655 data(dom, ISCLIPPED, true);
656 data(dom, ORIGINALCLIP, {
657 o: me.getStyle(OVERFLOW),
658 x: me.getStyle(OVERFLOWX),
659 y: me.getStyle(OVERFLOWY)
661 me.setStyle(OVERFLOW, HIDDEN);
662 me.setStyle(OVERFLOWX, HIDDEN);
663 me.setStyle(OVERFLOWY, HIDDEN);
668 <span id='Ext-core-Element-method-unclip'> /**
669 </span> * Return clipping (overflow) to original clipping before <tt>{@link #clip}</tt> was called
670 * @return {Ext.core.Element} this
677 if(data(dom, ISCLIPPED)){
678 data(dom, ISCLIPPED, false);
679 clip = data(dom, ORIGINALCLIP);
681 me.setStyle(OVERFLOW, o.o);
684 me.setStyle(OVERFLOWX, o.x);
687 me.setStyle(OVERFLOWY, o.y);
694 addStyles : function(sides, styles){
696 sidesArr = sides.match(wordsRe),
698 len = sidesArr.length,
700 for (; i < len; i++) {
702 size = side && parseInt(this.getStyle(styles[side]), 10);
704 totalSize += MATH.abs(size);
712 <span id='Ext-core-Element-method-applyStyles'> /**
713 </span> * More flexible version of {@link #setStyle} for setting style properties.
714 * @param {String/Object/Function} styles A style specification string, e.g. "width:100px", or object in the form {width:"100px"}, or
715 * a function which returns such a specification.
716 * @return {Ext.core.Element} this
718 applyStyles : function(style){
719 Ext.core.DomHelper.applyStyles(this.dom, style);
723 <span id='Ext-core-Element-method-getStyles'> /**
724 </span> * Returns an object with properties matching the styles requested.
725 * For example, el.getStyles('color', 'font-size', 'width') might return
726 * {'color': '#FFFFFF', 'font-size': '13px', 'width': '100px'}.
727 * @param {String} style1 A style name
728 * @param {String} style2 A style name
729 * @param {String} etc.
730 * @return {Object} The style object
732 getStyles : function(){
734 len = arguments.length,
737 for(; i < len; ++i) {
738 style = arguments[i];
739 styles[style] = this.getStyle(style);
744 <span id='Ext-core-Element-method-boxWrap'> /**
745 </span> * <p>Wraps the specified element with a special 9 element markup/CSS block that renders by default as
746 * a gray container with a gradient background, rounded corners and a 4-way shadow.</p>
747 * <p>This special markup is used throughout Ext when box wrapping elements ({@link Ext.button.Button},
748 * {@link Ext.panel.Panel} when <tt>{@link Ext.panel.Panel#frame frame=true}</tt>, {@link Ext.window.Window}). The markup
749 * is of this form:</p>
750 * <pre><code>
751 Ext.core.Element.boxMarkup =
752 &#39;&lt;div class="{0}-tl">&lt;div class="{0}-tr">&lt;div class="{0}-tc">&lt;/div>&lt;/div>&lt;/div>
753 &lt;div class="{0}-ml">&lt;div class="{0}-mr">&lt;div class="{0}-mc">&lt;/div>&lt;/div>&lt;/div>
754 &lt;div class="{0}-bl">&lt;div class="{0}-br">&lt;div class="{0}-bc">&lt;/div>&lt;/div>&lt;/div>&#39;;
755 * </code></pre>
756 * <p>Example usage:</p>
757 * <pre><code>
759 Ext.get("foo").boxWrap();
761 // You can also add a custom class and use CSS inheritance rules to customize the box look.
762 // 'x-box-blue' is a built-in alternative -- look at the related CSS definitions as an example
763 // for how to create a custom box wrap style.
764 Ext.get("foo").boxWrap().addCls("x-box-blue");
765 * </code></pre>
766 * @param {String} class (optional) A base CSS class to apply to the containing wrapper element
767 * (defaults to <tt>'x-box'</tt>). Note that there are a number of CSS rules that are dependent on
768 * this name to make the overall effect work, so if you supply an alternate base class, make sure you
769 * also supply all of the necessary rules.
770 * @return {Ext.core.Element} The outermost wrapping element of the created box structure.
772 boxWrap : function(cls){
773 cls = cls || Ext.baseCSSPrefix + 'box';
774 var el = Ext.get(this.insertHtml("beforeBegin", "<div class='" + cls + "'>" + Ext.String.format(Ext.core.Element.boxMarkup, cls) + "</div>"));
775 Ext.DomQuery.selectNode('.' + cls + '-mc', el.dom).appendChild(this.dom);
779 <span id='Ext-core-Element-method-setSize'> /**
780 </span> * Set the size of this Element. If animation is true, both width and height will be animated concurrently.
781 * @param {Mixed} width The new width. This may be one of:<div class="mdetail-params"><ul>
782 * <li>A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels).</li>
783 * <li>A String used to set the CSS width style. Animation may <b>not</b> be used.
784 * <li>A size object in the format <code>{width: widthValue, height: heightValue}</code>.</li>
785 * </ul></div>
786 * @param {Mixed} height The new height. This may be one of:<div class="mdetail-params"><ul>
787 * <li>A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels).</li>
788 * <li>A String used to set the CSS height style. Animation may <b>not</b> be used.</li>
789 * </ul></div>
790 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
791 * @return {Ext.core.Element} this
793 setSize : function(width, height, animate){
795 if (Ext.isObject(width)) { // in case of object from getSize()
797 height = width.height;
800 width = me.adjustWidth(width);
801 height = me.adjustHeight(height);
802 if(!animate || !me.anim){
803 me.dom.style.width = me.addUnits(width);
804 me.dom.style.height = me.addUnits(height);
807 if (animate === true) {
810 me.animate(Ext.applyIf({
820 <span id='Ext-core-Element-method-getComputedHeight'> /**
821 </span> * Returns either the offsetHeight or the height of this element based on CSS height adjusted by padding or borders
822 * when needed to simulate offsetHeight when offsets aren't available. This may not work on display:none elements
823 * if a height has not been set using CSS.
826 getComputedHeight : function(){
828 h = Math.max(me.dom.offsetHeight, me.dom.clientHeight);
830 h = parseFloat(me.getStyle('height')) || 0;
831 if(!me.isBorderBox()){
832 h += me.getFrameWidth('tb');
838 <span id='Ext-core-Element-method-getComputedWidth'> /**
839 </span> * Returns either the offsetWidth or the width of this element based on CSS width adjusted by padding or borders
840 * when needed to simulate offsetWidth when offsets aren't available. This may not work on display:none elements
841 * if a width has not been set using CSS.
844 getComputedWidth : function(){
846 w = Math.max(me.dom.offsetWidth, me.dom.clientWidth);
849 w = parseFloat(me.getStyle('width')) || 0;
850 if(!me.isBorderBox()){
851 w += me.getFrameWidth('lr');
857 <span id='Ext-core-Element-method-getFrameWidth'> /**
858 </span> * Returns the sum width of the padding and borders for the passed "sides". See getBorderWidth()
859 for more information about the sides.
860 * @param {String} sides
863 getFrameWidth : function(sides, onlyContentBox){
864 return onlyContentBox && this.isBorderBox() ? 0 : (this.getPadding(sides) + this.getBorderWidth(sides));
867 <span id='Ext-core-Element-method-addClsOnOver'> /**
868 </span> * Sets up event handlers to add and remove a css class when the mouse is over this element
869 * @param {String} className
870 * @return {Ext.core.Element} this
872 addClsOnOver : function(className){
876 Ext.fly(dom, INTERNAL).addCls(className);
879 Ext.fly(dom, INTERNAL).removeCls(className);
885 <span id='Ext-core-Element-method-addClsOnFocus'> /**
886 </span> * Sets up event handlers to add and remove a css class when this element has the focus
887 * @param {String} className
888 * @return {Ext.core.Element} this
890 addClsOnFocus : function(className){
893 me.on("focus", function(){
894 Ext.fly(dom, INTERNAL).addCls(className);
896 me.on("blur", function(){
897 Ext.fly(dom, INTERNAL).removeCls(className);
902 <span id='Ext-core-Element-method-addClsOnClick'> /**
903 </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)
904 * @param {String} className
905 * @return {Ext.core.Element} this
907 addClsOnClick : function(className){
909 this.on("mousedown", function(){
910 Ext.fly(dom, INTERNAL).addCls(className);
911 var d = Ext.getDoc(),
913 Ext.fly(dom, INTERNAL).removeCls(className);
914 d.removeListener("mouseup", fn);
916 d.on("mouseup", fn);
921 <span id='Ext-core-Element-method-getViewSize'> /**
922 </span> * <p>Returns the dimensions of the element available to lay content out in.<p>
923 * <p>If the element (or any ancestor element) has CSS style <code>display : none</code>, the dimensions will be zero.</p>
924 * example:<pre><code>
925 var vpSize = Ext.getBody().getViewSize();
927 // all Windows created afterwards will have a default value of 90% height and 95% width
928 Ext.Window.override({
929 width: vpSize.width * 0.9,
930 height: vpSize.height * 0.95
932 // To handle window resizing you would have to hook onto onWindowResize.
933 * </code></pre>
935 * getViewSize utilizes clientHeight/clientWidth which excludes sizing of scrollbars.
936 * To obtain the size including scrollbars, use getStyleSize
938 * Sizing of the document body is handled at the adapter level which handles special cases for IE and strict modes, etc.
941 getViewSize : function(){
944 isDoc = (dom == Ext.getDoc().dom || dom == Ext.getBody().dom),
945 style, overflow, ret;
947 // If the body, use static methods
950 width : Ext.core.Element.getViewWidth(),
951 height : Ext.core.Element.getViewHeight()
954 // Else use clientHeight/clientWidth
957 // IE 6 & IE Quirks mode acts more like a max-size measurement unless overflow is hidden during measurement.
958 // We will put the overflow back to it's original value when we are done measuring.
959 if (Ext.isIE6 || Ext.isIEQuirks) {
961 overflow = style.overflow;
962 me.setStyle({ overflow: 'hidden'});
965 width : dom.clientWidth,
966 height : dom.clientHeight
968 if (Ext.isIE6 || Ext.isIEQuirks) {
969 me.setStyle({ overflow: overflow });
975 <span id='Ext-core-Element-method-getStyleSize'> /**
976 </span> * <p>Returns the dimensions of the element available to lay content out in.<p>
978 * getStyleSize utilizes prefers style sizing if present, otherwise it chooses the larger of offsetHeight/clientHeight and offsetWidth/clientWidth.
979 * To obtain the size excluding scrollbars, use getViewSize
981 * Sizing of the document body is handled at the adapter level which handles special cases for IE and strict modes, etc.
984 getStyleSize : function(){
988 isDoc = (d == doc || d == doc.body),
992 // If the body, use static methods
995 width : Ext.core.Element.getViewWidth(),
996 height : Ext.core.Element.getViewHeight()
999 // Use Styles if they are set
1000 if(s.width && s.width != 'auto'){
1001 w = parseFloat(s.width);
1002 if(me.isBorderBox()){
1003 w -= me.getFrameWidth('lr');
1006 // Use Styles if they are set
1007 if(s.height && s.height != 'auto'){
1008 h = parseFloat(s.height);
1009 if(me.isBorderBox()){
1010 h -= me.getFrameWidth('tb');
1013 // Use getWidth/getHeight if style not set.
1014 return {width: w || me.getWidth(true), height: h || me.getHeight(true)};
1017 <span id='Ext-core-Element-method-getSize'> /**
1018 </span> * Returns the size of the element.
1019 * @param {Boolean} contentSize (optional) true to get the width/size minus borders and padding
1020 * @return {Object} An object containing the element's size {width: (element width), height: (element height)}
1022 getSize : function(contentSize){
1023 return {width: this.getWidth(contentSize), height: this.getHeight(contentSize)};
1026 <span id='Ext-core-Element-method-repaint'> /**
1027 </span> * Forces the browser to repaint this element
1028 * @return {Ext.core.Element} this
1030 repaint : function(){
1032 this.addCls(Ext.baseCSSPrefix + 'repaint');
1033 setTimeout(function(){
1034 Ext.fly(dom).removeCls(Ext.baseCSSPrefix + 'repaint');
1039 <span id='Ext-core-Element-method-unselectable'> /**
1040 </span> * Disables text selection for this element (normalized across browsers)
1041 * @return {Ext.core.Element} this
1043 unselectable : function(){
1045 me.dom.unselectable = "on";
1047 me.swallowEvent("selectstart", true);
1048 me.applyStyles("-moz-user-select:none;-khtml-user-select:none;");
1049 me.addCls(Ext.baseCSSPrefix + 'unselectable');
1054 <span id='Ext-core-Element-method-getMargin'> /**
1055 </span> * Returns an object with properties top, left, right and bottom representing the margins of this element unless sides is passed,
1056 * then it returns the calculated width of the sides (see getPadding)
1057 * @param {String} sides (optional) Any combination of l, r, t, b to get the sum of those sides
1058 * @return {Object/Number}
1060 getMargin : function(side){
1062 hash = {t:"top", l:"left", r:"right", b: "bottom"},
1067 for (key in me.margins){
1068 o[hash[key]] = parseFloat(me.getStyle(me.margins[key])) || 0;
1072 return me.addStyles.call(me, side, me.margins);