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.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.com/license
19 // special markup used throughout Ext when box wrapping elements
20 Ext.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>';
22 Ext.Element.addMethods(function(){
23 var INTERNAL = "_internal",
24 pxMatch = /(\d+\.?\d+)px/;
26 <div id="method-Ext.Element-applyStyles"></div>/**
27 * More flexible version of {@link #setStyle} for setting style properties.
28 * @param {String/Object/Function} styles A style specification string, e.g. "width:100px", or object in the form {width:"100px"}, or
29 * a function which returns such a specification.
30 * @return {Ext.Element} this
32 applyStyles : function(style){
33 Ext.DomHelper.applyStyles(this.dom, style);
37 <div id="method-Ext.Element-getStyles"></div>/**
38 * Returns an object with properties matching the styles requested.
39 * For example, el.getStyles('color', 'font-size', 'width') might return
40 * {'color': '#FFFFFF', 'font-size': '13px', 'width': '100px'}.
41 * @param {String} style1 A style name
42 * @param {String} style2 A style name
43 * @param {String} etc.
44 * @return {Object} The style object
46 getStyles : function(){
48 Ext.each(arguments, function(v) {
49 ret[v] = this.getStyle(v);
55 // private ==> used by ext full
56 setOverflow : function(v){
58 if(v=='auto' && Ext.isMac && Ext.isGecko2){ // work around stupid FF 2.0/Mac scroll bar bug
59 dom.style.overflow = 'hidden';
60 (function(){dom.style.overflow = 'auto';}).defer(1);
62 dom.style.overflow = v;
66 <div id="method-Ext.Element-boxWrap"></div>/**
67 * <p>Wraps the specified element with a special 9 element markup/CSS block that renders by default as
68 * a gray container with a gradient background, rounded corners and a 4-way shadow.</p>
69 * <p>This special markup is used throughout Ext when box wrapping elements ({@link Ext.Button},
70 * {@link Ext.Panel} when <tt>{@link Ext.Panel#frame frame=true}</tt>, {@link Ext.Window}). The markup
71 * is of this form:</p>
73 Ext.Element.boxMarkup =
74 '<div class="{0}-tl"><div class="{0}-tr"><div class="{0}-tc"></div></div></div>
75 <div class="{0}-ml"><div class="{0}-mr"><div class="{0}-mc"></div></div></div>
76 <div class="{0}-bl"><div class="{0}-br"><div class="{0}-bc"></div></div></div>';
78 * <p>Example usage:</p>
81 Ext.get("foo").boxWrap();
83 // You can also add a custom class and use CSS inheritance rules to customize the box look.
84 // 'x-box-blue' is a built-in alternative -- look at the related CSS definitions as an example
85 // for how to create a custom box wrap style.
86 Ext.get("foo").boxWrap().addClass("x-box-blue");
88 * @param {String} class (optional) A base CSS class to apply to the containing wrapper element
89 * (defaults to <tt>'x-box'</tt>). Note that there are a number of CSS rules that are dependent on
90 * this name to make the overall effect work, so if you supply an alternate base class, make sure you
91 * also supply all of the necessary rules.
92 * @return {Ext.Element} The outermost wrapping element of the created box structure.
94 boxWrap : function(cls){
96 var el = Ext.get(this.insertHtml("beforeBegin", "<div class='" + cls + "'>" + String.format(Ext.Element.boxMarkup, cls) + "</div>")); //String.format('<div class="{0}">'+Ext.Element.boxMarkup+'</div>', cls)));
97 Ext.DomQuery.selectNode('.' + cls + '-mc', el.dom).appendChild(this.dom);
101 <div id="method-Ext.Element-setSize"></div>/**
102 * Set the size of this Element. If animation is true, both width and height will be animated concurrently.
103 * @param {Mixed} width The new width. This may be one of:<div class="mdetail-params"><ul>
104 * <li>A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels).</li>
105 * <li>A String used to set the CSS width style. Animation may <b>not</b> be used.
106 * <li>A size object in the format <code>{width: widthValue, height: heightValue}</code>.</li>
108 * @param {Mixed} height The new height. This may be one of:<div class="mdetail-params"><ul>
109 * <li>A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels).</li>
110 * <li>A String used to set the CSS height style. Animation may <b>not</b> be used.</li>
112 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
113 * @return {Ext.Element} this
115 setSize : function(width, height, animate){
117 if(typeof width == 'object'){ // in case of object from getSize()
118 height = width.height;
121 width = me.adjustWidth(width);
122 height = me.adjustHeight(height);
123 if(!animate || !me.anim){
124 me.dom.style.width = me.addUnits(width);
125 me.dom.style.height = me.addUnits(height);
127 me.anim({width: {to: width}, height: {to: height}}, me.preanim(arguments, 2));
132 <div id="method-Ext.Element-getComputedHeight"></div>/**
133 * Returns either the offsetHeight or the height of this element based on CSS height adjusted by padding or borders
134 * when needed to simulate offsetHeight when offsets aren't available. This may not work on display:none elements
135 * if a height has not been set using CSS.
138 getComputedHeight : function(){
140 h = Math.max(me.dom.offsetHeight, me.dom.clientHeight);
142 h = parseFloat(me.getStyle('height')) || 0;
143 if(!me.isBorderBox()){
144 h += me.getFrameWidth('tb');
150 <div id="method-Ext.Element-getComputedWidth"></div>/**
151 * Returns either the offsetWidth or the width of this element based on CSS width adjusted by padding or borders
152 * when needed to simulate offsetWidth when offsets aren't available. This may not work on display:none elements
153 * if a width has not been set using CSS.
156 getComputedWidth : function(){
157 var w = Math.max(this.dom.offsetWidth, this.dom.clientWidth);
159 w = parseFloat(this.getStyle('width')) || 0;
160 if(!this.isBorderBox()){
161 w += this.getFrameWidth('lr');
167 <div id="method-Ext.Element-getFrameWidth"></div>/**
168 * Returns the sum width of the padding and borders for the passed "sides". See getBorderWidth()
169 for more information about the sides.
170 * @param {String} sides
173 getFrameWidth : function(sides, onlyContentBox){
174 return onlyContentBox && this.isBorderBox() ? 0 : (this.getPadding(sides) + this.getBorderWidth(sides));
177 <div id="method-Ext.Element-addClassOnOver"></div>/**
178 * Sets up event handlers to add and remove a css class when the mouse is over this element
179 * @param {String} className
180 * @return {Ext.Element} this
182 addClassOnOver : function(className){
185 Ext.fly(this, INTERNAL).addClass(className);
188 Ext.fly(this, INTERNAL).removeClass(className);
194 <div id="method-Ext.Element-addClassOnFocus"></div>/**
195 * Sets up event handlers to add and remove a css class when this element has the focus
196 * @param {String} className
197 * @return {Ext.Element} this
199 addClassOnFocus : function(className){
200 this.on("focus", function(){
201 Ext.fly(this, INTERNAL).addClass(className);
203 this.on("blur", function(){
204 Ext.fly(this, INTERNAL).removeClass(className);
209 <div id="method-Ext.Element-addClassOnClick"></div>/**
210 * 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)
211 * @param {String} className
212 * @return {Ext.Element} this
214 addClassOnClick : function(className){
216 this.on("mousedown", function(){
217 Ext.fly(dom, INTERNAL).addClass(className);
218 var d = Ext.getDoc(),
220 Ext.fly(dom, INTERNAL).removeClass(className);
221 d.removeListener("mouseup", fn);
228 <div id="method-Ext.Element-getViewSize"></div>/**
229 * <p>Returns the dimensions of the element available to lay content out in.<p>
230 * <p>If the element (or any ancestor element) has CSS style <code>display : none</code>, the dimensions will be zero.</p>
231 * example:<pre><code>
232 var vpSize = Ext.getBody().getViewSize();
234 // all Windows created afterwards will have a default value of 90% height and 95% width
235 Ext.Window.override({
236 width: vpSize.width * 0.9,
237 height: vpSize.height * 0.95
239 // To handle window resizing you would have to hook onto onWindowResize.
242 * getViewSize utilizes clientHeight/clientWidth which excludes sizing of scrollbars.
243 * To obtain the size including scrollbars, use getStyleSize
245 * Sizing of the document body is handled at the adapter level which handles special cases for IE and strict modes, etc.
248 getViewSize : function(){
251 isDoc = (d == doc || d == doc.body);
253 // If the body, use Ext.lib.Dom
255 var extdom = Ext.lib.Dom;
257 width : extdom.getViewWidth(),
258 height : extdom.getViewHeight()
261 // Else use clientHeight/clientWidth
264 width : d.clientWidth,
265 height : d.clientHeight
270 <div id="method-Ext.Element-getStyleSize"></div>/**
271 * <p>Returns the dimensions of the element available to lay content out in.<p>
273 * getStyleSize utilizes prefers style sizing if present, otherwise it chooses the larger of offsetHeight/clientHeight and offsetWidth/clientWidth.
274 * To obtain the size excluding scrollbars, use getViewSize
276 * Sizing of the document body is handled at the adapter level which handles special cases for IE and strict modes, etc.
279 getStyleSize : function(){
284 isDoc = (d == doc || d == doc.body),
287 // If the body, use Ext.lib.Dom
289 var extdom = Ext.lib.Dom;
291 width : extdom.getViewWidth(),
292 height : extdom.getViewHeight()
295 // Use Styles if they are set
296 if(s.width && s.width != 'auto'){
297 w = parseFloat(s.width);
298 if(me.isBorderBox()){
299 w -= me.getFrameWidth('lr');
302 // Use Styles if they are set
303 if(s.height && s.height != 'auto'){
304 h = parseFloat(s.height);
305 if(me.isBorderBox()){
306 h -= me.getFrameWidth('tb');
309 // Use getWidth/getHeight if style not set.
310 return {width: w || me.getWidth(true), height: h || me.getHeight(true)};
313 <div id="method-Ext.Element-getSize"></div>/**
314 * Returns the size of the element.
315 * @param {Boolean} contentSize (optional) true to get the width/size minus borders and padding
316 * @return {Object} An object containing the element's size {width: (element width), height: (element height)}
318 getSize : function(contentSize){
319 return {width: this.getWidth(contentSize), height: this.getHeight(contentSize)};
322 <div id="method-Ext.Element-repaint"></div>/**
323 * Forces the browser to repaint this element
324 * @return {Ext.Element} this
326 repaint : function(){
328 this.addClass("x-repaint");
329 setTimeout(function(){
330 Ext.fly(dom).removeClass("x-repaint");
335 <div id="method-Ext.Element-unselectable"></div>/**
336 * Disables text selection for this element (normalized across browsers)
337 * @return {Ext.Element} this
339 unselectable : function(){
340 this.dom.unselectable = "on";
341 return this.swallowEvent("selectstart", true).
342 applyStyles("-moz-user-select:none;-khtml-user-select:none;").
343 addClass("x-unselectable");
346 <div id="method-Ext.Element-getMargins"></div>/**
347 * Returns an object with properties top, left, right and bottom representing the margins of this element unless sides is passed,
348 * then it returns the calculated width of the sides (see getPadding)
349 * @param {String} sides (optional) Any combination of l, r, t, b to get the sum of those sides
350 * @return {Object/Number}
352 getMargins : function(side){
355 hash = {t:"top", l:"left", r:"right", b: "bottom"},
359 for (key in me.margins){
360 o[hash[key]] = parseFloat(me.getStyle(me.margins[key])) || 0;
364 return me.addStyles.call(me, side, me.margins);