]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | /**\r |
2 | * @class Ext.fx.target.Component\r | |
3 | * \r | |
4 | * This class represents a animation target for a {@link Ext.Component}. In general this class will not be\r | |
5 | * created directly, the {@link Ext.Component} will be passed to the animation and\r | |
6 | * and the appropriate target will be created.\r | |
7 | */\r | |
8 | Ext.define('Ext.fx.target.Component', {\r | |
9 | \r | |
10 | /* Begin Definitions */\r | |
11 | \r | |
12 | extend: 'Ext.fx.target.Target',\r | |
13 | \r | |
14 | /* End Definitions */\r | |
15 | \r | |
16 | type: 'component',\r | |
17 | \r | |
18 | // Methods to call to retrieve unspecified "from" values from a target Component\r | |
19 | getPropMethod: {\r | |
20 | top: function() {\r | |
21 | return this.getPosition(true)[1];\r | |
22 | },\r | |
23 | left: function() {\r | |
24 | return this.getPosition(true)[0];\r | |
25 | },\r | |
26 | x: function() {\r | |
27 | return this.getPosition()[0];\r | |
28 | },\r | |
29 | y: function() {\r | |
30 | return this.getPosition()[1];\r | |
31 | },\r | |
32 | height: function() {\r | |
33 | return this.getHeight();\r | |
34 | },\r | |
35 | width: function() {\r | |
36 | return this.getWidth();\r | |
37 | },\r | |
38 | opacity: function() {\r | |
39 | return this.el.getStyle('opacity');\r | |
40 | }\r | |
41 | },\r | |
42 | \r | |
43 | setMethods: {\r | |
44 | top: 'setPosition',\r | |
45 | left: 'setPosition',\r | |
46 | x: 'setPagePosition',\r | |
47 | y: 'setPagePosition',\r | |
48 | height: 'setSize',\r | |
49 | width: 'setSize',\r | |
50 | opacity: 'setOpacity'\r | |
51 | },\r | |
52 | \r | |
53 | // Read the named attribute from the target Component. Use the defined getter for the attribute\r | |
54 | getAttr: function(attr, val) {\r | |
55 | return [[this.target, val !== undefined ? val : this.getPropMethod[attr].call(this.target)]];\r | |
56 | },\r | |
57 | \r | |
58 | setAttr: function(targetData, isFirstFrame, isLastFrame) {\r | |
59 | var me = this,\r | |
60 | ln = targetData.length,\r | |
61 | attrs, attr, o, i, j, targets, left, top, w, h,\r | |
62 | methodsToCall = {},\r | |
63 | methodProps;\r | |
64 | \r | |
65 | for (i = 0; i < ln; i++) {\r | |
66 | attrs = targetData[i].attrs;\r | |
67 | for (attr in attrs) {\r | |
68 | targets = attrs[attr].length;\r | |
69 | for (j = 0; j < targets; j++) {\r | |
70 | o = attrs[attr][j];\r | |
71 | methodProps = methodsToCall[me.setMethods[attr]] || (methodsToCall[me.setMethods[attr]] = {});\r | |
72 | methodProps.target = o[0];\r | |
73 | methodProps[attr] = o[1];\r | |
74 | // debugging code: Ext.log('Setting ' + o[0].id + "'s " + attr + ' to ' + o[1]);\r | |
75 | }\r | |
76 | }\r | |
77 | if (methodsToCall.setPosition) {\r | |
78 | o = methodsToCall.setPosition;\r | |
79 | left = (o.left === undefined) ? undefined : parseFloat(o.left);\r | |
80 | top = (o.top === undefined) ? undefined : parseFloat(o.top);\r | |
81 | o.target.setPosition(left, top);\r | |
82 | }\r | |
83 | if (methodsToCall.setPagePosition) {\r | |
84 | o = methodsToCall.setPagePosition;\r | |
85 | o.target.setPagePosition(o.x, o.y);\r | |
86 | }\r | |
87 | if (methodsToCall.setSize) {\r | |
88 | o = methodsToCall.setSize;\r | |
89 | // Dimensions not being animated MUST NOT be autosized. They must remain at current value.\r | |
90 | w = (o.width === undefined) ? o.target.getWidth() : parseFloat(o.width);\r | |
91 | h = (o.height === undefined) ? o.target.getHeight() : parseFloat(o.height);\r | |
92 | \r | |
93 | // Only set the size of the Component on the last frame, or if the animation was\r | |
94 | // configured with dynamic: true.\r | |
95 | // In other cases, we just set the target element size.\r | |
96 | // This will result in either clipping if animating a reduction in size, or the revealing of\r | |
97 | // the inner elements of the Component if animating an increase in size.\r | |
98 | // Component's animate function initially resizes to the larger size before resizing the\r | |
99 | // outer element to clip the contents.\r | |
100 | o.target.el.setSize(w, h);\r | |
101 | if (isLastFrame || me.dynamic) {\r | |
102 | // Defer the final sizing & layout until we are outside of this frame.\r | |
103 | // In case anything in the resulting layout calls animation.\r | |
104 | // If it does, *this* frame will fire again... recursively\r | |
105 | Ext.GlobalEvents.on({\r | |
106 | idle: Ext.Function.bind(o.target.setSize, o.target, [w, h]),\r | |
107 | single: true\r | |
108 | });\r | |
109 | }\r | |
110 | }\r | |
111 | if (methodsToCall.setOpacity) {\r | |
112 | o = methodsToCall.setOpacity;\r | |
113 | o.target.el.setStyle('opacity', o.opacity);\r | |
114 | }\r | |
115 | }\r | |
116 | }\r | |
117 | });\r |