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+)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
50 getStyleSize : function(){
\r
56 if(s.width && s.width != 'auto'){
\r
57 w = parseInt(s.width, 10);
\r
58 if(me.isBorderBox()){
\r
59 w -= me.getFrameWidth('lr');
\r
62 if(s.height && s.height != 'auto'){
\r
63 h = parseInt(s.height, 10);
\r
64 if(me.isBorderBox()){
\r
65 h -= me.getFrameWidth('tb');
\r
68 return {width: w || me.getWidth(true), height: h || me.getHeight(true)};
\r
71 // private ==> used by ext full
\r
72 setOverflow : function(v){
\r
74 if(v=='auto' && Ext.isMac && Ext.isGecko2){ // work around stupid FF 2.0/Mac scroll bar bug
\r
75 dom.style.overflow = 'hidden';
\r
76 (function(){dom.style.overflow = 'auto';}).defer(1);
\r
78 dom.style.overflow = v;
\r
82 <div id="method-Ext.Element-boxWrap"></div>/**
\r
83 * <p>Wraps the specified element with a special 9 element markup/CSS block that renders by default as
\r
84 * a gray container with a gradient background, rounded corners and a 4-way shadow.</p>
\r
85 * <p>This special markup is used throughout Ext when box wrapping elements ({@link Ext.Button},
\r
86 * {@link Ext.Panel} when <tt>{@link Ext.Panel#frame frame=true}</tt>, {@link Ext.Window}). The markup
\r
87 * is of this form:</p>
\r
89 Ext.Element.boxMarkup =
\r
90 '<div class="{0}-tl"><div class="{0}-tr"><div class="{0}-tc"></div></div></div>
\r
91 <div class="{0}-ml"><div class="{0}-mr"><div class="{0}-mc"></div></div></div>
\r
92 <div class="{0}-bl"><div class="{0}-br"><div class="{0}-bc"></div></div></div>';
\r
94 * <p>Example usage:</p>
\r
97 Ext.get("foo").boxWrap();
\r
99 // You can also add a custom class and use CSS inheritance rules to customize the box look.
\r
100 // 'x-box-blue' is a built-in alternative -- look at the related CSS definitions as an example
\r
101 // for how to create a custom box wrap style.
\r
102 Ext.get("foo").boxWrap().addClass("x-box-blue");
\r
104 * @param {String} class (optional) A base CSS class to apply to the containing wrapper element
\r
105 * (defaults to <tt>'x-box'</tt>). Note that there are a number of CSS rules that are dependent on
\r
106 * this name to make the overall effect work, so if you supply an alternate base class, make sure you
\r
107 * also supply all of the necessary rules.
\r
108 * @return {Ext.Element} The outermost wrapping element of the created box structure.
\r
110 boxWrap : function(cls){
\r
111 cls = cls || 'x-box';
\r
112 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
113 Ext.DomQuery.selectNode('.' + cls + '-mc', el.dom).appendChild(this.dom);
\r
117 <div id="method-Ext.Element-setSize"></div>/**
\r
118 * Set the size of this Element. If animation is true, both width and height will be animated concurrently.
\r
119 * @param {Mixed} width The new width. This may be one of:<div class="mdetail-params"><ul>
\r
120 * <li>A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels).</li>
\r
121 * <li>A String used to set the CSS width style. Animation may <b>not</b> be used.
\r
122 * <li>A size object in the format <code>{width: widthValue, height: heightValue}</code>.</li>
\r
124 * @param {Mixed} height The new height. This may be one of:<div class="mdetail-params"><ul>
\r
125 * <li>A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels).</li>
\r
126 * <li>A String used to set the CSS height style. Animation may <b>not</b> be used.</li>
\r
128 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
\r
129 * @return {Ext.Element} this
\r
131 setSize : function(width, height, animate){
\r
133 if(Ext.isObject(width)){ // in case of object from getSize()
\r
134 height = width.height;
\r
135 width = width.width;
\r
137 width = me.adjustWidth(width);
\r
138 height = me.adjustHeight(height);
\r
139 if(!animate || !me.anim){
\r
140 me.dom.style.width = me.addUnits(width);
\r
141 me.dom.style.height = me.addUnits(height);
\r
143 me.anim({width: {to: width}, height: {to: height}}, me.preanim(arguments, 2));
\r
148 <div id="method-Ext.Element-getComputedHeight"></div>/**
\r
149 * Returns either the offsetHeight or the height of this element based on CSS height adjusted by padding or borders
\r
150 * when needed to simulate offsetHeight when offsets aren't available. This may not work on display:none elements
\r
151 * if a height has not been set using CSS.
\r
154 getComputedHeight : function(){
\r
156 h = Math.max(me.dom.offsetHeight, me.dom.clientHeight);
\r
158 h = parseInt(me.getStyle('height'), 10) || 0;
\r
159 if(!me.isBorderBox()){
\r
160 h += me.getFrameWidth('tb');
\r
166 <div id="method-Ext.Element-getComputedWidth"></div>/**
\r
167 * Returns either the offsetWidth or the width of this element based on CSS width adjusted by padding or borders
\r
168 * when needed to simulate offsetWidth when offsets aren't available. This may not work on display:none elements
\r
169 * if a width has not been set using CSS.
\r
172 getComputedWidth : function(){
\r
173 var w = Math.max(this.dom.offsetWidth, this.dom.clientWidth);
\r
175 w = parseInt(this.getStyle('width'), 10) || 0;
\r
176 if(!this.isBorderBox()){
\r
177 w += this.getFrameWidth('lr');
\r
183 <div id="method-Ext.Element-getFrameWidth"></div>/**
\r
184 * Returns the sum width of the padding and borders for the passed "sides". See getBorderWidth()
\r
185 for more information about the sides.
\r
186 * @param {String} sides
\r
189 getFrameWidth : function(sides, onlyContentBox){
\r
190 return onlyContentBox && this.isBorderBox() ? 0 : (this.getPadding(sides) + this.getBorderWidth(sides));
\r
193 <div id="method-Ext.Element-addClassOnOver"></div>/**
\r
194 * Sets up event handlers to add and remove a css class when the mouse is over this element
\r
195 * @param {String} className
\r
196 * @return {Ext.Element} this
\r
198 addClassOnOver : function(className){
\r
201 Ext.fly(this, INTERNAL).addClass(className);
\r
204 Ext.fly(this, INTERNAL).removeClass(className);
\r
210 <div id="method-Ext.Element-addClassOnFocus"></div>/**
\r
211 * Sets up event handlers to add and remove a css class when this element has the focus
\r
212 * @param {String} className
\r
213 * @return {Ext.Element} this
\r
215 addClassOnFocus : function(className){
\r
216 this.on("focus", function(){
\r
217 Ext.fly(this, INTERNAL).addClass(className);
\r
219 this.on("blur", function(){
\r
220 Ext.fly(this, INTERNAL).removeClass(className);
\r
225 <div id="method-Ext.Element-addClassOnClick"></div>/**
\r
226 * 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
227 * @param {String} className
\r
228 * @return {Ext.Element} this
\r
230 addClassOnClick : function(className){
\r
231 var dom = this.dom;
\r
232 this.on("mousedown", function(){
\r
233 Ext.fly(dom, INTERNAL).addClass(className);
\r
234 var d = Ext.getDoc(),
\r
236 Ext.fly(dom, INTERNAL).removeClass(className);
\r
237 d.removeListener("mouseup", fn);
\r
239 d.on("mouseup", fn);
\r
244 <div id="method-Ext.Element-getViewSize"></div>/**
\r
245 * <p>Returns the dimensions of the element available to lay content out in.<p>
\r
246 * <p>If the element (or any ancestor element) has CSS style <code>display : none</code>, the dimensions will be zero.</p>
\r
247 * example:<pre><code>
\r
248 var vpSize = Ext.getBody().getViewSize();
\r
250 // all Windows created afterwards will have a default value of 90% height and 95% width
\r
251 Ext.Window.override({
\r
252 width: vpSize.width * 0.9,
\r
253 height: vpSize.height * 0.95
\r
255 // To handle window resizing you would have to hook onto onWindowResize.
\r
257 * @param {Boolean} contentBox True to return the W3 content box <i>within</i> the padding area of the element. False
\r
258 * or omitted to return the full area of the element within the border. See <a href="http://www.w3.org/TR/CSS2/box.html">http://www.w3.org/TR/CSS2/box.html</a>
\r
259 * @return {Object} An object containing the elements's area: <code>{width: <element width>, height: <element height>}</code>
\r
261 getViewSize : function(contentBox){
\r
262 var doc = document,
\r
265 extdom = Ext.lib.Dom,
\r
266 isDoc = (d == doc || d == doc.body),
\r
267 isBB, w, h, tbBorder = 0, lrBorder = 0,
\r
268 tbPadding = 0, lrPadding = 0;
\r
270 return { width: extdom.getViewWidth(), height: extdom.getViewHeight() };
\r
272 isBB = me.isBorderBox();
\r
273 tbBorder = me.getBorderWidth('tb');
\r
274 lrBorder = me.getBorderWidth('lr');
\r
275 tbPadding = me.getPadding('tb');
\r
276 lrPadding = me.getPadding('lr');
\r
279 // Try the style first, then clientWidth, then offsetWidth
\r
280 if (w = me.getStyle('width').match(pxMatch)){
\r
281 if ((w = parseInt(w[1], 10)) && isBB){
\r
282 // Style includes the padding and border if isBB
\r
283 w -= (lrBorder + lrPadding);
\r
289 if (!(w = d.clientWidth) && (w = d.offsetWidth)){
\r
292 if (w && contentBox){
\r
298 // Try the style first, then clientHeight, then offsetHeight
\r
299 if (h = me.getStyle('height').match(pxMatch)){
\r
300 if ((h = parseInt(h[1], 10)) && isBB){
\r
301 // Style includes the padding and border if isBB
\r
302 h -= (tbBorder + tbPadding);
\r
308 if (!(h = d.clientHeight) && (h = d.offsetHeight)){
\r
311 if (h && contentBox){
\r
322 <div id="method-Ext.Element-getSize"></div>/**
\r
323 * Returns the size of the element.
\r
324 * @param {Boolean} contentSize (optional) true to get the width/size minus borders and padding
\r
325 * @return {Object} An object containing the element's size {width: (element width), height: (element height)}
\r
327 getSize : function(contentSize){
\r
328 return {width: this.getWidth(contentSize), height: this.getHeight(contentSize)};
\r
331 <div id="method-Ext.Element-repaint"></div>/**
\r
332 * Forces the browser to repaint this element
\r
333 * @return {Ext.Element} this
\r
335 repaint : function(){
\r
336 var dom = this.dom;
\r
337 this.addClass("x-repaint");
\r
338 setTimeout(function(){
\r
339 Ext.fly(dom).removeClass("x-repaint");
\r
344 <div id="method-Ext.Element-unselectable"></div>/**
\r
345 * Disables text selection for this element (normalized across browsers)
\r
346 * @return {Ext.Element} this
\r
348 unselectable : function(){
\r
349 this.dom.unselectable = "on";
\r
350 return this.swallowEvent("selectstart", true).
\r
351 applyStyles("-moz-user-select:none;-khtml-user-select:none;").
\r
352 addClass("x-unselectable");
\r
355 <div id="method-Ext.Element-getMargins"></div>/**
\r
356 * Returns an object with properties top, left, right and bottom representing the margins of this element unless sides is passed,
\r
357 * then it returns the calculated width of the sides (see getPadding)
\r
358 * @param {String} sides (optional) Any combination of l, r, t, b to get the sum of those sides
\r
359 * @return {Object/Number}
\r
361 getMargins : function(side){
\r
364 hash = {t:"top", l:"left", r:"right", b: "bottom"},
\r
368 for (key in me.margins){
\r
369 o[hash[key]] = parseInt(me.getStyle(me.margins[key]), 10) || 0;
\r
373 return me.addStyles.call(me, side, me.margins);
\r