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.2.2
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
21 camelRe = /(-[a-z])/gi,
22 view = document.defaultView,
23 propFloat = Ext.isIE ? 'styleFloat' : 'cssFloat',
24 opacityRe = /alpha\(opacity=(.*)\)/i,
25 trimRe = /^\s+|\s+$/g,
38 ISCLIPPED = 'isClipped',
39 OVERFLOW = 'overflow',
40 OVERFLOWX = 'overflow-x',
41 OVERFLOWY = 'overflow-y',
42 ORIGINALCLIP = 'originalClip',
43 // special markup used throughout Ext when box wrapping elements
44 borders = {l: BORDER + LEFT + WIDTH, r: BORDER + RIGHT + WIDTH, t: BORDER + TOP + WIDTH, b: BORDER + BOTTOM + WIDTH},
45 paddings = {l: PADDING + LEFT, r: PADDING + RIGHT, t: PADDING + TOP, b: PADDING + BOTTOM},
46 margins = {l: MARGIN + LEFT, r: MARGIN + RIGHT, t: MARGIN + TOP, b: MARGIN + BOTTOM},
47 data = Ext.Element.data;
51 function camelFn(m, a) {
52 return a.charAt(1).toUpperCase();
55 function chkCache(prop) {
56 return propCache[prop] || (propCache[prop] = prop == 'float' ? propFloat : prop.replace(camelRe, camelFn));
60 // private ==> used by Fx
61 adjustWidth : function(width) {
63 var isNum = (typeof width == "number");
64 if(isNum && me.autoBoxAdjust && !me.isBorderBox()){
65 width -= (me.getBorderWidth("lr") + me.getPadding("lr"));
67 return (isNum && width < 0) ? 0 : width;
70 // private ==> used by Fx
71 adjustHeight : function(height) {
73 var 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 <div id="method-Ext.Element-addClass"></div>/**
82 * Adds one or more CSS classes to the element. Duplicate classes are automatically filtered out.
83 * @param {String/Array} className The CSS class to add, or an array of classes
84 * @return {Ext.Element} this
86 addClass : function(className){
92 // Separate case is for speed
93 if (!Ext.isArray(className)) {
94 if (typeof className == 'string' && !this.hasClass(className)) {
95 me.dom.className += " " + className;
99 for (i = 0, len = className.length; i < len; i++) {
101 if (typeof v == 'string' && (' ' + me.dom.className + ' ').indexOf(' ' + v + ' ') == -1) {
106 me.dom.className += " " + cls.join(" ");
112 <div id="method-Ext.Element-removeClass"></div>/**
113 * Removes one or more CSS classes from the element.
114 * @param {String/Array} className The CSS class to remove, or an array of classes
115 * @return {Ext.Element} this
117 removeClass : function(className){
124 if (!Ext.isArray(className)){
125 className = [className];
127 if (me.dom && me.dom.className) {
128 elClasses = me.dom.className.replace(trimRe, '').split(spacesRe);
129 for (i = 0, len = className.length; i < len; i++) {
131 if (typeof cls == 'string') {
132 cls = cls.replace(trimRe, '');
133 idx = elClasses.indexOf(cls);
135 elClasses.splice(idx, 1);
139 me.dom.className = elClasses.join(" ");
144 <div id="method-Ext.Element-radioClass"></div>/**
145 * Adds one or more CSS classes to this element and removes the same class(es) from all siblings.
146 * @param {String/Array} className The CSS class to add, or an array of classes
147 * @return {Ext.Element} this
149 radioClass : function(className){
150 var cn = this.dom.parentNode.childNodes,
154 className = Ext.isArray(className) ? className : [className];
155 for (i = 0, len = cn.length; i < len; i++) {
157 if (v && v.nodeType == 1) {
158 Ext.fly(v, '_internal').removeClass(className);
161 return this.addClass(className);
164 <div id="method-Ext.Element-toggleClass"></div>/**
165 * Toggles the specified CSS class on this element (removes it if it already exists, otherwise adds it).
166 * @param {String} className The CSS class to toggle
167 * @return {Ext.Element} this
169 toggleClass : function(className){
170 return this.hasClass(className) ? this.removeClass(className) : this.addClass(className);
173 <div id="method-Ext.Element-hasClass"></div>/**
174 * Checks if the specified CSS class exists on this element's DOM node.
175 * @param {String} className The CSS class to check for
176 * @return {Boolean} True if the class exists, else false
178 hasClass : function(className){
179 return className && (' '+this.dom.className+' ').indexOf(' '+className+' ') != -1;
182 <div id="method-Ext.Element-replaceClass"></div>/**
183 * Replaces a CSS class on the element with another. If the old name does not exist, the new name will simply be added.
184 * @param {String} oldClassName The CSS class to replace
185 * @param {String} newClassName The replacement CSS class
186 * @return {Ext.Element} this
188 replaceClass : function(oldClassName, newClassName){
189 return this.removeClass(oldClassName).addClass(newClassName);
192 isStyle : function(style, val) {
193 return this.getStyle(style) == val;
196 <div id="method-Ext.Element-getStyle"></div>/**
197 * Normalizes currentStyle and computedStyle.
198 * @param {String} property The style property whose value is returned.
199 * @return {String} The current value of the style property for this element.
201 getStyle : function(){
202 return view && view.getComputedStyle ?
215 prop = chkCache(prop);
216 // Fix bug caused by this: https://bugs.webkit.org/show_bug.cgi?id=13343
217 if(wk && (/marginRight/.test(prop))) {
218 display = this.getStyle('display');
219 el.style.display = 'inline-block';
221 out = (v = el.style[prop]) ? v :
222 (cs = view.getComputedStyle(el, "")) ? cs[prop] : null;
224 // Webkit returns rgb values for transparent.
226 if(out == 'rgba(0, 0, 0, 0)'){
229 el.style.display = display;
239 if(el == document) return null;
240 if (prop == 'opacity') {
241 if (el.style.filter.match) {
242 if(m = el.style.filter.match(opacityRe)){
243 var fv = parseFloat(m[1]);
245 return fv ? fv / 100 : 0;
251 prop = chkCache(prop);
252 return el.style[prop] || ((cs = el.currentStyle) ? cs[prop] : null);
256 <div id="method-Ext.Element-getColor"></div>/**
257 * Return the CSS color for the specified CSS attribute. rgb, 3 digit (like #fff) and valid values
258 * are convert to standard 6 digit hex color.
259 * @param {String} attr The css attribute
260 * @param {String} defaultValue The default value to use when a valid color isn't found
261 * @param {String} prefix (optional) defaults to #. Use an empty string when working with
264 getColor : function(attr, defaultValue, prefix){
265 var v = this.getStyle(attr),
266 color = (typeof prefix != 'undefined') ? prefix : '#',
269 if(!v || (/transparent|inherit/.test(v))) {
273 Ext.each(v.slice(4, v.length -1).split(','), function(s){
275 color += (h < 16 ? '0' : '') + h.toString(16);
278 v = v.replace('#', '');
279 color += v.length == 3 ? v.replace(/^(\w)(\w)(\w)$/, '$1$1$2$2$3$3') : v;
281 return(color.length > 5 ? color.toLowerCase() : defaultValue);
284 <div id="method-Ext.Element-setStyle"></div>/**
285 * Wrapper for setting style properties, also takes single object parameter of multiple styles.
286 * @param {String/Object} property The style property to be set, or an object of multiple styles.
287 * @param {String} value (optional) The value to apply to the given property, or null if an object was passed.
288 * @return {Ext.Element} this
290 setStyle : function(prop, value){
293 if (typeof prop != 'object') {
298 for (style in prop) {
301 this.setOpacity(value) :
302 this.dom.style[chkCache(style)] = value;
307 <div id="method-Ext.Element-setOpacity"></div>/**
308 * Set the opacity of the element
309 * @param {Float} opacity The new opacity. 0 = transparent, .5 = 50% visibile, 1 = fully visible, etc
310 * @param {Boolean/Object} animate (optional) a standard Element animation config object or <tt>true</tt> for
311 * the default animation (<tt>{duration: .35, easing: 'easeIn'}</tt>)
312 * @return {Ext.Element} this
314 setOpacity : function(opacity, animate){
318 if(!animate || !me.anim){
320 var opac = opacity < 1 ? 'alpha(opacity=' + opacity * 100 + ')' : '',
321 val = s.filter.replace(opacityRe, '').replace(trimRe, '');
324 s.filter = val + (val.length > 0 ? ' ' : '') + opac;
329 me.anim({opacity: {to: opacity}}, me.preanim(arguments, 1), null, .35, 'easeIn');
334 <div id="method-Ext.Element-clearOpacity"></div>/**
335 * Clears any opacity settings from this element. Required in some cases for IE.
336 * @return {Ext.Element} this
338 clearOpacity : function(){
339 var style = this.dom.style;
341 if(!Ext.isEmpty(style.filter)){
342 style.filter = style.filter.replace(opacityRe, '').replace(trimRe, '');
345 style.opacity = style['-moz-opacity'] = style['-khtml-opacity'] = '';
350 <div id="method-Ext.Element-getHeight"></div>/**
351 * Returns the offset height of the element
352 * @param {Boolean} contentHeight (optional) true to get the height minus borders and padding
353 * @return {Number} The element's height
355 getHeight : function(contentHeight){
358 hidden = Ext.isIE && me.isStyle('display', 'none'),
359 h = MATH.max(dom.offsetHeight, hidden ? 0 : dom.clientHeight) || 0;
361 h = !contentHeight ? h : h - me.getBorderWidth("tb") - me.getPadding("tb");
362 return h < 0 ? 0 : h;
365 <div id="method-Ext.Element-getWidth"></div>/**
366 * Returns the offset width of the element
367 * @param {Boolean} contentWidth (optional) true to get the width minus borders and padding
368 * @return {Number} The element's width
370 getWidth : function(contentWidth){
373 hidden = Ext.isIE && me.isStyle('display', 'none'),
374 w = MATH.max(dom.offsetWidth, hidden ? 0 : dom.clientWidth) || 0;
375 w = !contentWidth ? w : w - me.getBorderWidth("lr") - me.getPadding("lr");
376 return w < 0 ? 0 : w;
379 <div id="method-Ext.Element-setWidth"></div>/**
380 * Set the width of this Element.
381 * @param {Mixed} width The new width. This may be one of:<div class="mdetail-params"><ul>
382 * <li>A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels).</li>
383 * <li>A String used to set the CSS width style. Animation may <b>not</b> be used.
385 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
386 * @return {Ext.Element} this
388 setWidth : function(width, animate){
390 width = me.adjustWidth(width);
391 !animate || !me.anim ?
392 me.dom.style.width = me.addUnits(width) :
393 me.anim({width : {to : width}}, me.preanim(arguments, 1));
397 <div id="method-Ext.Element-setHeight"></div>/**
398 * Set the height of this Element.
400 // change the height to 200px and animate with default configuration
401 Ext.fly('elementId').setHeight(200, true);
403 // change the height to 150px and animate with a custom configuration
404 Ext.fly('elId').setHeight(150, {
405 duration : .5, // animation will have a duration of .5 seconds
406 // will change the content to "finished"
407 callback: function(){ this.{@link #update}("finished"); }
410 * @param {Mixed} height The new height. This may be one of:<div class="mdetail-params"><ul>
411 * <li>A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels.)</li>
412 * <li>A String used to set the CSS height style. Animation may <b>not</b> be used.</li>
414 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
415 * @return {Ext.Element} this
417 setHeight : function(height, animate){
419 height = me.adjustHeight(height);
420 !animate || !me.anim ?
421 me.dom.style.height = me.addUnits(height) :
422 me.anim({height : {to : height}}, me.preanim(arguments, 1));
426 <div id="method-Ext.Element-getBorderWidth"></div>/**
427 * Gets the width of the border(s) for the specified side(s)
428 * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
429 * passing <tt>'lr'</tt> would get the border <b><u>l</u></b>eft width + the border <b><u>r</u></b>ight width.
430 * @return {Number} The width of the sides passed added together
432 getBorderWidth : function(side){
433 return this.addStyles(side, borders);
436 <div id="method-Ext.Element-getPadding"></div>/**
437 * Gets the width of the padding(s) for the specified side(s)
438 * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
439 * passing <tt>'lr'</tt> would get the padding <b><u>l</u></b>eft + the padding <b><u>r</u></b>ight.
440 * @return {Number} The padding of the sides passed added together
442 getPadding : function(side){
443 return this.addStyles(side, paddings);
446 <div id="method-Ext.Element-clip"></div>/**
447 * Store the current overflow setting and clip overflow on the element - use <tt>{@link #unclip}</tt> to remove
448 * @return {Ext.Element} this
454 if(!data(dom, ISCLIPPED)){
455 data(dom, ISCLIPPED, true);
456 data(dom, ORIGINALCLIP, {
457 o: me.getStyle(OVERFLOW),
458 x: me.getStyle(OVERFLOWX),
459 y: me.getStyle(OVERFLOWY)
461 me.setStyle(OVERFLOW, HIDDEN);
462 me.setStyle(OVERFLOWX, HIDDEN);
463 me.setStyle(OVERFLOWY, HIDDEN);
468 <div id="method-Ext.Element-unclip"></div>/**
469 * Return clipping (overflow) to original clipping before <tt>{@link #clip}</tt> was called
470 * @return {Ext.Element} this
476 if(data(dom, ISCLIPPED)){
477 data(dom, ISCLIPPED, false);
478 var o = data(dom, ORIGINALCLIP);
480 me.setStyle(OVERFLOW, o.o);
483 me.setStyle(OVERFLOWX, o.x);
486 me.setStyle(OVERFLOWY, o.y);
493 addStyles : function(sides, styles){
495 sidesArr = sides.match(wordsRe),
499 len = sidesArr.length;
500 for (i = 0; i < len; i++) {
502 size = side && parseInt(this.getStyle(styles[side]), 10);
504 ttlSize += MATH.abs(size);