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; }
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-Element'>/**
19 </span> * @class Ext.Element
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,
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},
53 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>';
55 // These property values are read from the parentNode if they cannot be read
57 ELEMENT.inheritedProps = {
63 Ext.override(ELEMENT, {
65 <span id='Ext-Element-method-adjustWidth'> /**
66 </span> * TODO: Look at this
68 // private ==> used by Fx
69 adjustWidth : function(width) {
71 isNum = (typeof width == 'number');
73 if(isNum && me.autoBoxAdjust && !me.isBorderBox()){
74 width -= (me.getBorderWidth("lr") + me.getPadding("lr"));
76 return (isNum && width < 0) ? 0 : width;
79 // private ==> used by Fx
80 adjustHeight : function(height) {
82 isNum = (typeof height == "number");
84 if(isNum && me.autoBoxAdjust && !me.isBorderBox()){
85 height -= (me.getBorderWidth("tb") + me.getPadding("tb"));
87 return (isNum && height < 0) ? 0 : height;
91 <span id='Ext-Element-method-addCls'> /**
92 </span> * Adds one or more CSS classes to the element. Duplicate classes are automatically filtered out.
93 * @param {String/String[]} className The CSS classes to add separated by space, or an array of classes
94 * @return {Ext.Element} this
96 addCls : function(className){
99 space = ((me.dom.className.replace(trimRe, '') == '') ? "" : " "),
101 if (className === undefined) {
104 // Separate case is for speed
105 if (Object.prototype.toString.call(className) !== '[object Array]') {
106 if (typeof className === 'string') {
107 className = className.replace(trimRe, '').split(spacesRe);
108 if (className.length === 1) {
109 className = className[0];
110 if (!me.hasCls(className)) {
111 me.dom.className += space + className;
114 this.addCls(className);
118 for (i = 0, len = className.length; i < len; i++) {
120 if (typeof v == 'string' && (' ' + me.dom.className + ' ').indexOf(' ' + v + ' ') == -1) {
125 me.dom.className += space + cls.join(" ");
131 <span id='Ext-Element-method-removeCls'> /**
132 </span> * Removes one or more CSS classes from the element.
133 * @param {String/String[]} className The CSS classes to remove separated by space, or an array of classes
134 * @return {Ext.Element} this
136 removeCls : function(className){
138 i, idx, len, cls, elClasses;
139 if (className === undefined) {
142 if (Object.prototype.toString.call(className) !== '[object Array]') {
143 className = className.replace(trimRe, '').split(spacesRe);
145 if (me.dom && me.dom.className) {
146 elClasses = me.dom.className.replace(trimRe, '').split(spacesRe);
147 for (i = 0, len = className.length; i < len; i++) {
149 if (typeof cls == 'string') {
150 cls = cls.replace(trimRe, '');
151 idx = Ext.Array.indexOf(elClasses, cls);
153 Ext.Array.erase(elClasses, idx, 1);
157 me.dom.className = elClasses.join(" ");
162 <span id='Ext-Element-method-radioCls'> /**
163 </span> * Adds one or more CSS classes to this element and removes the same class(es) from all siblings.
164 * @param {String/String[]} className The CSS class to add, or an array of classes
165 * @return {Ext.Element} this
167 radioCls : function(className){
168 var cn = this.dom.parentNode.childNodes,
170 className = Ext.isArray(className) ? className : [className];
171 for (i = 0, len = cn.length; i < len; i++) {
173 if (v && v.nodeType == 1) {
174 Ext.fly(v, '_internal').removeCls(className);
177 return this.addCls(className);
180 <span id='Ext-Element-method-toggleCls'> /**
181 </span> * Toggles the specified CSS class on this element (removes it if it already exists, otherwise adds it).
182 * @param {String} className The CSS class to toggle
183 * @return {Ext.Element} this
186 toggleCls : Ext.supports.ClassList ?
187 function(className) {
188 this.dom.classList.toggle(Ext.String.trim(className));
191 function(className) {
192 return this.hasCls(className) ? this.removeCls(className) : this.addCls(className);
195 <span id='Ext-Element-method-hasCls'> /**
196 </span> * Checks if the specified CSS class exists on this element's DOM node.
197 * @param {String} className The CSS class to check for
198 * @return {Boolean} True if the class exists, else false
201 hasCls : Ext.supports.ClassList ?
202 function(className) {
206 className = className.split(spacesRe);
207 var ln = className.length,
209 for (; i < ln; i++) {
210 if (className[i] && this.dom.classList.contains(className[i])) {
217 return className && (' ' + this.dom.className + ' ').indexOf(' ' + className + ' ') != -1;
220 <span id='Ext-Element-method-replaceCls'> /**
221 </span> * Replaces a CSS class on the element with another. If the old name does not exist, the new name will simply be added.
222 * @param {String} oldClassName The CSS class to replace
223 * @param {String} newClassName The replacement CSS class
224 * @return {Ext.Element} this
226 replaceCls : function(oldClassName, newClassName){
227 return this.removeCls(oldClassName).addCls(newClassName);
230 isStyle : function(style, val) {
231 return this.getStyle(style) == val;
234 <span id='Ext-Element-method-getStyle'> /**
235 </span> * Normalizes currentStyle and computedStyle.
236 * @param {String} property The style property whose value is returned.
237 * @return {String} The current value of the style property for this element.
240 getStyle : function() {
241 return view && view.getComputedStyle ?
244 v, cs, out, display, cleaner;
249 prop = ELEMENT.normalize(prop);
250 out = (v = el.style[prop]) ? v :
251 (cs = view.getComputedStyle(el, "")) ? cs[prop] : null;
253 // Ignore cases when the margin is correctly reported as 0, the bug only shows
255 if(prop == 'marginRight' && out != '0px' && !supports.RightMargin){
256 cleaner = ELEMENT.getRightMarginFixCleaner(el);
257 display = this.getStyle('display');
258 el.style.display = 'inline-block';
259 out = view.getComputedStyle(el, '').marginRight;
260 el.style.display = display;
264 if(prop == 'backgroundColor' && out == 'rgba(0, 0, 0, 0)' && !supports.TransparentColor){
273 if (el == document) {
276 prop = ELEMENT.normalize(prop);
279 if (prop == 'opacity') {
280 if (el.style.filter.match) {
281 m = el.style.filter.match(opacityRe);
283 var fv = parseFloat(m[1]);
285 return fv ? fv / 100 : 0;
292 // the try statement does have a cost, so we avoid it unless we are
295 return el.style[prop] || ((cs = el.currentStyle) ? cs[prop] : null);
299 return el.style[prop] || ((cs = el.currentStyle) ? cs[prop] : null);
301 // in some cases, IE6 will throw Invalid Argument for properties
302 // like fontSize (see in /examples/tabs/tabs.html).
305 if (!ELEMENT.inheritedProps[prop]) {
310 // this is _not_ perfect, but we can only hope that the style we
311 // need is inherited from a parentNode. If not and since IE won't
312 // give us the info we need, we are never going to be 100% right.
318 msg: 'Failed to get ' + this.dom.id + '.currentStyle.' + prop
325 <span id='Ext-Element-method-getColor'> /**
326 </span> * Return the CSS color for the specified CSS attribute. rgb, 3 digit (like #fff) and valid values
327 * are convert to standard 6 digit hex color.
328 * @param {String} attr The css attribute
329 * @param {String} defaultValue The default value to use when a valid color isn't found
330 * @param {String} prefix (optional) defaults to #. Use an empty string when working with
333 getColor : function(attr, defaultValue, prefix){
334 var v = this.getStyle(attr),
335 color = prefix || prefix === '' ? prefix : '#',
338 if(!v || (/transparent|inherit/.test(v))) {
342 Ext.each(v.slice(4, v.length -1).split(','), function(s){
344 color += (h < 16 ? '0' : '') + h.toString(16);
347 v = v.replace('#', '');
348 color += v.length == 3 ? v.replace(/^(\w)(\w)(\w)$/, '$1$1$2$2$3$3') : v;
350 return(color.length > 5 ? color.toLowerCase() : defaultValue);
353 <span id='Ext-Element-method-setStyle'> /**
354 </span> * Wrapper for setting style properties, also takes single object parameter of multiple styles.
355 * @param {String/Object} property The style property to be set, or an object of multiple styles.
356 * @param {String} value (optional) The value to apply to the given property, or null if an object was passed.
357 * @return {Ext.Element} this
359 setStyle : function(prop, value){
366 if (typeof prop === 'string') {
371 for (style in prop) {
372 if (prop.hasOwnProperty(style)) {
373 value = Ext.value(prop[style], '');
374 if (style == 'opacity') {
375 me.setOpacity(value);
378 me.dom.style[ELEMENT.normalize(style)] = value;
385 <span id='Ext-Element-method-setOpacity'> /**
386 </span> * Set the opacity of the element
387 * @param {Number} opacity The new opacity. 0 = transparent, .5 = 50% visibile, 1 = fully visible, etc
388 * @param {Boolean/Object} animate (optional) a standard Element animation config object or <tt>true</tt> for
389 * the default animation (<tt>{duration: .35, easing: 'easeIn'}</tt>)
390 * @return {Ext.Element} this
392 setOpacity: function(opacity, animate) {
402 style = me.dom.style;
404 if (!animate || !me.anim) {
405 if (!Ext.supports.Opacity) {
406 opacity = opacity < 1 ? 'alpha(opacity=' + opacity * 100 + ')': '';
407 val = style.filter.replace(opacityRe, '').replace(trimRe, '');
410 style.filter = val + (val.length > 0 ? ' ': '') + opacity;
413 style.opacity = opacity;
417 if (!Ext.isObject(animate)) {
423 me.animate(Ext.applyIf({
434 <span id='Ext-Element-method-clearOpacity'> /**
435 </span> * Clears any opacity settings from this element. Required in some cases for IE.
436 * @return {Ext.Element} this
438 clearOpacity : function(){
439 var style = this.dom.style;
440 if(!Ext.supports.Opacity){
441 if(!Ext.isEmpty(style.filter)){
442 style.filter = style.filter.replace(opacityRe, '').replace(trimRe, '');
445 style.opacity = style['-moz-opacity'] = style['-khtml-opacity'] = '';
450 <span id='Ext-Element-method-adjustDirect2DDimension'> /**
452 * Returns 1 if the browser returns the subpixel dimension rounded to the lowest pixel.
453 * @return {Number} 0 or 1
455 adjustDirect2DDimension: function(dimension) {
458 display = me.getStyle('display'),
459 inlineDisplay = dom.style['display'],
460 inlinePosition = dom.style['position'],
461 originIndex = dimension === 'width' ? 0 : 1,
464 if (display === 'inline') {
465 dom.style['display'] = 'inline-block';
468 dom.style['position'] = display.match(adjustDirect2DTableRe) ? 'absolute' : 'static';
470 // floating will contain digits that appears after the decimal point
471 // if height or width are set to auto we fallback to msTransformOrigin calculation
472 floating = (parseFloat(me.getStyle(dimension)) || parseFloat(dom.currentStyle.msTransformOrigin.split(' ')[originIndex]) * 2) % 1;
474 dom.style['position'] = inlinePosition;
476 if (display === 'inline') {
477 dom.style['display'] = inlineDisplay;
483 <span id='Ext-Element-method-getHeight'> /**
484 </span> * Returns the offset height of the element
485 * @param {Boolean} contentHeight (optional) true to get the height minus borders and padding
486 * @return {Number} The element's height
488 getHeight: function(contentHeight, preciseHeight) {
491 hidden = Ext.isIE && me.isStyle('display', 'none'),
492 height, overflow, style, floating;
494 // IE Quirks mode acts more like a max-size measurement unless overflow is hidden during measurement.
495 // We will put the overflow back to it's original value when we are done measuring.
496 if (Ext.isIEQuirks) {
498 overflow = style.overflow;
499 me.setStyle({ overflow: 'hidden'});
502 height = dom.offsetHeight;
504 height = MATH.max(height, hidden ? 0 : dom.clientHeight) || 0;
506 // IE9 Direct2D dimension rounding bug
507 if (!hidden && Ext.supports.Direct2DBug) {
508 floating = me.adjustDirect2DDimension('height');
512 else if (floating > 0 && floating < 0.5) {
518 height -= (me.getBorderWidth("tb") + me.getPadding("tb"));
521 if (Ext.isIEQuirks) {
522 me.setStyle({ overflow: overflow});
531 <span id='Ext-Element-method-getWidth'> /**
532 </span> * Returns the offset width of the element
533 * @param {Boolean} contentWidth (optional) true to get the width minus borders and padding
534 * @return {Number} The element's width
536 getWidth: function(contentWidth, preciseWidth) {
539 hidden = Ext.isIE && me.isStyle('display', 'none'),
540 rect, width, overflow, style, floating, parentPosition;
542 // IE Quirks mode acts more like a max-size measurement unless overflow is hidden during measurement.
543 // We will put the overflow back to it's original value when we are done measuring.
544 if (Ext.isIEQuirks) {
546 overflow = style.overflow;
547 me.setStyle({overflow: 'hidden'});
550 // Fix Opera 10.5x width calculation issues
551 if (Ext.isOpera10_5) {
552 if (dom.parentNode.currentStyle.position === 'relative') {
553 parentPosition = dom.parentNode.style.position;
554 dom.parentNode.style.position = 'static';
555 width = dom.offsetWidth;
556 dom.parentNode.style.position = parentPosition;
558 width = Math.max(width || 0, dom.offsetWidth);
560 // Gecko will in some cases report an offsetWidth that is actually less than the width of the
561 // text contents, because it measures fonts with sub-pixel precision but rounds the calculated
562 // value down. Using getBoundingClientRect instead of offsetWidth allows us to get the precise
563 // subpixel measurements so we can force them to always be rounded up. See
564 // https://bugzilla.mozilla.org/show_bug.cgi?id=458617
565 } else if (Ext.supports.BoundingClientRect) {
566 rect = dom.getBoundingClientRect();
567 width = rect.right - rect.left;
568 width = preciseWidth ? width : Math.ceil(width);
570 width = dom.offsetWidth;
573 width = MATH.max(width, hidden ? 0 : dom.clientWidth) || 0;
575 // IE9 Direct2D dimension rounding bug
576 if (!hidden && Ext.supports.Direct2DBug) {
577 floating = me.adjustDirect2DDimension('width');
581 else if (floating > 0 && floating < 0.5) {
587 width -= (me.getBorderWidth("lr") + me.getPadding("lr"));
590 if (Ext.isIEQuirks) {
591 me.setStyle({ overflow: overflow});
600 <span id='Ext-Element-method-setWidth'> /**
601 </span> * Set the width of this Element.
602 * @param {Number/String} width The new width. This may be one of:<div class="mdetail-params"><ul>
603 * <li>A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels).</li>
604 * <li>A String used to set the CSS width style. Animation may <b>not</b> be used.
605 * </ul></div>
606 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
607 * @return {Ext.Element} this
609 setWidth : function(width, animate){
611 width = me.adjustWidth(width);
612 if (!animate || !me.anim) {
613 me.dom.style.width = me.addUnits(width);
616 if (!Ext.isObject(animate)) {
619 me.animate(Ext.applyIf({
628 <span id='Ext-Element-method-setHeight'> /**
629 </span> * Set the height of this Element.
630 * <pre><code>
631 // change the height to 200px and animate with default configuration
632 Ext.fly('elementId').setHeight(200, true);
634 // change the height to 150px and animate with a custom configuration
635 Ext.fly('elId').setHeight(150, {
636 duration : .5, // animation will have a duration of .5 seconds
637 // will change the content to "finished"
638 callback: function(){ this.{@link #update}("finished"); }
640 * </code></pre>
641 * @param {Number/String} height The new height. This may be one of:<div class="mdetail-params"><ul>
642 * <li>A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels.)</li>
643 * <li>A String used to set the CSS height style. Animation may <b>not</b> be used.</li>
644 * </ul></div>
645 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
646 * @return {Ext.Element} this
648 setHeight : function(height, animate){
650 height = me.adjustHeight(height);
651 if (!animate || !me.anim) {
652 me.dom.style.height = me.addUnits(height);
655 if (!Ext.isObject(animate)) {
658 me.animate(Ext.applyIf({
667 <span id='Ext-Element-method-getBorderWidth'> /**
668 </span> * Gets the width of the border(s) for the specified side(s)
669 * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
670 * passing <tt>'lr'</tt> would get the border <b><u>l</u></b>eft width + the border <b><u>r</u></b>ight width.
671 * @return {Number} The width of the sides passed added together
673 getBorderWidth : function(side){
674 return this.addStyles(side, borders);
677 <span id='Ext-Element-method-getPadding'> /**
678 </span> * Gets the width of the padding(s) for the specified side(s)
679 * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
680 * passing <tt>'lr'</tt> would get the padding <b><u>l</u></b>eft + the padding <b><u>r</u></b>ight.
681 * @return {Number} The padding of the sides passed added together
683 getPadding : function(side){
684 return this.addStyles(side, paddings);
687 <span id='Ext-Element-method-clip'> /**
688 </span> * Store the current overflow setting and clip overflow on the element - use <tt>{@link #unclip}</tt> to remove
689 * @return {Ext.Element} this
695 if(!data(dom, ISCLIPPED)){
696 data(dom, ISCLIPPED, true);
697 data(dom, ORIGINALCLIP, {
698 o: me.getStyle(OVERFLOW),
699 x: me.getStyle(OVERFLOWX),
700 y: me.getStyle(OVERFLOWY)
702 me.setStyle(OVERFLOW, HIDDEN);
703 me.setStyle(OVERFLOWX, HIDDEN);
704 me.setStyle(OVERFLOWY, HIDDEN);
709 <span id='Ext-Element-method-unclip'> /**
710 </span> * Return clipping (overflow) to original clipping before <tt>{@link #clip}</tt> was called
711 * @return {Ext.Element} this
718 if(data(dom, ISCLIPPED)){
719 data(dom, ISCLIPPED, false);
720 clip = data(dom, ORIGINALCLIP);
722 me.setStyle(OVERFLOW, clip.o);
725 me.setStyle(OVERFLOWX, clip.x);
728 me.setStyle(OVERFLOWY, clip.y);
735 addStyles : function(sides, styles){
737 sidesArr = sides.match(wordsRe),
739 len = sidesArr.length,
741 for (; i < len; i++) {
743 size = side && parseInt(this.getStyle(styles[side]), 10);
745 totalSize += MATH.abs(size);
753 <span id='Ext-Element-method-applyStyles'> /**
754 </span> * More flexible version of {@link #setStyle} for setting style properties.
755 * @param {String/Object/Function} styles A style specification string, e.g. "width:100px", or object in the form {width:"100px"}, or
756 * a function which returns such a specification.
757 * @return {Ext.Element} this
759 applyStyles : function(style){
760 Ext.DomHelper.applyStyles(this.dom, style);
764 <span id='Ext-Element-method-getStyles'> /**
765 </span> * Returns an object with properties matching the styles requested.
766 * For example, el.getStyles('color', 'font-size', 'width') might return
767 * {'color': '#FFFFFF', 'font-size': '13px', 'width': '100px'}.
768 * @param {String} style1 A style name
769 * @param {String} style2 A style name
770 * @param {String} etc.
771 * @return {Object} The style object
773 getStyles : function(){
775 len = arguments.length,
778 for(; i < len; ++i) {
779 style = arguments[i];
780 styles[style] = this.getStyle(style);
785 <span id='Ext-Element-method-boxWrap'> /**
786 </span> * <p>Wraps the specified element with a special 9 element markup/CSS block that renders by default as
787 * a gray container with a gradient background, rounded corners and a 4-way shadow.</p>
788 * <p>This special markup is used throughout Ext when box wrapping elements ({@link Ext.button.Button},
789 * {@link Ext.panel.Panel} when <tt>{@link Ext.panel.Panel#frame frame=true}</tt>, {@link Ext.window.Window}). The markup
790 * is of this form:</p>
791 * <pre><code>
792 Ext.Element.boxMarkup =
793 &#39;&lt;div class="{0}-tl">&lt;div class="{0}-tr">&lt;div class="{0}-tc">&lt;/div>&lt;/div>&lt;/div>
794 &lt;div class="{0}-ml">&lt;div class="{0}-mr">&lt;div class="{0}-mc">&lt;/div>&lt;/div>&lt;/div>
795 &lt;div class="{0}-bl">&lt;div class="{0}-br">&lt;div class="{0}-bc">&lt;/div>&lt;/div>&lt;/div>&#39;;
796 * </code></pre>
797 * <p>Example usage:</p>
798 * <pre><code>
800 Ext.get("foo").boxWrap();
802 // You can also add a custom class and use CSS inheritance rules to customize the box look.
803 // 'x-box-blue' is a built-in alternative -- look at the related CSS definitions as an example
804 // for how to create a custom box wrap style.
805 Ext.get("foo").boxWrap().addCls("x-box-blue");
806 * </code></pre>
807 * @param {String} class (optional) A base CSS class to apply to the containing wrapper element
808 * (defaults to <tt>'x-box'</tt>). Note that there are a number of CSS rules that are dependent on
809 * this name to make the overall effect work, so if you supply an alternate base class, make sure you
810 * also supply all of the necessary rules.
811 * @return {Ext.Element} The outermost wrapping element of the created box structure.
813 boxWrap : function(cls){
814 cls = cls || Ext.baseCSSPrefix + 'box';
815 var el = Ext.get(this.insertHtml("beforeBegin", "<div class='" + cls + "'>" + Ext.String.format(ELEMENT.boxMarkup, cls) + "</div>"));
816 Ext.DomQuery.selectNode('.' + cls + '-mc', el.dom).appendChild(this.dom);
820 <span id='Ext-Element-method-setSize'> /**
821 </span> * Set the size of this Element. If animation is true, both width and height will be animated concurrently.
822 * @param {Number/String} width The new width. This may be one of:<div class="mdetail-params"><ul>
823 * <li>A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels).</li>
824 * <li>A String used to set the CSS width style. Animation may <b>not</b> be used.
825 * <li>A size object in the format <code>{width: widthValue, height: heightValue}</code>.</li>
826 * </ul></div>
827 * @param {Number/String} height The new height. This may be one of:<div class="mdetail-params"><ul>
828 * <li>A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels).</li>
829 * <li>A String used to set the CSS height style. Animation may <b>not</b> be used.</li>
830 * </ul></div>
831 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
832 * @return {Ext.Element} this
834 setSize : function(width, height, animate){
836 if (Ext.isObject(width)) { // in case of object from getSize()
838 height = width.height;
841 width = me.adjustWidth(width);
842 height = me.adjustHeight(height);
843 if(!animate || !me.anim){
844 // Must touch some property before setting style.width/height on non-quirk IE6,7, or the
845 // properties will not reflect the changes on the style immediately
846 if (!Ext.isIEQuirks && (Ext.isIE6 || Ext.isIE7)) {
849 me.dom.style.width = me.addUnits(width);
850 me.dom.style.height = me.addUnits(height);
853 if (animate === true) {
856 me.animate(Ext.applyIf({
866 <span id='Ext-Element-method-getComputedHeight'> /**
867 </span> * Returns either the offsetHeight or the height of this element based on CSS height adjusted by padding or borders
868 * when needed to simulate offsetHeight when offsets aren't available. This may not work on display:none elements
869 * if a height has not been set using CSS.
872 getComputedHeight : function(){
874 h = Math.max(me.dom.offsetHeight, me.dom.clientHeight);
876 h = parseFloat(me.getStyle('height')) || 0;
877 if(!me.isBorderBox()){
878 h += me.getFrameWidth('tb');
884 <span id='Ext-Element-method-getComputedWidth'> /**
885 </span> * Returns either the offsetWidth or the width of this element based on CSS width adjusted by padding or borders
886 * when needed to simulate offsetWidth when offsets aren't available. This may not work on display:none elements
887 * if a width has not been set using CSS.
890 getComputedWidth : function(){
892 w = Math.max(me.dom.offsetWidth, me.dom.clientWidth);
895 w = parseFloat(me.getStyle('width')) || 0;
896 if(!me.isBorderBox()){
897 w += me.getFrameWidth('lr');
903 <span id='Ext-Element-method-getFrameWidth'> /**
904 </span> * Returns the sum width of the padding and borders for the passed "sides". See getBorderWidth()
905 for more information about the sides.
906 * @param {String} sides
909 getFrameWidth : function(sides, onlyContentBox){
910 return onlyContentBox && this.isBorderBox() ? 0 : (this.getPadding(sides) + this.getBorderWidth(sides));
913 <span id='Ext-Element-method-addClsOnOver'> /**
914 </span> * Sets up event handlers to add and remove a css class when the mouse is over this element
915 * @param {String} className
916 * @return {Ext.Element} this
918 addClsOnOver : function(className){
922 Ext.fly(dom, INTERNAL).addCls(className);
925 Ext.fly(dom, INTERNAL).removeCls(className);
931 <span id='Ext-Element-method-addClsOnFocus'> /**
932 </span> * Sets up event handlers to add and remove a css class when this element has the focus
933 * @param {String} className
934 * @return {Ext.Element} this
936 addClsOnFocus : function(className){
939 me.on("focus", function(){
940 Ext.fly(dom, INTERNAL).addCls(className);
942 me.on("blur", function(){
943 Ext.fly(dom, INTERNAL).removeCls(className);
948 <span id='Ext-Element-method-addClsOnClick'> /**
949 </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)
950 * @param {String} className
951 * @return {Ext.Element} this
953 addClsOnClick : function(className){
955 this.on("mousedown", function(){
956 Ext.fly(dom, INTERNAL).addCls(className);
957 var d = Ext.getDoc(),
959 Ext.fly(dom, INTERNAL).removeCls(className);
960 d.removeListener("mouseup", fn);
962 d.on("mouseup", fn);
967 <span id='Ext-Element-method-getViewSize'> /**
968 </span> * <p>Returns the dimensions of the element available to lay content out in.<p>
969 * <p>If the element (or any ancestor element) has CSS style <code>display : none</code>, the dimensions will be zero.</p>
970 * example:<pre><code>
971 var vpSize = Ext.getBody().getViewSize();
973 // all Windows created afterwards will have a default value of 90% height and 95% width
974 Ext.Window.override({
975 width: vpSize.width * 0.9,
976 height: vpSize.height * 0.95
978 // To handle window resizing you would have to hook onto onWindowResize.
979 * </code></pre>
981 * getViewSize utilizes clientHeight/clientWidth which excludes sizing of scrollbars.
982 * To obtain the size including scrollbars, use getStyleSize
984 * Sizing of the document body is handled at the adapter level which handles special cases for IE and strict modes, etc.
987 getViewSize : function(){
990 isDoc = (dom == Ext.getDoc().dom || dom == Ext.getBody().dom),
991 style, overflow, ret;
993 // If the body, use static methods
996 width : ELEMENT.getViewWidth(),
997 height : ELEMENT.getViewHeight()
1000 // Else use clientHeight/clientWidth
1003 // IE 6 & IE Quirks mode acts more like a max-size measurement unless overflow is hidden during measurement.
1004 // We will put the overflow back to it's original value when we are done measuring.
1005 if (Ext.isIE6 || Ext.isIEQuirks) {
1007 overflow = style.overflow;
1008 me.setStyle({ overflow: 'hidden'});
1011 width : dom.clientWidth,
1012 height : dom.clientHeight
1014 if (Ext.isIE6 || Ext.isIEQuirks) {
1015 me.setStyle({ overflow: overflow });
1021 <span id='Ext-Element-method-getStyleSize'> /**
1022 </span> * <p>Returns the dimensions of the element available to lay content out in.<p>
1024 * getStyleSize utilizes prefers style sizing if present, otherwise it chooses the larger of offsetHeight/clientHeight and offsetWidth/clientWidth.
1025 * To obtain the size excluding scrollbars, use getViewSize
1027 * Sizing of the document body is handled at the adapter level which handles special cases for IE and strict modes, etc.
1030 getStyleSize : function(){
1034 isDoc = (d == doc || d == doc.body),
1038 // If the body, use static methods
1041 width : ELEMENT.getViewWidth(),
1042 height : ELEMENT.getViewHeight()
1045 // Use Styles if they are set
1046 if(s.width && s.width != 'auto'){
1047 w = parseFloat(s.width);
1048 if(me.isBorderBox()){
1049 w -= me.getFrameWidth('lr');
1052 // Use Styles if they are set
1053 if(s.height && s.height != 'auto'){
1054 h = parseFloat(s.height);
1055 if(me.isBorderBox()){
1056 h -= me.getFrameWidth('tb');
1059 // Use getWidth/getHeight if style not set.
1060 return {width: w || me.getWidth(true), height: h || me.getHeight(true)};
1063 <span id='Ext-Element-method-getSize'> /**
1064 </span> * Returns the size of the element.
1065 * @param {Boolean} contentSize (optional) true to get the width/size minus borders and padding
1066 * @return {Object} An object containing the element's size {width: (element width), height: (element height)}
1068 getSize : function(contentSize){
1069 return {width: this.getWidth(contentSize), height: this.getHeight(contentSize)};
1072 <span id='Ext-Element-method-repaint'> /**
1073 </span> * Forces the browser to repaint this element
1074 * @return {Ext.Element} this
1076 repaint : function(){
1078 this.addCls(Ext.baseCSSPrefix + 'repaint');
1079 setTimeout(function(){
1080 Ext.fly(dom).removeCls(Ext.baseCSSPrefix + 'repaint');
1085 <span id='Ext-Element-method-selectable'> /**
1086 </span> * Enable text selection for this element (normalized across browsers)
1087 * @return {Ext.Element} this
1089 selectable : function() {
1091 me.dom.unselectable = "off";
1092 // Prevent it from bubles up and enables it to be selectable
1093 me.on('selectstart', function (e) {
1094 e.stopPropagation();
1097 me.applyStyles("-moz-user-select: text; -khtml-user-select: text;");
1098 me.removeCls(Ext.baseCSSPrefix + 'unselectable');
1102 <span id='Ext-Element-method-unselectable'> /**
1103 </span> * Disables text selection for this element (normalized across browsers)
1104 * @return {Ext.Element} this
1106 unselectable : function(){
1108 me.dom.unselectable = "on";
1110 me.swallowEvent("selectstart", true);
1111 me.applyStyles("-moz-user-select:-moz-none;-khtml-user-select:none;");
1112 me.addCls(Ext.baseCSSPrefix + 'unselectable');
1117 <span id='Ext-Element-method-getMargin'> /**
1118 </span> * Returns an object with properties top, left, right and bottom representing the margins of this element unless sides is passed,
1119 * then it returns the calculated width of the sides (see getPadding)
1120 * @param {String} sides (optional) Any combination of l, r, t, b to get the sum of those sides
1121 * @return {Object/Number}
1123 getMargin : function(side){
1125 hash = {t:"top", l:"left", r:"right", b: "bottom"},
1130 for (key in me.margins){
1131 o[hash[key]] = parseFloat(me.getStyle(me.margins[key])) || 0;
1135 return me.addStyles.call(me, side, me.margins);