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.1
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
15 <div id="cls-Ext.Element"></div>/**
18 Ext.Element.addMethods(function(){
19 // local style camelizing for speed
21 camelRe = /(-[a-z])/gi,
23 view = document.defaultView,
24 propFloat = Ext.isIE ? 'styleFloat' : 'cssFloat',
25 opacityRe = /alpha\(opacity=(.*)\)/i,
26 trimRe = /^\s+|\s+$/g,
40 ISCLIPPED = 'isClipped',
41 OVERFLOW = 'overflow',
42 OVERFLOWX = 'overflow-x',
43 OVERFLOWY = 'overflow-y',
44 ORIGINALCLIP = 'originalClip',
45 // special markup used throughout Ext when box wrapping elements
46 borders = {l: BORDER + LEFT + WIDTH, r: BORDER + RIGHT + WIDTH, t: BORDER + TOP + WIDTH, b: BORDER + BOTTOM + WIDTH},
47 paddings = {l: PADDING + LEFT, r: PADDING + RIGHT, t: PADDING + TOP, b: PADDING + BOTTOM},
48 margins = {l: MARGIN + LEFT, r: MARGIN + RIGHT, t: MARGIN + TOP, b: MARGIN + BOTTOM},
49 data = Ext.Element.data;
53 function camelFn(m, a) {
54 return a.charAt(1).toUpperCase();
57 function chkCache(prop) {
58 return propCache[prop] || (propCache[prop] = prop == 'float' ? propFloat : prop.replace(camelRe, camelFn));
62 // private ==> used by Fx
63 adjustWidth : function(width) {
65 var isNum = (typeof width == "number");
66 if(isNum && me.autoBoxAdjust && !me.isBorderBox()){
67 width -= (me.getBorderWidth("lr") + me.getPadding("lr"));
69 return (isNum && width < 0) ? 0 : width;
72 // private ==> used by Fx
73 adjustHeight : function(height) {
75 var isNum = (typeof height == "number");
76 if(isNum && me.autoBoxAdjust && !me.isBorderBox()){
77 height -= (me.getBorderWidth("tb") + me.getPadding("tb"));
79 return (isNum && height < 0) ? 0 : height;
83 <div id="method-Ext.Element-addClass"></div>/**
84 * Adds one or more CSS classes to the element. Duplicate classes are automatically filtered out.
85 * @param {String/Array} className The CSS class to add, or an array of classes
86 * @return {Ext.Element} this
88 addClass : function(className){
94 // Separate case is for speed
95 if (!Ext.isArray(className)) {
96 if (typeof className == 'string' && !this.hasClass(className)) {
97 me.dom.className += " " + className;
101 for (i = 0, len = className.length; i < len; i++) {
103 if (typeof v == 'string' && (' ' + me.dom.className + ' ').indexOf(' ' + v + ' ') == -1) {
108 me.dom.className += " " + cls.join(" ");
114 <div id="method-Ext.Element-removeClass"></div>/**
115 * Removes one or more CSS classes from the element.
116 * @param {String/Array} className The CSS class to remove, or an array of classes
117 * @return {Ext.Element} this
119 removeClass : function(className){
126 if (!Ext.isArray(className)){
127 className = [className];
129 if (me.dom && me.dom.className) {
130 elClasses = me.dom.className.replace(trimRe, '').split(spacesRe);
131 for (i = 0, len = className.length; i < len; i++) {
133 if (typeof cls == 'string') {
134 cls = cls.replace(trimRe, '');
135 idx = elClasses.indexOf(cls);
137 elClasses.splice(idx, 1);
141 me.dom.className = elClasses.join(" ");
146 <div id="method-Ext.Element-radioClass"></div>/**
147 * Adds one or more CSS classes to this element and removes the same class(es) from all siblings.
148 * @param {String/Array} className The CSS class to add, or an array of classes
149 * @return {Ext.Element} this
151 radioClass : function(className){
152 var cn = this.dom.parentNode.childNodes,
156 className = Ext.isArray(className) ? className : [className];
157 for (i = 0, len = cn.length; i < len; i++) {
159 if (v && v.nodeType == 1) {
160 Ext.fly(v, '_internal').removeClass(className);
163 return this.addClass(className);
166 <div id="method-Ext.Element-toggleClass"></div>/**
167 * Toggles the specified CSS class on this element (removes it if it already exists, otherwise adds it).
168 * @param {String} className The CSS class to toggle
169 * @return {Ext.Element} this
171 toggleClass : function(className){
172 return this.hasClass(className) ? this.removeClass(className) : this.addClass(className);
175 <div id="method-Ext.Element-hasClass"></div>/**
176 * Checks if the specified CSS class exists on this element's DOM node.
177 * @param {String} className The CSS class to check for
178 * @return {Boolean} True if the class exists, else false
180 hasClass : function(className){
181 return className && (' '+this.dom.className+' ').indexOf(' '+className+' ') != -1;
184 <div id="method-Ext.Element-replaceClass"></div>/**
185 * Replaces a CSS class on the element with another. If the old name does not exist, the new name will simply be added.
186 * @param {String} oldClassName The CSS class to replace
187 * @param {String} newClassName The replacement CSS class
188 * @return {Ext.Element} this
190 replaceClass : function(oldClassName, newClassName){
191 return this.removeClass(oldClassName).addClass(newClassName);
194 isStyle : function(style, val) {
195 return this.getStyle(style) == val;
198 <div id="method-Ext.Element-getStyle"></div>/**
199 * Normalizes currentStyle and computedStyle.
200 * @param {String} property The style property whose value is returned.
201 * @return {String} The current value of the style property for this element.
203 getStyle : function(){
204 return view && view.getComputedStyle ?
217 prop = chkCache(prop);
218 // Fix bug caused by this: https://bugs.webkit.org/show_bug.cgi?id=13343
219 if(wk && /marginRight/.test(prop)){
220 display = this.getStyle('display');
221 el.style.display = 'inline-block';
223 out = (v = el.style[prop]) ? v :
224 (cs = view.getComputedStyle(el, "")) ? cs[prop] : null;
226 // Webkit returns rgb values for transparent.
228 if(out == 'rgba(0, 0, 0, 0)'){
231 el.style.display = display;
241 if(el == document) return null;
242 if (prop == 'opacity') {
243 if (el.style.filter.match) {
244 if(m = el.style.filter.match(opacityRe)){
245 var fv = parseFloat(m[1]);
247 return fv ? fv / 100 : 0;
253 prop = chkCache(prop);
254 return el.style[prop] || ((cs = el.currentStyle) ? cs[prop] : null);
258 <div id="method-Ext.Element-getColor"></div>/**
259 * Return the CSS color for the specified CSS attribute. rgb, 3 digit (like #fff) and valid values
260 * are convert to standard 6 digit hex color.
261 * @param {String} attr The css attribute
262 * @param {String} defaultValue The default value to use when a valid color isn't found
263 * @param {String} prefix (optional) defaults to #. Use an empty string when working with
266 getColor : function(attr, defaultValue, prefix){
267 var v = this.getStyle(attr),
268 color = (typeof prefix != 'undefined') ? prefix : '#',
271 if(!v || /transparent|inherit/.test(v)){
275 Ext.each(v.slice(4, v.length -1).split(','), function(s){
277 color += (h < 16 ? '0' : '') + h.toString(16);
280 v = v.replace('#', '');
281 color += v.length == 3 ? v.replace(/^(\w)(\w)(\w)$/, '$1$1$2$2$3$3') : v;
283 return(color.length > 5 ? color.toLowerCase() : defaultValue);
286 <div id="method-Ext.Element-setStyle"></div>/**
287 * Wrapper for setting style properties, also takes single object parameter of multiple styles.
288 * @param {String/Object} property The style property to be set, or an object of multiple styles.
289 * @param {String} value (optional) The value to apply to the given property, or null if an object was passed.
290 * @return {Ext.Element} this
292 setStyle : function(prop, value){
296 if (typeof prop != 'object') {
301 for (style in prop) {
304 this.setOpacity(value) :
305 this.dom.style[chkCache(style)] = value;
310 <div id="method-Ext.Element-setOpacity"></div>/**
311 * Set the opacity of the element
312 * @param {Float} opacity The new opacity. 0 = transparent, .5 = 50% visibile, 1 = fully visible, etc
313 * @param {Boolean/Object} animate (optional) a standard Element animation config object or <tt>true</tt> for
314 * the default animation (<tt>{duration: .35, easing: 'easeIn'}</tt>)
315 * @return {Ext.Element} this
317 setOpacity : function(opacity, animate){
321 if(!animate || !me.anim){
323 var opac = opacity < 1 ? 'alpha(opacity=' + opacity * 100 + ')' : '',
324 val = s.filter.replace(opacityRe, '').replace(trimRe, '');
327 s.filter = val + (val.length > 0 ? ' ' : '') + opac;
332 me.anim({opacity: {to: opacity}}, me.preanim(arguments, 1), null, .35, 'easeIn');
337 <div id="method-Ext.Element-clearOpacity"></div>/**
338 * Clears any opacity settings from this element. Required in some cases for IE.
339 * @return {Ext.Element} this
341 clearOpacity : function(){
342 var style = this.dom.style;
344 if(!Ext.isEmpty(style.filter)){
345 style.filter = style.filter.replace(opacityRe, '').replace(trimRe, '');
348 style.opacity = style['-moz-opacity'] = style['-khtml-opacity'] = '';
353 <div id="method-Ext.Element-getHeight"></div>/**
354 * Returns the offset height of the element
355 * @param {Boolean} contentHeight (optional) true to get the height minus borders and padding
356 * @return {Number} The element's height
358 getHeight : function(contentHeight){
361 hidden = Ext.isIE && me.isStyle('display', 'none'),
362 h = MATH.max(dom.offsetHeight, hidden ? 0 : dom.clientHeight) || 0;
364 h = !contentHeight ? h : h - me.getBorderWidth("tb") - me.getPadding("tb");
365 return h < 0 ? 0 : h;
368 <div id="method-Ext.Element-getWidth"></div>/**
369 * Returns the offset width of the element
370 * @param {Boolean} contentWidth (optional) true to get the width minus borders and padding
371 * @return {Number} The element's width
373 getWidth : function(contentWidth){
376 hidden = Ext.isIE && me.isStyle('display', 'none'),
377 w = MATH.max(dom.offsetWidth, hidden ? 0 : dom.clientWidth) || 0;
378 w = !contentWidth ? w : w - me.getBorderWidth("lr") - me.getPadding("lr");
379 return w < 0 ? 0 : w;
382 <div id="method-Ext.Element-setWidth"></div>/**
383 * Set the width of this Element.
384 * @param {Mixed} width The new width. This may be one of:<div class="mdetail-params"><ul>
385 * <li>A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels).</li>
386 * <li>A String used to set the CSS width style. Animation may <b>not</b> be used.
388 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
389 * @return {Ext.Element} this
391 setWidth : function(width, animate){
393 width = me.adjustWidth(width);
394 !animate || !me.anim ?
395 me.dom.style.width = me.addUnits(width) :
396 me.anim({width : {to : width}}, me.preanim(arguments, 1));
400 <div id="method-Ext.Element-setHeight"></div>/**
401 * Set the height of this Element.
403 // change the height to 200px and animate with default configuration
404 Ext.fly('elementId').setHeight(200, true);
406 // change the height to 150px and animate with a custom configuration
407 Ext.fly('elId').setHeight(150, {
408 duration : .5, // animation will have a duration of .5 seconds
409 // will change the content to "finished"
410 callback: function(){ this.{@link #update}("finished"); }
413 * @param {Mixed} height The new height. This may be one of:<div class="mdetail-params"><ul>
414 * <li>A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels.)</li>
415 * <li>A String used to set the CSS height style. Animation may <b>not</b> be used.</li>
417 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
418 * @return {Ext.Element} this
420 setHeight : function(height, animate){
422 height = me.adjustHeight(height);
423 !animate || !me.anim ?
424 me.dom.style.height = me.addUnits(height) :
425 me.anim({height : {to : height}}, me.preanim(arguments, 1));
429 <div id="method-Ext.Element-getBorderWidth"></div>/**
430 * Gets the width of the border(s) for the specified side(s)
431 * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
432 * passing <tt>'lr'</tt> would get the border <b><u>l</u></b>eft width + the border <b><u>r</u></b>ight width.
433 * @return {Number} The width of the sides passed added together
435 getBorderWidth : function(side){
436 return this.addStyles(side, borders);
439 <div id="method-Ext.Element-getPadding"></div>/**
440 * Gets the width of the padding(s) for the specified side(s)
441 * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
442 * passing <tt>'lr'</tt> would get the padding <b><u>l</u></b>eft + the padding <b><u>r</u></b>ight.
443 * @return {Number} The padding of the sides passed added together
445 getPadding : function(side){
446 return this.addStyles(side, paddings);
449 <div id="method-Ext.Element-clip"></div>/**
450 * Store the current overflow setting and clip overflow on the element - use <tt>{@link #unclip}</tt> to remove
451 * @return {Ext.Element} this
457 if(!data(dom, ISCLIPPED)){
458 data(dom, ISCLIPPED, true);
459 data(dom, ORIGINALCLIP, {
460 o: me.getStyle(OVERFLOW),
461 x: me.getStyle(OVERFLOWX),
462 y: me.getStyle(OVERFLOWY)
464 me.setStyle(OVERFLOW, HIDDEN);
465 me.setStyle(OVERFLOWX, HIDDEN);
466 me.setStyle(OVERFLOWY, HIDDEN);
471 <div id="method-Ext.Element-unclip"></div>/**
472 * Return clipping (overflow) to original clipping before <tt>{@link #clip}</tt> was called
473 * @return {Ext.Element} this
479 if(data(dom, ISCLIPPED)){
480 data(dom, ISCLIPPED, false);
481 var o = data(dom, ORIGINALCLIP);
483 me.setStyle(OVERFLOW, o.o);
486 me.setStyle(OVERFLOWX, o.x);
489 me.setStyle(OVERFLOWY, o.y);
496 addStyles : function(sides, styles){
498 sidesArr = sides.match(wordsRe),
502 len = sidesArr.length;
503 for (i = 0; i < len; i++) {
505 size = side && parseInt(this.getStyle(styles[side]), 10);
507 ttlSize += MATH.abs(size);