]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | /**\r |
2 | * A simple Component for displaying an Adobe Flash SWF movie. The movie will be sized and can participate\r | |
3 | * in layout like any other Component.\r | |
4 | *\r | |
5 | * This component requires the third-party SWFObject library version 2.2 or above. It is not included within\r | |
6 | * the ExtJS distribution, so you will have to include it into your page manually in order to use this component.\r | |
7 | * The SWFObject library can be downloaded from the [SWFObject project page](http://code.google.com/p/swfobject)\r | |
8 | * and then simply import it into the head of your HTML document:\r | |
9 | *\r | |
10 | * <script type="text/javascript" src="path/to/local/swfobject.js"></script>\r | |
11 | *\r | |
12 | * ## Configuration\r | |
13 | *\r | |
14 | * This component allows several options for configuring how the target Flash movie is embedded. The most\r | |
15 | * important is the required {@link #url} which points to the location of the Flash movie to load. Other\r | |
16 | * configurations include:\r | |
17 | *\r | |
18 | * - {@link #backgroundColor}\r | |
19 | * - {@link #wmode}\r | |
20 | * - {@link #flashVars}\r | |
21 | * - {@link #flashParams}\r | |
22 | * - {@link #flashAttributes}\r | |
23 | *\r | |
24 | * ## Example usage:\r | |
25 | *\r | |
26 | * var win = Ext.widget('window', {\r | |
27 | * title: "It's a tiger!",\r | |
28 | * layout: 'fit',\r | |
29 | * width: 300,\r | |
30 | * height: 300,\r | |
31 | * x: 20,\r | |
32 | * y: 20,\r | |
33 | * resizable: true,\r | |
34 | * items: {\r | |
35 | * xtype: 'flash',\r | |
36 | * url: 'tiger.swf'\r | |
37 | * }\r | |
38 | * });\r | |
39 | * win.show();\r | |
40 | *\r | |
41 | * ## Express Install\r | |
42 | *\r | |
43 | * Adobe provides a tool called [Express Install](http://www.adobe.com/devnet/flashplayer/articles/express_install.html)\r | |
44 | * that offers users an easy way to upgrade their Flash player. If you wish to make use of this, you should set\r | |
45 | * the static EXPRESS\_INSTALL\_URL property to the location of your Express Install SWF file:\r | |
46 | *\r | |
47 | * Ext.flash.Component.EXPRESS_INSTALL_URL = 'path/to/local/expressInstall.swf';\r | |
48 | */\r | |
49 | Ext.define('Ext.flash.Component', {\r | |
50 | extend: 'Ext.Component',\r | |
51 | alternateClassName: 'Ext.FlashComponent',\r | |
52 | alias: 'widget.flash',\r | |
53 | \r | |
54 | /**\r | |
55 | * @cfg {String} [flashVersion="9.0.115"]\r | |
56 | * Indicates the version the flash content was published for.\r | |
57 | */\r | |
58 | flashVersion : '9.0.115',\r | |
59 | \r | |
60 | /**\r | |
61 | * @cfg {String} [backgroundColor="#ffffff"]\r | |
62 | * The background color of the SWF movie.\r | |
63 | */\r | |
64 | backgroundColor: '#ffffff',\r | |
65 | \r | |
66 | /**\r | |
67 | * @cfg {String} [wmode="opaque"]\r | |
68 | * The wmode of the flash object. This can be used to control layering.\r | |
69 | * Set to 'transparent' to ignore the {@link #backgroundColor} and make the background of the Flash\r | |
70 | * movie transparent.\r | |
71 | */\r | |
72 | wmode: 'opaque',\r | |
73 | \r | |
74 | /**\r | |
75 | * @cfg {Object} flashVars\r | |
76 | * A set of key value pairs to be passed to the flash object as flash variables.\r | |
77 | */\r | |
78 | \r | |
79 | /**\r | |
80 | * @cfg {Object} flashParams\r | |
81 | * A set of key value pairs to be passed to the flash object as parameters. Possible parameters can be found here:\r | |
82 | * http://kb2.adobe.com/cps/127/tn_12701.html\r | |
83 | */\r | |
84 | \r | |
85 | /**\r | |
86 | * @cfg {Object} flashAttributes\r | |
87 | * A set of key value pairs to be passed to the flash object as attributes.\r | |
88 | */\r | |
89 | \r | |
90 | /**\r | |
91 | * @cfg {String} url (required)\r | |
92 | * The URL of the SWF file to include.\r | |
93 | */\r | |
94 | \r | |
95 | /**\r | |
96 | * @cfg {String/Number} [swfWidth="100%"]\r | |
97 | * The width of the embedded SWF movie inside the component.\r | |
98 | *\r | |
99 | * Defaults to "100%" so that the movie matches the width of the component.\r | |
100 | */\r | |
101 | swfWidth: '100%',\r | |
102 | \r | |
103 | /**\r | |
104 | * @cfg {String/Number} [swfHeight="100%"]\r | |
105 | * The height of the embedded SWF movie inside the component.\r | |
106 | *\r | |
107 | * Defaults to "100%" so that the movie matches the height of the component.\r | |
108 | */\r | |
109 | swfHeight: '100%',\r | |
110 | \r | |
111 | /**\r | |
112 | * @cfg {Boolean} [expressInstall=false]\r | |
113 | * True to prompt the user to install flash if not installed. Note that this uses\r | |
114 | * Ext.FlashComponent.EXPRESS_INSTALL_URL, which should be set to the local resource.\r | |
115 | */\r | |
116 | expressInstall: false,\r | |
117 | \r | |
118 | /**\r | |
119 | * @property {Ext.dom.Element} swf\r | |
120 | * A reference to the object or embed element into which the SWF file is loaded. Only\r | |
121 | * populated after the component is rendered and the SWF has been successfully embedded.\r | |
122 | */\r | |
123 | \r | |
124 | // Have to create a placeholder div with the swfId, which SWFObject will replace with the object/embed element.\r | |
125 | renderTpl: ['<div id="{swfId}" role="application"></div>'],\r | |
126 | \r | |
127 | /**\r | |
128 | * @event success\r | |
129 | * Fired when the Flash movie has been successfully embedded\r | |
130 | * @param {Ext.flash.Component} this\r | |
131 | */\r | |
132 | \r | |
133 | /**\r | |
134 | * @event failure\r | |
135 | * Fired when the Flash movie embedding fails\r | |
136 | * @param {Ext.flash.Component} this\r | |
137 | */\r | |
138 | \r | |
139 | initComponent: function() {\r | |
140 | // <debug>\r | |
141 | if (!('swfobject' in window)) {\r | |
142 | Ext.raise('The SWFObject library is not loaded. Ext.flash.Component requires SWFObject version 2.2 or later: http://code.google.com/p/swfobject/');\r | |
143 | }\r | |
144 | if (!this.url) {\r | |
145 | Ext.raise('The "url" config is required for Ext.flash.Component');\r | |
146 | }\r | |
147 | // </debug>\r | |
148 | \r | |
149 | this.callParent();\r | |
150 | },\r | |
151 | \r | |
152 | beforeRender: function(){\r | |
153 | this.callParent();\r | |
154 | \r | |
155 | Ext.applyIf(this.renderData, {\r | |
156 | swfId: this.getSwfId()\r | |
157 | });\r | |
158 | },\r | |
159 | \r | |
160 | afterRender: function() {\r | |
161 | var me = this,\r | |
162 | flashParams = Ext.apply({}, me.flashParams), \r | |
163 | flashVars = Ext.apply({}, me.flashVars);\r | |
164 | \r | |
165 | me.callParent();\r | |
166 | \r | |
167 | flashParams = Ext.apply({\r | |
168 | allowScriptAccess: 'always',\r | |
169 | bgcolor: me.backgroundColor,\r | |
170 | wmode: me.wmode\r | |
171 | }, flashParams);\r | |
172 | \r | |
173 | flashVars = Ext.apply({\r | |
174 | allowedDomain: document.location.hostname\r | |
175 | }, flashVars);\r | |
176 | \r | |
177 | new swfobject.embedSWF( // jshint ignore:line\r | |
178 | me.url,\r | |
179 | me.getSwfId(),\r | |
180 | me.swfWidth,\r | |
181 | me.swfHeight,\r | |
182 | me.flashVersion,\r | |
183 | me.expressInstall ? me.statics.EXPRESS_INSTALL_URL : undefined,\r | |
184 | flashVars,\r | |
185 | flashParams,\r | |
186 | me.flashAttributes,\r | |
187 | me.swfCallback.bind(me)\r | |
188 | );\r | |
189 | },\r | |
190 | \r | |
191 | /**\r | |
192 | * @private\r | |
193 | * The callback method for handling an embedding success or failure by SWFObject\r | |
194 | * @param {Object} e The event object passed by SWFObject - see http://code.google.com/p/swfobject/wiki/api\r | |
195 | */\r | |
196 | swfCallback: function(e) {\r | |
197 | var me = this;\r | |
198 | if (e.success) {\r | |
199 | me.swf = Ext.get(e.ref);\r | |
200 | me.onSuccess();\r | |
201 | me.fireEvent('success', me);\r | |
202 | } else {\r | |
203 | me.onFailure();\r | |
204 | me.fireEvent('failure', me);\r | |
205 | }\r | |
206 | },\r | |
207 | \r | |
208 | /**\r | |
209 | * Retrieves the id of the SWF object/embed element.\r | |
210 | */\r | |
211 | getSwfId: function() {\r | |
212 | return this.swfId || (this.swfId = "extswf" + this.getAutoId());\r | |
213 | },\r | |
214 | \r | |
215 | onSuccess: function() {\r | |
216 | // swfobject forces visiblity:visible on the swf element, which prevents it \r | |
217 | // from getting hidden when an ancestor is given visibility:hidden.\r | |
218 | this.swf.setStyle('visibility', 'inherit');\r | |
219 | },\r | |
220 | \r | |
221 | onFailure: Ext.emptyFn,\r | |
222 | \r | |
223 | beforeDestroy: function() {\r | |
224 | var me = this,\r | |
225 | swf = me.swf;\r | |
226 | if (swf) {\r | |
227 | swfobject.removeSWF(me.getSwfId()); // jshint ignore:line\r | |
228 | Ext.destroy(swf);\r | |
229 | delete me.swf;\r | |
230 | }\r | |
231 | me.callParent();\r | |
232 | },\r | |
233 | \r | |
234 | statics: {\r | |
235 | /**\r | |
236 | * @property {String}\r | |
237 | * The url for installing flash if it doesn't exist. This should be set to a local resource.\r | |
238 | * See [http://get.adobe.com/flashplayer/](http://get.adobe.com/flashplayer/) for details.\r | |
239 | * @static\r | |
240 | */\r | |
241 | EXPRESS_INSTALL_URL: 'http:/' + '/swfobject.googlecode.com/svn/trunk/swfobject/expressInstall.swf'\r | |
242 | }\r | |
243 | });\r |