3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js">/**
\r
10 * @class Ext.Element
\r
13 // special markup used throughout Ext when box wrapping elements
\r
14 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>';
\r
16 Ext.Element.addMethods(function(){
\r
17 var INTERNAL = "_internal",
\r
18 pxMatch = /(\d+\.?\d+)px/;
\r
20 <div id="method-Ext.Element-applyStyles"></div>/**
\r
21 * More flexible version of {@link #setStyle} for setting style properties.
\r
22 * @param {String/Object/Function} styles A style specification string, e.g. "width:100px", or object in the form {width:"100px"}, or
\r
23 * a function which returns such a specification.
\r
24 * @return {Ext.Element} this
\r
26 applyStyles : function(style){
\r
27 Ext.DomHelper.applyStyles(this.dom, style);
\r
31 <div id="method-Ext.Element-getStyles"></div>/**
\r
32 * Returns an object with properties matching the styles requested.
\r
33 * For example, el.getStyles('color', 'font-size', 'width') might return
\r
34 * {'color': '#FFFFFF', 'font-size': '13px', 'width': '100px'}.
\r
35 * @param {String} style1 A style name
\r
36 * @param {String} style2 A style name
\r
37 * @param {String} etc.
\r
38 * @return {Object} The style object
\r
40 getStyles : function(){
\r
42 Ext.each(arguments, function(v) {
\r
43 ret[v] = this.getStyle(v);
\r
49 // private ==> used by ext full
\r
50 setOverflow : function(v){
\r
52 if(v=='auto' && Ext.isMac && Ext.isGecko2){ // work around stupid FF 2.0/Mac scroll bar bug
\r
53 dom.style.overflow = 'hidden';
\r
54 (function(){dom.style.overflow = 'auto';}).defer(1);
\r
56 dom.style.overflow = v;
\r
60 <div id="method-Ext.Element-boxWrap"></div>/**
\r
61 * <p>Wraps the specified element with a special 9 element markup/CSS block that renders by default as
\r
62 * a gray container with a gradient background, rounded corners and a 4-way shadow.</p>
\r
63 * <p>This special markup is used throughout Ext when box wrapping elements ({@link Ext.Button},
\r
64 * {@link Ext.Panel} when <tt>{@link Ext.Panel#frame frame=true}</tt>, {@link Ext.Window}). The markup
\r
65 * is of this form:</p>
\r
67 Ext.Element.boxMarkup =
\r
68 '<div class="{0}-tl"><div class="{0}-tr"><div class="{0}-tc"></div></div></div>
\r
69 <div class="{0}-ml"><div class="{0}-mr"><div class="{0}-mc"></div></div></div>
\r
70 <div class="{0}-bl"><div class="{0}-br"><div class="{0}-bc"></div></div></div>';
\r
72 * <p>Example usage:</p>
\r
75 Ext.get("foo").boxWrap();
\r
77 // You can also add a custom class and use CSS inheritance rules to customize the box look.
\r
78 // 'x-box-blue' is a built-in alternative -- look at the related CSS definitions as an example
\r
79 // for how to create a custom box wrap style.
\r
80 Ext.get("foo").boxWrap().addClass("x-box-blue");
\r
82 * @param {String} class (optional) A base CSS class to apply to the containing wrapper element
\r
83 * (defaults to <tt>'x-box'</tt>). Note that there are a number of CSS rules that are dependent on
\r
84 * this name to make the overall effect work, so if you supply an alternate base class, make sure you
\r
85 * also supply all of the necessary rules.
\r
86 * @return {Ext.Element} The outermost wrapping element of the created box structure.
\r
88 boxWrap : function(cls){
\r
89 cls = cls || 'x-box';
\r
90 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)));
\r
91 Ext.DomQuery.selectNode('.' + cls + '-mc', el.dom).appendChild(this.dom);
\r
95 <div id="method-Ext.Element-setSize"></div>/**
\r
96 * Set the size of this Element. If animation is true, both width and height will be animated concurrently.
\r
97 * @param {Mixed} width The new width. This may be one of:<div class="mdetail-params"><ul>
\r
98 * <li>A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels).</li>
\r
99 * <li>A String used to set the CSS width style. Animation may <b>not</b> be used.
\r
100 * <li>A size object in the format <code>{width: widthValue, height: heightValue}</code>.</li>
\r
102 * @param {Mixed} height The new height. This may be one of:<div class="mdetail-params"><ul>
\r
103 * <li>A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels).</li>
\r
104 * <li>A String used to set the CSS height style. Animation may <b>not</b> be used.</li>
\r
106 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
\r
107 * @return {Ext.Element} this
\r
109 setSize : function(width, height, animate){
\r
111 if(Ext.isObject(width)){ // in case of object from getSize()
\r
112 height = width.height;
\r
113 width = width.width;
\r
115 width = me.adjustWidth(width);
\r
116 height = me.adjustHeight(height);
\r
117 if(!animate || !me.anim){
\r
118 me.dom.style.width = me.addUnits(width);
\r
119 me.dom.style.height = me.addUnits(height);
\r
121 me.anim({width: {to: width}, height: {to: height}}, me.preanim(arguments, 2));
\r
126 <div id="method-Ext.Element-getComputedHeight"></div>/**
\r
127 * Returns either the offsetHeight or the height of this element based on CSS height adjusted by padding or borders
\r
128 * when needed to simulate offsetHeight when offsets aren't available. This may not work on display:none elements
\r
129 * if a height has not been set using CSS.
\r
132 getComputedHeight : function(){
\r
134 h = Math.max(me.dom.offsetHeight, me.dom.clientHeight);
\r
136 h = parseFloat(me.getStyle('height')) || 0;
\r
137 if(!me.isBorderBox()){
\r
138 h += me.getFrameWidth('tb');
\r
144 <div id="method-Ext.Element-getComputedWidth"></div>/**
\r
145 * Returns either the offsetWidth or the width of this element based on CSS width adjusted by padding or borders
\r
146 * when needed to simulate offsetWidth when offsets aren't available. This may not work on display:none elements
\r
147 * if a width has not been set using CSS.
\r
150 getComputedWidth : function(){
\r
151 var w = Math.max(this.dom.offsetWidth, this.dom.clientWidth);
\r
153 w = parseFloat(this.getStyle('width')) || 0;
\r
154 if(!this.isBorderBox()){
\r
155 w += this.getFrameWidth('lr');
\r
161 <div id="method-Ext.Element-getFrameWidth"></div>/**
\r
162 * Returns the sum width of the padding and borders for the passed "sides". See getBorderWidth()
\r
163 for more information about the sides.
\r
164 * @param {String} sides
\r
167 getFrameWidth : function(sides, onlyContentBox){
\r
168 return onlyContentBox && this.isBorderBox() ? 0 : (this.getPadding(sides) + this.getBorderWidth(sides));
\r
171 <div id="method-Ext.Element-addClassOnOver"></div>/**
\r
172 * Sets up event handlers to add and remove a css class when the mouse is over this element
\r
173 * @param {String} className
\r
174 * @return {Ext.Element} this
\r
176 addClassOnOver : function(className){
\r
179 Ext.fly(this, INTERNAL).addClass(className);
\r
182 Ext.fly(this, INTERNAL).removeClass(className);
\r
188 <div id="method-Ext.Element-addClassOnFocus"></div>/**
\r
189 * Sets up event handlers to add and remove a css class when this element has the focus
\r
190 * @param {String} className
\r
191 * @return {Ext.Element} this
\r
193 addClassOnFocus : function(className){
\r
194 this.on("focus", function(){
\r
195 Ext.fly(this, INTERNAL).addClass(className);
\r
197 this.on("blur", function(){
\r
198 Ext.fly(this, INTERNAL).removeClass(className);
\r
203 <div id="method-Ext.Element-addClassOnClick"></div>/**
\r
204 * 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)
\r
205 * @param {String} className
\r
206 * @return {Ext.Element} this
\r
208 addClassOnClick : function(className){
\r
209 var dom = this.dom;
\r
210 this.on("mousedown", function(){
\r
211 Ext.fly(dom, INTERNAL).addClass(className);
\r
212 var d = Ext.getDoc(),
\r
214 Ext.fly(dom, INTERNAL).removeClass(className);
\r
215 d.removeListener("mouseup", fn);
\r
217 d.on("mouseup", fn);
\r
222 <div id="method-Ext.Element-getViewSize"></div>/**
\r
223 * <p>Returns the dimensions of the element available to lay content out in.<p>
\r
224 * <p>If the element (or any ancestor element) has CSS style <code>display : none</code>, the dimensions will be zero.</p>
\r
225 * example:<pre><code>
\r
226 var vpSize = Ext.getBody().getViewSize();
\r
228 // all Windows created afterwards will have a default value of 90% height and 95% width
\r
229 Ext.Window.override({
\r
230 width: vpSize.width * 0.9,
\r
231 height: vpSize.height * 0.95
\r
233 // To handle window resizing you would have to hook onto onWindowResize.
\r
236 * getViewSize utilizes clientHeight/clientWidth which excludes sizing of scrollbars.
\r
237 * To obtain the size including scrollbars, use getStyleSize
\r
239 * Sizing of the document body is handled at the adapter level which handles special cases for IE and strict modes, etc.
\r
242 getViewSize : function(){
\r
243 var doc = document,
\r
245 isDoc = (d == doc || d == doc.body);
\r
247 // If the body, use Ext.lib.Dom
\r
249 var extdom = Ext.lib.Dom;
\r
251 width : extdom.getViewWidth(),
\r
252 height : extdom.getViewHeight()
\r
255 // Else use clientHeight/clientWidth
\r
258 width : d.clientWidth,
\r
259 height : d.clientHeight
\r
264 <div id="method-Ext.Element-getStyleSize"></div>/**
\r
265 * <p>Returns the dimensions of the element available to lay content out in.<p>
\r
267 * getStyleSize utilizes prefers style sizing if present, otherwise it chooses the larger of offsetHeight/clientHeight and offsetWidth/clientWidth.
\r
268 * To obtain the size excluding scrollbars, use getViewSize
\r
270 * Sizing of the document body is handled at the adapter level which handles special cases for IE and strict modes, etc.
\r
273 getStyleSize : function(){
\r
278 isDoc = (d == doc || d == doc.body),
\r
281 // If the body, use Ext.lib.Dom
\r
283 var extdom = Ext.lib.Dom;
\r
285 width : extdom.getViewWidth(),
\r
286 height : extdom.getViewHeight()
\r
289 // Use Styles if they are set
\r
290 if(s.width && s.width != 'auto'){
\r
291 w = parseFloat(s.width);
\r
292 if(me.isBorderBox()){
\r
293 w -= me.getFrameWidth('lr');
\r
296 // Use Styles if they are set
\r
297 if(s.height && s.height != 'auto'){
\r
298 h = parseFloat(s.height);
\r
299 if(me.isBorderBox()){
\r
300 h -= me.getFrameWidth('tb');
\r
303 // Use getWidth/getHeight if style not set.
\r
304 return {width: w || me.getWidth(true), height: h || me.getHeight(true)};
\r
307 <div id="method-Ext.Element-getSize"></div>/**
\r
308 * Returns the size of the element.
\r
309 * @param {Boolean} contentSize (optional) true to get the width/size minus borders and padding
\r
310 * @return {Object} An object containing the element's size {width: (element width), height: (element height)}
\r
312 getSize : function(contentSize){
\r
313 return {width: this.getWidth(contentSize), height: this.getHeight(contentSize)};
\r
316 <div id="method-Ext.Element-repaint"></div>/**
\r
317 * Forces the browser to repaint this element
\r
318 * @return {Ext.Element} this
\r
320 repaint : function(){
\r
321 var dom = this.dom;
\r
322 this.addClass("x-repaint");
\r
323 setTimeout(function(){
\r
324 Ext.fly(dom).removeClass("x-repaint");
\r
329 <div id="method-Ext.Element-unselectable"></div>/**
\r
330 * Disables text selection for this element (normalized across browsers)
\r
331 * @return {Ext.Element} this
\r
333 unselectable : function(){
\r
334 this.dom.unselectable = "on";
\r
335 return this.swallowEvent("selectstart", true).
\r
336 applyStyles("-moz-user-select:none;-khtml-user-select:none;").
\r
337 addClass("x-unselectable");
\r
340 <div id="method-Ext.Element-getMargins"></div>/**
\r
341 * Returns an object with properties top, left, right and bottom representing the margins of this element unless sides is passed,
\r
342 * then it returns the calculated width of the sides (see getPadding)
\r
343 * @param {String} sides (optional) Any combination of l, r, t, b to get the sum of those sides
\r
344 * @return {Object/Number}
\r
346 getMargins : function(side){
\r
349 hash = {t:"top", l:"left", r:"right", b: "bottom"},
\r
353 for (key in me.margins){
\r
354 o[hash[key]] = parseFloat(me.getStyle(me.margins[key])) || 0;
\r
358 return me.addStyles.call(me, side, me.margins);
\r