Upgrade to ExtJS 3.1.1 - Released 02/08/2010
[extjs.git] / src / core / Element.legacy.js
1 /*!
2  * Ext JS Library 3.1.1
3  * Copyright(c) 2006-2010 Ext JS, LLC
4  * licensing@extjs.com
5  * http://www.extjs.com/license
6  */
7 /**\r
8  * @class Ext.Element\r
9  */\r
10 Ext.Element.addMethods({\r
11     /**\r
12      * Measures the element's content height and updates height to match. Note: this function uses setTimeout so\r
13      * the new height may not be available immediately.\r
14      * @param {Boolean} animate (optional) Animate the transition (defaults to false)\r
15      * @param {Float} duration (optional) Length of the animation in seconds (defaults to .35)\r
16      * @param {Function} onComplete (optional) Function to call when animation completes\r
17      * @param {String} easing (optional) Easing method to use (defaults to easeOut)\r
18      * @return {Ext.Element} this\r
19      */\r
20     autoHeight : function(animate, duration, onComplete, easing){\r
21         var oldHeight = this.getHeight();\r
22         this.clip();\r
23         this.setHeight(1); // force clipping\r
24         setTimeout(function(){\r
25             var height = parseInt(this.dom.scrollHeight, 10); // parseInt for Safari\r
26             if(!animate){\r
27                 this.setHeight(height);\r
28                 this.unclip();\r
29                 if(typeof onComplete == "function"){\r
30                     onComplete();\r
31                 }\r
32             }else{\r
33                 this.setHeight(oldHeight); // restore original height\r
34                 this.setHeight(height, animate, duration, function(){\r
35                     this.unclip();\r
36                     if(typeof onComplete == "function") onComplete();\r
37                 }.createDelegate(this), easing);\r
38             }\r
39         }.createDelegate(this), 0);\r
40         return this;\r
41     }\r
42 });