Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / src / fx / target / Element.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 /**
16  * @class Ext.fx.target.Element
17  * @extends Ext.fx.target.Target
18  * 
19  * This class represents a animation target for an {@link Ext.Element}. In general this class will not be
20  * created directly, the {@link Ext.Element} will be passed to the animation and
21  * and the appropriate target will be created.
22  */
23 Ext.define('Ext.fx.target.Element', {
24
25     /* Begin Definitions */
26     
27     extend: 'Ext.fx.target.Target',
28     
29     /* End Definitions */
30
31     type: 'element',
32
33     getElVal: function(el, attr, val) {
34         if (val == undefined) {
35             if (attr === 'x') {
36                 val = el.getX();
37             }
38             else if (attr === 'y') {
39                 val = el.getY();
40             }
41             else if (attr === 'scrollTop') {
42                 val = el.getScroll().top;
43             }
44             else if (attr === 'scrollLeft') {
45                 val = el.getScroll().left;
46             }
47             else if (attr === 'height') {
48                 val = el.getHeight();
49             }
50             else if (attr === 'width') {
51                 val = el.getWidth();
52             }
53             else {
54                 val = el.getStyle(attr);
55             }
56         }
57         return val;
58     },
59
60     getAttr: function(attr, val) {
61         var el = this.target;
62         return [[ el, this.getElVal(el, attr, val)]];
63     },
64
65     setAttr: function(targetData) {
66         var target = this.target,
67             ln = targetData.length,
68             attrs, attr, o, i, j, ln2, element, value;
69         for (i = 0; i < ln; i++) {
70             attrs = targetData[i].attrs;
71             for (attr in attrs) {
72                 if (attrs.hasOwnProperty(attr)) {
73                     ln2 = attrs[attr].length;
74                     for (j = 0; j < ln2; j++) {
75                         o = attrs[attr][j];
76                         element = o[0];
77                         value = o[1];
78                         if (attr === 'x') {
79                             element.setX(value);
80                         }
81                         else if (attr === 'y') {
82                             element.setY(value);
83                         }
84                         else if (attr === 'scrollTop') {
85                             element.scrollTo('top', value);
86                         }
87                         else if (attr === 'scrollLeft') {
88                             element.scrollTo('left',value);
89                         }
90                         else {
91                             element.setStyle(attr, value);
92                         }
93                     }
94                 }
95             }
96         }
97     }
98 });
99