3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js">/**
\r
11 <div id="prop-Ext.Element-VISIBILITY"></div>/**
\r
12 * Visibility mode constant for use with {@link #setVisibilityMode}. Use visibility to hide element
\r
16 Ext.Element.VISIBILITY = 1;
\r
17 <div id="prop-Ext.Element-DISPLAY"></div>/**
\r
18 * Visibility mode constant for use with {@link #setVisibilityMode}. Use display to hide element
\r
22 Ext.Element.DISPLAY = 2;
\r
24 Ext.Element.addMethods(function(){
\r
25 var VISIBILITY = "visibility",
\r
26 DISPLAY = "display",
\r
29 ORIGINALDISPLAY = 'originalDisplay',
\r
30 VISMODE = 'visibilityMode',
\r
31 ELDISPLAY = Ext.Element.DISPLAY,
\r
32 data = Ext.Element.data,
\r
33 getDisplay = function(dom){
\r
34 var d = data(dom, ORIGINALDISPLAY);
\r
35 if(d === undefined){
\r
36 data(dom, ORIGINALDISPLAY, d = '');
\r
40 getVisMode = function(dom){
\r
41 var m = data(dom, VISMODE);
\r
42 if(m === undefined){
\r
43 data(dom, VISMODE, m = 1)
\r
49 <div id="prop-Ext.Element-originalDisplay"></div>/**
\r
50 * The element's default display mode (defaults to "")
\r
53 originalDisplay : "",
\r
56 <div id="method-Ext.Element-setVisibilityMode"></div>/**
\r
57 * Sets the element's visibility mode. When setVisible() is called it
\r
58 * will use this to determine whether to set the visibility or the display property.
\r
59 * @param visMode Ext.Element.VISIBILITY or Ext.Element.DISPLAY
\r
60 * @return {Ext.Element} this
\r
62 setVisibilityMode : function(visMode){
\r
63 data(this.dom, VISMODE, visMode);
\r
67 <div id="method-Ext.Element-animate"></div>/**
\r
68 * Perform custom animation on this element.
\r
69 * <div><ul class="mdetail-params">
\r
70 * <li><u>Animation Properties</u></li>
\r
72 * <p>The Animation Control Object enables gradual transitions for any member of an
\r
73 * element's style object that takes a numeric value including but not limited to
\r
74 * these properties:</p><div><ul class="mdetail-params">
\r
75 * <li><tt>bottom, top, left, right</tt></li>
\r
76 * <li><tt>height, width</tt></li>
\r
77 * <li><tt>margin, padding</tt></li>
\r
78 * <li><tt>borderWidth</tt></li>
\r
79 * <li><tt>opacity</tt></li>
\r
80 * <li><tt>fontSize</tt></li>
\r
81 * <li><tt>lineHeight</tt></li>
\r
85 * <li><u>Animation Property Attributes</u></li>
\r
87 * <p>Each Animation Property is a config object with optional properties:</p>
\r
88 * <div><ul class="mdetail-params">
\r
89 * <li><tt>by</tt>* : relative change - start at current value, change by this value</li>
\r
90 * <li><tt>from</tt> : ignore current value, start from this value</li>
\r
91 * <li><tt>to</tt>* : start at current value, go to this value</li>
\r
92 * <li><tt>unit</tt> : any allowable unit specification</li>
\r
93 * <p>* do not specify both <tt>to</tt> and <tt>by</tt> for an animation property</p>
\r
96 * <li><u>Animation Types</u></li>
\r
98 * <p>The supported animation types:</p><div><ul class="mdetail-params">
\r
99 * <li><tt>'run'</tt> : Default
\r
101 var el = Ext.get('complexEl');
\r
103 // animation control object
\r
105 borderWidth: {to: 3, from: 0},
\r
106 opacity: {to: .3, from: 1},
\r
107 height: {to: 50, from: el.getHeight()},
\r
108 width: {to: 300, from: el.getWidth()},
\r
109 top : {by: - 100, unit: 'px'},
\r
111 0.35, // animation duration
\r
113 'easeOut', // easing method
\r
114 'run' // animation type ('run','color','motion','scroll')
\r
118 * <li><tt>'color'</tt>
\r
119 * <p>Animates transition of background, text, or border colors.</p>
\r
122 // animation control object
\r
124 color: { to: '#06e' },
\r
125 backgroundColor: { to: '#e06' }
\r
127 0.35, // animation duration
\r
129 'easeOut', // easing method
\r
130 'color' // animation type ('run','color','motion','scroll')
\r
135 * <li><tt>'motion'</tt>
\r
136 * <p>Animates the motion of an element to/from specific points using optional bezier
\r
137 * way points during transit.</p>
\r
140 // animation control object
\r
142 borderWidth: {to: 3, from: 0},
\r
143 opacity: {to: .3, from: 1},
\r
144 height: {to: 50, from: el.getHeight()},
\r
145 width: {to: 300, from: el.getWidth()},
\r
146 top : {by: - 100, unit: 'px'},
\r
148 to: [50, 100], // go to this point
\r
149 control: [ // optional bezier way points
\r
155 3000, // animation duration (milliseconds!)
\r
157 'easeOut', // easing method
\r
158 'motion' // animation type ('run','color','motion','scroll')
\r
162 * <li><tt>'scroll'</tt>
\r
163 * <p>Animate horizontal or vertical scrolling of an overflowing page element.</p>
\r
166 // animation control object
\r
168 scroll: {to: [400, 300]}
\r
170 0.35, // animation duration
\r
172 'easeOut', // easing method
\r
173 'scroll' // animation type ('run','color','motion','scroll')
\r
181 * @param {Object} args The animation control args
\r
182 * @param {Float} duration (optional) How long the animation lasts in seconds (defaults to <tt>.35</tt>)
\r
183 * @param {Function} onComplete (optional) Function to call when animation completes
\r
184 * @param {String} easing (optional) {@link Ext.Fx#easing} method to use (defaults to <tt>'easeOut'</tt>)
\r
185 * @param {String} animType (optional) <tt>'run'</tt> is the default. Can also be <tt>'color'</tt>,
\r
186 * <tt>'motion'</tt>, or <tt>'scroll'</tt>
\r
187 * @return {Ext.Element} this
\r
189 animate : function(args, duration, onComplete, easing, animType){
\r
190 this.anim(args, {duration: duration, callback: onComplete, easing: easing}, animType);
\r
195 * @private Internal animation call
\r
197 anim : function(args, opt, animType, defaultDur, defaultEase, cb){
\r
198 animType = animType || 'run';
\r
201 anim = Ext.lib.Anim[animType](
\r
204 (opt.duration || defaultDur) || .35,
\r
205 (opt.easing || defaultEase) || 'easeOut',
\r
207 if(cb) cb.call(me);
\r
208 if(opt.callback) opt.callback.call(opt.scope || me, me, opt);
\r
216 // private legacy anim prep
\r
217 preanim : function(a, i){
\r
218 return !a[i] ? false : (Ext.isObject(a[i]) ? a[i]: {duration: a[i+1], callback: a[i+2], easing: a[i+3]});
\r
221 <div id="method-Ext.Element-isVisible"></div>/**
\r
222 * Checks whether the element is currently visible using both visibility and display properties.
\r
223 * @return {Boolean} True if the element is currently visible, else false
\r
225 isVisible : function() {
\r
226 return !this.isStyle(VISIBILITY, HIDDEN) && !this.isStyle(DISPLAY, NONE);
\r
229 <div id="method-Ext.Element-setVisible"></div>/**
\r
230 * Sets the visibility of the element (see details). If the visibilityMode is set to Element.DISPLAY, it will use
\r
231 * the display property to hide the element, otherwise it uses visibility. The default is to hide and show using the visibility property.
\r
232 * @param {Boolean} visible Whether the element is visible
\r
233 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
\r
234 * @return {Ext.Element} this
\r
236 setVisible : function(visible, animate){
\r
239 isDisplay = getVisMode(this.dom) == ELDISPLAY;
\r
241 if (!animate || !me.anim) {
\r
243 me.setDisplayed(visible);
\r
246 dom.style.visibility = visible ? "visible" : HIDDEN;
\r
249 // closure for composites
\r
251 me.setOpacity(.01);
\r
252 me.setVisible(true);
\r
254 me.anim({opacity: { to: (visible?1:0) }},
\r
255 me.preanim(arguments, 1),
\r
261 dom.style[isDisplay ? DISPLAY : VISIBILITY] = (isDisplay) ? NONE : HIDDEN;
\r
262 Ext.fly(dom).setOpacity(1);
\r
269 <div id="method-Ext.Element-toggle"></div>/**
\r
270 * Toggles the element's visibility or display, depending on visibility mode.
\r
271 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
\r
272 * @return {Ext.Element} this
\r
274 toggle : function(animate){
\r
276 me.setVisible(!me.isVisible(), me.preanim(arguments, 0));
\r
280 <div id="method-Ext.Element-setDisplayed"></div>/**
\r
281 * Sets the CSS display property. Uses originalDisplay if the specified value is a boolean true.
\r
282 * @param {Mixed} value Boolean value to display the element using its default display, or a string to set the display directly.
\r
283 * @return {Ext.Element} this
\r
285 setDisplayed : function(value) {
\r
286 if(typeof value == "boolean"){
\r
287 value = value ? getDisplay(this.dom) : NONE;
\r
289 this.setStyle(DISPLAY, value);
\r
294 fixDisplay : function(){
\r
296 if(me.isStyle(DISPLAY, NONE)){
\r
297 me.setStyle(VISIBILITY, HIDDEN);
\r
298 me.setStyle(DISPLAY, getDisplay(this.dom)); // first try reverting to default
\r
299 if(me.isStyle(DISPLAY, NONE)){ // if that fails, default to block
\r
300 me.setStyle(DISPLAY, "block");
\r
305 <div id="method-Ext.Element-hide"></div>/**
\r
306 * Hide this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
\r
307 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
\r
308 * @return {Ext.Element} this
\r
310 hide : function(animate){
\r
311 this.setVisible(false, this.preanim(arguments, 0));
\r
315 <div id="method-Ext.Element-show"></div>/**
\r
316 * Show this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
\r
317 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
\r
318 * @return {Ext.Element} this
\r
320 show : function(animate){
\r
321 this.setVisible(true, this.preanim(arguments, 0));
\r