3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.3.0
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
18 Ext.Element.addMethods(function(){
19 // local style camelizing for speed
20 var supports = Ext.supports,
22 camelRe = /(-[a-z])/gi,
23 view = document.defaultView,
24 opacityRe = /alpha\(opacity=(.*)\)/i,
25 trimRe = /^\s+|\s+$/g,
39 ISCLIPPED = 'isClipped',
40 OVERFLOW = 'overflow',
41 OVERFLOWX = 'overflow-x',
42 OVERFLOWY = 'overflow-y',
43 ORIGINALCLIP = 'originalClip',
44 // special markup used throughout Ext when box wrapping elements
45 borders = {l: BORDER + LEFT + WIDTH, r: BORDER + RIGHT + WIDTH, t: BORDER + TOP + WIDTH, b: BORDER + BOTTOM + WIDTH},
46 paddings = {l: PADDING + LEFT, r: PADDING + RIGHT, t: PADDING + TOP, b: PADDING + BOTTOM},
47 margins = {l: MARGIN + LEFT, r: MARGIN + RIGHT, t: MARGIN + TOP, b: MARGIN + BOTTOM},
48 data = Ext.Element.data;
52 function camelFn(m, a) {
53 return a.charAt(1).toUpperCase();
56 function chkCache(prop) {
57 return propCache[prop] || (propCache[prop] = prop == 'float' ? (supports.cssFloat ? 'cssFloat' : 'styleFloat') : prop.replace(camelRe, camelFn));
61 // private ==> used by Fx
62 adjustWidth : function(width) {
64 var isNum = (typeof width == "number");
65 if(isNum && me.autoBoxAdjust && !me.isBorderBox()){
66 width -= (me.getBorderWidth("lr") + me.getPadding("lr"));
68 return (isNum && width < 0) ? 0 : width;
71 // private ==> used by Fx
72 adjustHeight : function(height) {
74 var isNum = (typeof height == "number");
75 if(isNum && me.autoBoxAdjust && !me.isBorderBox()){
76 height -= (me.getBorderWidth("tb") + me.getPadding("tb"));
78 return (isNum && height < 0) ? 0 : height;
82 <div id="method-Ext.Element-addClass"></div>/**
83 * Adds one or more CSS classes to the element. Duplicate classes are automatically filtered out.
84 * @param {String/Array} className The CSS class to add, or an array of classes
85 * @return {Ext.Element} this
87 addClass : function(className){
93 // Separate case is for speed
94 if (!Ext.isArray(className)) {
95 if (typeof className == 'string' && !this.hasClass(className)) {
96 me.dom.className += " " + className;
100 for (i = 0, len = className.length; i < len; i++) {
102 if (typeof v == 'string' && (' ' + me.dom.className + ' ').indexOf(' ' + v + ' ') == -1) {
107 me.dom.className += " " + cls.join(" ");
113 <div id="method-Ext.Element-removeClass"></div>/**
114 * Removes one or more CSS classes from the element.
115 * @param {String/Array} className The CSS class to remove, or an array of classes
116 * @return {Ext.Element} this
118 removeClass : function(className){
125 if (!Ext.isArray(className)){
126 className = [className];
128 if (me.dom && me.dom.className) {
129 elClasses = me.dom.className.replace(trimRe, '').split(spacesRe);
130 for (i = 0, len = className.length; i < len; i++) {
132 if (typeof cls == 'string') {
133 cls = cls.replace(trimRe, '');
134 idx = elClasses.indexOf(cls);
136 elClasses.splice(idx, 1);
140 me.dom.className = elClasses.join(" ");
145 <div id="method-Ext.Element-radioClass"></div>/**
146 * Adds one or more CSS classes to this element and removes the same class(es) from all siblings.
147 * @param {String/Array} className The CSS class to add, or an array of classes
148 * @return {Ext.Element} this
150 radioClass : function(className){
151 var cn = this.dom.parentNode.childNodes,
155 className = Ext.isArray(className) ? className : [className];
156 for (i = 0, len = cn.length; i < len; i++) {
158 if (v && v.nodeType == 1) {
159 Ext.fly(v, '_internal').removeClass(className);
162 return this.addClass(className);
165 <div id="method-Ext.Element-toggleClass"></div>/**
166 * Toggles the specified CSS class on this element (removes it if it already exists, otherwise adds it).
167 * @param {String} className The CSS class to toggle
168 * @return {Ext.Element} this
170 toggleClass : function(className){
171 return this.hasClass(className) ? this.removeClass(className) : this.addClass(className);
174 <div id="method-Ext.Element-hasClass"></div>/**
175 * Checks if the specified CSS class exists on this element's DOM node.
176 * @param {String} className The CSS class to check for
177 * @return {Boolean} True if the class exists, else false
179 hasClass : function(className){
180 return className && (' '+this.dom.className+' ').indexOf(' '+className+' ') != -1;
183 <div id="method-Ext.Element-replaceClass"></div>/**
184 * Replaces a CSS class on the element with another. If the old name does not exist, the new name will simply be added.
185 * @param {String} oldClassName The CSS class to replace
186 * @param {String} newClassName The replacement CSS class
187 * @return {Ext.Element} this
189 replaceClass : function(oldClassName, newClassName){
190 return this.removeClass(oldClassName).addClass(newClassName);
193 isStyle : function(style, val) {
194 return this.getStyle(style) == val;
197 <div id="method-Ext.Element-getStyle"></div>/**
198 * Normalizes currentStyle and computedStyle.
199 * @param {String} property The style property whose value is returned.
200 * @return {String} The current value of the style property for this element.
202 getStyle : function(){
203 return view && view.getComputedStyle ?
214 prop = chkCache(prop);
215 out = (v = el.style[prop]) ? v :
216 (cs = view.getComputedStyle(el, "")) ? cs[prop] : null;
218 // Ignore cases when the margin is correctly reported as 0, the bug only shows
220 if(prop == 'marginRight' && out != '0px' && !supports.correctRightMargin){
221 display = el.style.display;
222 el.style.display = 'inline-block';
223 out = view.getComputedStyle(el, '').marginRight;
224 el.style.display = display;
227 if(prop == 'backgroundColor' && out == 'rgba(0, 0, 0, 0)' && !supports.correctTransparentColor){
237 if(el == document) return null;
238 if (prop == 'opacity') {
239 if (el.style.filter.match) {
240 if(m = el.style.filter.match(opacityRe)){
241 var fv = parseFloat(m[1]);
243 return fv ? fv / 100 : 0;
249 prop = chkCache(prop);
250 return el.style[prop] || ((cs = el.currentStyle) ? cs[prop] : null);
254 <div id="method-Ext.Element-getColor"></div>/**
255 * Return the CSS color for the specified CSS attribute. rgb, 3 digit (like #fff) and valid values
256 * are convert to standard 6 digit hex color.
257 * @param {String} attr The css attribute
258 * @param {String} defaultValue The default value to use when a valid color isn't found
259 * @param {String} prefix (optional) defaults to #. Use an empty string when working with
262 getColor : function(attr, defaultValue, prefix){
263 var v = this.getStyle(attr),
264 color = (typeof prefix != 'undefined') ? prefix : '#',
267 if(!v || (/transparent|inherit/.test(v))) {
271 Ext.each(v.slice(4, v.length -1).split(','), function(s){
273 color += (h < 16 ? '0' : '') + h.toString(16);
276 v = v.replace('#', '');
277 color += v.length == 3 ? v.replace(/^(\w)(\w)(\w)$/, '$1$1$2$2$3$3') : v;
279 return(color.length > 5 ? color.toLowerCase() : defaultValue);
282 <div id="method-Ext.Element-setStyle"></div>/**
283 * Wrapper for setting style properties, also takes single object parameter of multiple styles.
284 * @param {String/Object} property The style property to be set, or an object of multiple styles.
285 * @param {String} value (optional) The value to apply to the given property, or null if an object was passed.
286 * @return {Ext.Element} this
288 setStyle : function(prop, value){
291 if (typeof prop != 'object') {
296 for (style in prop) {
299 this.setOpacity(value) :
300 this.dom.style[chkCache(style)] = value;
305 <div id="method-Ext.Element-setOpacity"></div>/**
306 * Set the opacity of the element
307 * @param {Float} opacity The new opacity. 0 = transparent, .5 = 50% visibile, 1 = fully visible, etc
308 * @param {Boolean/Object} animate (optional) a standard Element animation config object or <tt>true</tt> for
309 * the default animation (<tt>{duration: .35, easing: 'easeIn'}</tt>)
310 * @return {Ext.Element} this
312 setOpacity : function(opacity, animate){
316 if(!animate || !me.anim){
318 var opac = opacity < 1 ? 'alpha(opacity=' + opacity * 100 + ')' : '',
319 val = s.filter.replace(opacityRe, '').replace(trimRe, '');
322 s.filter = val + (val.length > 0 ? ' ' : '') + opac;
327 me.anim({opacity: {to: opacity}}, me.preanim(arguments, 1), null, .35, 'easeIn');
332 <div id="method-Ext.Element-clearOpacity"></div>/**
333 * Clears any opacity settings from this element. Required in some cases for IE.
334 * @return {Ext.Element} this
336 clearOpacity : function(){
337 var style = this.dom.style;
339 if(!Ext.isEmpty(style.filter)){
340 style.filter = style.filter.replace(opacityRe, '').replace(trimRe, '');
343 style.opacity = style['-moz-opacity'] = style['-khtml-opacity'] = '';
348 <div id="method-Ext.Element-getHeight"></div>/**
349 * Returns the offset height of the element
350 * @param {Boolean} contentHeight (optional) true to get the height minus borders and padding
351 * @return {Number} The element's height
353 getHeight : function(contentHeight){
356 hidden = Ext.isIE && me.isStyle('display', 'none'),
357 h = MATH.max(dom.offsetHeight, hidden ? 0 : dom.clientHeight) || 0;
359 h = !contentHeight ? h : h - me.getBorderWidth("tb") - me.getPadding("tb");
360 return h < 0 ? 0 : h;
363 <div id="method-Ext.Element-getWidth"></div>/**
364 * Returns the offset width of the element
365 * @param {Boolean} contentWidth (optional) true to get the width minus borders and padding
366 * @return {Number} The element's width
368 getWidth : function(contentWidth){
371 hidden = Ext.isIE && me.isStyle('display', 'none'),
372 w = MATH.max(dom.offsetWidth, hidden ? 0 : dom.clientWidth) || 0;
373 w = !contentWidth ? w : w - me.getBorderWidth("lr") - me.getPadding("lr");
374 return w < 0 ? 0 : w;
377 <div id="method-Ext.Element-setWidth"></div>/**
378 * Set the width of this Element.
379 * @param {Mixed} width The new width. This may be one of:<div class="mdetail-params"><ul>
380 * <li>A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels).</li>
381 * <li>A String used to set the CSS width style. Animation may <b>not</b> be used.
383 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
384 * @return {Ext.Element} this
386 setWidth : function(width, animate){
388 width = me.adjustWidth(width);
389 !animate || !me.anim ?
390 me.dom.style.width = me.addUnits(width) :
391 me.anim({width : {to : width}}, me.preanim(arguments, 1));
395 <div id="method-Ext.Element-setHeight"></div>/**
396 * Set the height of this Element.
398 // change the height to 200px and animate with default configuration
399 Ext.fly('elementId').setHeight(200, true);
401 // change the height to 150px and animate with a custom configuration
402 Ext.fly('elId').setHeight(150, {
403 duration : .5, // animation will have a duration of .5 seconds
404 // will change the content to "finished"
405 callback: function(){ this.{@link #update}("finished"); }
408 * @param {Mixed} height The new height. This may be one of:<div class="mdetail-params"><ul>
409 * <li>A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels.)</li>
410 * <li>A String used to set the CSS height style. Animation may <b>not</b> be used.</li>
412 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
413 * @return {Ext.Element} this
415 setHeight : function(height, animate){
417 height = me.adjustHeight(height);
418 !animate || !me.anim ?
419 me.dom.style.height = me.addUnits(height) :
420 me.anim({height : {to : height}}, me.preanim(arguments, 1));
424 <div id="method-Ext.Element-getBorderWidth"></div>/**
425 * Gets the width of the border(s) for the specified side(s)
426 * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
427 * passing <tt>'lr'</tt> would get the border <b><u>l</u></b>eft width + the border <b><u>r</u></b>ight width.
428 * @return {Number} The width of the sides passed added together
430 getBorderWidth : function(side){
431 return this.addStyles(side, borders);
434 <div id="method-Ext.Element-getPadding"></div>/**
435 * Gets the width of the padding(s) for the specified side(s)
436 * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
437 * passing <tt>'lr'</tt> would get the padding <b><u>l</u></b>eft + the padding <b><u>r</u></b>ight.
438 * @return {Number} The padding of the sides passed added together
440 getPadding : function(side){
441 return this.addStyles(side, paddings);
444 <div id="method-Ext.Element-clip"></div>/**
445 * Store the current overflow setting and clip overflow on the element - use <tt>{@link #unclip}</tt> to remove
446 * @return {Ext.Element} this
452 if(!data(dom, ISCLIPPED)){
453 data(dom, ISCLIPPED, true);
454 data(dom, ORIGINALCLIP, {
455 o: me.getStyle(OVERFLOW),
456 x: me.getStyle(OVERFLOWX),
457 y: me.getStyle(OVERFLOWY)
459 me.setStyle(OVERFLOW, HIDDEN);
460 me.setStyle(OVERFLOWX, HIDDEN);
461 me.setStyle(OVERFLOWY, HIDDEN);
466 <div id="method-Ext.Element-unclip"></div>/**
467 * Return clipping (overflow) to original clipping before <tt>{@link #clip}</tt> was called
468 * @return {Ext.Element} this
474 if(data(dom, ISCLIPPED)){
475 data(dom, ISCLIPPED, false);
476 var o = data(dom, ORIGINALCLIP);
478 me.setStyle(OVERFLOW, o.o);
481 me.setStyle(OVERFLOWX, o.x);
484 me.setStyle(OVERFLOWY, o.y);
491 addStyles : function(sides, styles){
493 sidesArr = sides.match(wordsRe),
497 len = sidesArr.length;
498 for (i = 0; i < len; i++) {
500 size = side && parseInt(this.getStyle(styles[side]), 10);
502 ttlSize += MATH.abs(size);