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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
|
//>>built
define("dojox/embed/Flash", ["dojo"], function(dojo) {
/*******************************************************
dojox.embed.Flash
Base functionality to insert a flash movie into
a document on the fly.
Usage:
var movie=new dojox.embed.Flash({ args }, containerNode);
******************************************************/
dojo.getObject("embed", true, dojox);
var fMarkup, fVersion;
var minimumVersion = 9; // anything below this will throw an error (may overwrite)
var keyBase = "dojox-embed-flash-", keyCount=0;
var _baseKwArgs = {
expressInstall: false,
width: 320,
height: 240,
swLiveConnect: "true",
allowScriptAccess: "sameDomain",
allowNetworking:"all",
style: null,
redirect: null
};
function prep(kwArgs){
kwArgs = dojo.delegate(_baseKwArgs, kwArgs);
if(!("path" in kwArgs)){
console.error("dojox.embed.Flash(ctor):: no path reference to a Flash movie was provided.");
return null;
}
if(!("id" in kwArgs)){
kwArgs.id = (keyBase + keyCount++);
}
return kwArgs;
}
if(dojo.isIE){
fMarkup = function(kwArgs){
kwArgs = prep(kwArgs);
if(!kwArgs){ return null; }
var p;
var path = kwArgs.path;
if(kwArgs.vars){
var a = [];
for(p in kwArgs.vars){
a.push(p + '=' + kwArgs.vars[p]);
}
kwArgs.params.FlashVars = a.join("&");
delete kwArgs.vars;
}
var s = '<object id="' + kwArgs.id + '" '
+ 'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '
+ 'width="' + kwArgs.width + '" '
+ 'height="' + kwArgs.height + '"'
+ ((kwArgs.style)?' style="' + kwArgs.style + '"':'')
+ '>'
+ '<param name="movie" value="' + path + '" />';
if(kwArgs.params){
for(p in kwArgs.params){
s += '<param name="' + p + '" value="' + kwArgs.params[p] + '" />';
}
}
s += '</object>';
return { id: kwArgs.id, markup: s };
};
fVersion = (function(){
var testVersion = 10, testObj = null;
while(!testObj && testVersion > 7){
try {
testObj = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + testVersion--);
}catch(e){ }
}
if(testObj){
var v = testObj.GetVariable("$version").split(" ")[1].split(",");
return {
major: (v[0]!=null) ? parseInt(v[0]) : 0,
minor: (v[1]!=null) ? parseInt(v[1]) : 0,
rev: (v[2]!=null) ? parseInt(v[2]) : 0
};
}
return { major: 0, minor: 0, rev: 0 };
})();
// attach some cleanup for IE, thanks to deconcept :)
dojo.addOnUnload(function(){
var dummy = function(){};
var objs = dojo.query("object").
reverse().
style("display", "none").
forEach(function(i){
for(var p in i){
if((p != "FlashVars") && dojo.isFunction(i[p])){
try{
i[p] = dummy;
}catch(e){}
}
}
});
});
} else {
// *** Sane browsers branch ******************************************************************
fMarkup = function(kwArgs){
kwArgs = prep(kwArgs);
if(!kwArgs){ return null; }
var p;
var path = kwArgs.path;
if(kwArgs.vars){
var a = [];
for(p in kwArgs.vars){
a.push(p + '=' + kwArgs.vars[p]);
}
kwArgs.params.flashVars = a.join("&");
delete kwArgs.vars;
}
var s = '<embed type="application/x-shockwave-flash" '
+ 'src="' + path + '" '
+ 'id="' + kwArgs.id + '" '
+ 'width="' + kwArgs.width + '" '
+ 'height="' + kwArgs.height + '"'
+ ((kwArgs.style)?' style="' + kwArgs.style + '" ':'')
+ 'pluginspage="' + window.location.protocol + '//www.adobe.com/go/getflashplayer" ';
if(kwArgs.params){
for(p in kwArgs.params){
s += ' ' + p + '="' + kwArgs.params[p] + '"';
}
}
s += ' />';
return { id: kwArgs.id, markup: s };
};
fVersion=(function(){
var plugin = navigator.plugins["Shockwave Flash"];
if(plugin && plugin.description){
var v = plugin.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split(".");
return {
major: (v[0]!=null) ? parseInt(v[0]) : 0,
minor: (v[1]!=null) ? parseInt(v[1]) : 0,
rev: (v[2]!=null) ? parseInt(v[2]) : 0
};
}
return { major: 0, minor: 0, rev: 0 };
})();
}
/*=====
dojox.embed.__flashArgs = function(path, id, width, height, style, params, vars, expressInstall, redirect){
// path: String
// The URL of the movie to embed.
// id: String?
// A unique key that will be used as the id of the created markup. If you don't
// provide this, a unique key will be generated.
// width: Number?
// The width of the embedded movie; the default value is 320px.
// height: Number?
// The height of the embedded movie; the default value is 240px
// minimumVersion: Number ?
// The minimum targeted version of the Flash Player (defaults to 9)
// style: String?
// Any CSS style information (i.e. style="background-color:transparent") you want
// to define on the markup.
// params: Object?
// A set of key/value pairs that you want to define in the resultant markup.
// vars: Object?
// A set of key/value pairs that the Flash movie will interpret as FlashVars.
// expressInstall: Boolean?
// Whether or not to include any kind of expressInstall info. Default is false.
// redirect: String?
// A url to redirect the browser to if the current Flash version is not supported.
this.id=id;
this.path=path;
this.width=width;
this.minimumVersion=minimumVersion;
this.height=height;
this.style=style;
this.params=params;
this.vars=vars;
this.expressInstall=expressInstall;
this.redirect=redirect;
}
=====*/
// the main entry point
dojox.embed.Flash = function(/*dojox.embed.__flashArgs*/ kwArgs, /*DOMNode*/ node){
// summary:
// Create a wrapper object around a Flash movie; this is the DojoX equivilent
// to SWFObject.
//
// description:
// Creates a wrapper object around a Flash movie. Wrapper object will
// insert the movie reference in node; when the browser first starts
// grabbing the movie, onReady will be fired; when the movie has finished
// loading, it will fire onLoad.
//
// If your movie uses ExternalInterface, you should use the onLoad event
// to do any kind of proxy setup (see dojox.embed.Flash.proxy); this seems
// to be the only consistent time calling EI methods are stable (since the
// Flash movie will shoot several methods into the window object before
// EI callbacks can be used properly).
//
// kwArgs: dojox.embed.__flashArgs
// The various arguments that will be used to help define the Flash movie.
// node: DomNode
// The node where the embed object will be placed
//
// example:
// Embed a flash movie in a document using the new operator, and get a reference to it.
// | var movie = new dojox.embed.Flash({
// | path: "path/to/my/movie.swf",
// | width: 400,
// | height: 300
// | }, myWrapperNode, "testLoaded");
//
// example:
// Embed a flash movie in a document without using the new operator.
// | var movie = dojox.embed.Flash({
// | path: "path/to/my/movie.swf",
// | width: 400,
// | height: 300,
// | style: "position:absolute;top:0;left:0"
// | }, myWrapperNode, "testLoaded");
//
// File can only be run from a server, due to SWF dependency.
if(location.href.toLowerCase().indexOf("file://")>-1){
throw new Error("dojox.embed.Flash can't be run directly from a file. To instatiate the required SWF correctly it must be run from a server, like localHost.");
}
// available: Number
// If there is a flash player available, and if so what version.
this.available = dojox.embed.Flash.available;
// minimumVersion: Number
// The minimum version of Flash required to run this movie.
this.minimumVersion = kwArgs.minimumVersion || minimumVersion;
// id: String
// The id of the DOMNode to be used for this movie. Can be used with dojo.byId to get a reference.
this.id = null;
// movie: FlashObject
// A reference to the movie itself.
this.movie = null;
// domNode: DOMNode
// A reference to the DOMNode that contains this movie.
this.domNode = null;
if(node){
node = dojo.byId(node);
}
// setTimeout Fixes #8743 - creating double SWFs
// also allows time for code to attach to onError
setTimeout(dojo.hitch(this, function(){
if(kwArgs.expressInstall || this.available && this.available >= this.minimumVersion){
if(kwArgs && node){
this.init(kwArgs, node);
}else{
this.onError("embed.Flash was not provided with the proper arguments.");
}
}else{
if(!this.available){
this.onError("Flash is not installed.");
}else{
this.onError("Flash version detected: "+this.available+" is out of date. Minimum required: "+this.minimumVersion);
}
}
}), 100);
};
dojo.extend(dojox.embed.Flash, {
onReady: function(/*HTMLObject*/ movie){
// summary:
// Stub function for you to attach to when the movie reference is first
// pushed into the document.
},
onLoad: function(/*HTMLObject*/ movie){
// summary:
// Stub function for you to attach to when the movie has finished downloading
// and is ready to be manipulated.
},
onError: function(msg){
},
_onload: function(){
// summary:
// Internal. Cleans up before calling onLoad.
clearInterval(this._poller);
delete this._poller;
delete this._pollCount;
delete this._pollMax;
this.onLoad(this.movie);
},
init: function(/*dojox.embed.__flashArgs*/ kwArgs, /*DOMNode?*/ node){
// summary
// Initialize (i.e. place and load) the movie based on kwArgs.
this.destroy(); // ensure we are clean first.
node = dojo.byId(node || this.domNode);
if(!node){ throw new Error("dojox.embed.Flash: no domNode reference has been passed."); }
// vars to help determine load status
var p = 0, testLoaded=false;
this._poller = null; this._pollCount = 0; this._pollMax = 15; this.pollTime = 100;
if(dojox.embed.Flash.initialized){
this.id = dojox.embed.Flash.place(kwArgs, node);
this.domNode = node;
setTimeout(dojo.hitch(this, function(){
this.movie = this.byId(this.id, kwArgs.doc);
this.onReady(this.movie);
this._poller = setInterval(dojo.hitch(this, function(){
// catch errors if not quite ready.
try{
p = this.movie.PercentLoaded();
}catch(e){
console.warn("this.movie.PercentLoaded() failed", e, this.movie);
}
if(p == 100){
// if percent = 100, movie is fully loaded and we're communicating
this._onload();
}else if(p==0 && this._pollCount++ > this._pollMax){
// after several attempts, we're not past zero.
clearInterval(this._poller);
throw new Error("Building SWF failed.");
}
}), this.pollTime);
}), 1);
}
},
_destroy: function(){
// summary
// Kill the movie and reset all the properties of this object.
try{
this.domNode.removeChild(this.movie);
}catch(e){}
this.id = this.movie = this.domNode = null;
},
destroy: function(){
// summary
// Public interface for destroying all the properties in this object.
// Will also clean all proxied methods.
if(!this.movie){ return; }
// remove any proxy functions
var test = dojo.delegate({
id: true,
movie: true,
domNode: true,
onReady: true,
onLoad: true
});
for(var p in this){
if(!test[p]){
delete this[p];
}
}
// poll the movie
if(this._poller){
// wait until onLoad to destroy
dojo.connect(this, "onLoad", this, "_destroy");
} else {
this._destroy();
}
},
byId: function (movieName, doc){
// summary:
// Gets Flash movie by id.
// description:
// Probably includes methods for outdated
// browsers, but this should catch all cases.
// arguments:
// movieName: String
// The name of the SWF
// doc: Object
// The document, if not current window
// (not fully supported)
// example:
// | var movie = dojox.embed.Flash.byId("myId");
//
doc = doc || document;
if(doc.embeds[movieName]){
return doc.embeds[movieName];
}
if(doc[movieName]){
return doc[movieName];
}
if(window[movieName]){
return window[movieName];
}
if(document[movieName]){
return document[movieName];
}
return null;
}
});
// expose information through the constructor function itself.
dojo.mixin(dojox.embed.Flash, {
// summary:
// A singleton object used internally to get information
// about the Flash player available in a browser, and
// as the factory for generating and placing markup in a
// document.
//
// minSupported: Number
// The minimum supported version of the Flash Player, defaults to 8.
// available: Number
// Used as both a detection (i.e. if(dojox.embed.Flash.available){ })
// and as a variable holding the major version of the player installed.
// supported: Boolean
// Whether or not the Flash Player installed is supported by dojox.embed.
// version: Object
// The version of the installed Flash Player; takes the form of
// { major, minor, rev }. To get the major version, you'd do this:
// var v=dojox.embed.Flash.version.major;
// initialized: Boolean
// Whether or not the Flash engine is available for use.
// onInitialize: Function
// A stub you can connect to if you are looking to fire code when the
// engine becomes available. A note: DO NOT use this event to
// place a movie in a document; it will usually fire before DOMContentLoaded
// is fired, and you will get an error. Use dojo.addOnLoad instead.
minSupported : 8,
available: fVersion.major,
supported: (fVersion.major >= fVersion.required),
minimumRequired: fVersion.required,
version: fVersion,
initialized: false,
onInitialize: function(){
dojox.embed.Flash.initialized = true;
},
__ie_markup__: function(kwArgs){
return fMarkup(kwArgs);
},
proxy: function(/*dojox.embed.Flash*/ obj, /*Array|String*/ methods){
// summary:
// Create the set of passed methods on the dojox.embed.Flash object
// so that you can call that object directly, as opposed to having to
// delve into the internal movie to do this. Intended to make working
// with Flash movies that use ExternalInterface much easier to use.
//
// example:
// Create "setMessage" and "getMessage" methods on foo.
// | var foo = new dojox.embed.Flash(args, someNode);
// | dojo.connect(foo, "onLoad", dojo.hitch(foo, function(){
// | dojox.embed.Flash.proxy(this, [ "setMessage", "getMessage" ]);
// | this.setMessage("dojox.embed.Flash.proxy is pretty cool...");
// | console.log(this.getMessage());
// | }));
dojo.forEach((dojo.isArray(methods) ? methods : [ methods ]), function(item){
this[item] = dojo.hitch(this, function(){
return (function(){
return eval(this.movie.CallFunction(
'<invoke name="' + item + '" returntype="javascript">'
+ '<arguments>'
+ dojo.map(arguments, function(item){
// FIXME:
// investigate if __flash__toXML will
// accept direct application via map()
// (e.g., does it ignore args past the
// first? or does it blow up?)
return __flash__toXML(item);
}).join("")
+ '</arguments>'
+ '</invoke>'
));
}).apply(this, arguments||[]);
});
}, obj);
}
});
dojox.embed.Flash.place = function(kwArgs, node){
var o = fMarkup(kwArgs);
node = dojo.byId(node);
if(!node){
node = dojo.doc.createElement("div");
node.id = o.id+"-container";
dojo.body().appendChild(node);
}
if(o){
node.innerHTML = o.markup;
return o.id;
}
return null;
}
dojox.embed.Flash.onInitialize();
return dojox.embed.Flash;
});
|