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