1 | dojo.provide("dojox.flash._base"); |
---|
2 | dojo.experimental("dojox.flash"); |
---|
3 | |
---|
4 | // for dojo.window.getBox(), needed by dojox.flash.Embed.center() |
---|
5 | dojo.require("dojo.window"); |
---|
6 | |
---|
7 | dojox.flash = function(){ |
---|
8 | // summary: |
---|
9 | // Utilities to embed and communicate with the Flash player from Javascript |
---|
10 | // |
---|
11 | // description: |
---|
12 | // The goal of dojox.flash is to make it easy to extend Flash's capabilities |
---|
13 | // into an Ajax/DHTML environment. |
---|
14 | // |
---|
15 | // dojox.flash provides an easy object for interacting with the Flash plugin. |
---|
16 | // This object provides methods to determine the current version of the Flash |
---|
17 | // plugin (dojox.flash.info); write out the necessary markup to |
---|
18 | // dynamically insert a Flash object into the page (dojox.flash.Embed; and |
---|
19 | // do dynamic installation and upgrading of the current Flash plugin in |
---|
20 | // use (dojox.flash.Install). If you want to call methods on the Flash object |
---|
21 | // embedded into the page it is your responsibility to use Flash's ExternalInterface |
---|
22 | // API and get a reference to the Flash object yourself. |
---|
23 | // |
---|
24 | // To use dojox.flash, you must first wait until Flash is finished loading |
---|
25 | // and initializing before you attempt communication or interaction. |
---|
26 | // To know when Flash is finished use dojo.connect: |
---|
27 | // |
---|
28 | //| dojo.connect(dojox.flash, "loaded", myInstance, "myCallback"); |
---|
29 | // |
---|
30 | // Then, while the page is still loading provide the file name: |
---|
31 | // |
---|
32 | //| dojox.flash.setSwf(dojo.moduleUrl("dojox", "_storage/storage.swf")); |
---|
33 | // |
---|
34 | // If no SWF files are specified, then Flash is not initialized. |
---|
35 | // |
---|
36 | // Your Flash must use Flash's ExternalInterface to expose Flash methods and |
---|
37 | // to call JavaScript. |
---|
38 | // |
---|
39 | // setSwf can take an optional 'visible' attribute to control whether |
---|
40 | // the Flash object is visible or not on the page; the default is visible: |
---|
41 | // |
---|
42 | //| dojox.flash.setSwf(dojo.moduleUrl("dojox", "_storage/storage.swf"), |
---|
43 | // false); |
---|
44 | // |
---|
45 | // Once finished, you can query Flash version information: |
---|
46 | // |
---|
47 | //| dojox.flash.info.version |
---|
48 | // |
---|
49 | // Or can communicate with Flash methods that were exposed: |
---|
50 | // |
---|
51 | //| var f = dojox.flash.get(); |
---|
52 | //| var results = f.sayHello("Some Message"); |
---|
53 | // |
---|
54 | // Your Flash files should use DojoExternalInterface.as to register methods; |
---|
55 | // this file wraps Flash's normal ExternalInterface but correct various |
---|
56 | // serialization bugs that ExternalInterface has. |
---|
57 | // |
---|
58 | // Note that dojox.flash is not meant to be a generic Flash embedding |
---|
59 | // mechanism; it is as generic as necessary to make Dojo Storage's |
---|
60 | // Flash Storage Provider as clean and modular as possible. If you want |
---|
61 | // a generic Flash embed mechanism see [SWFObject](http://blog.deconcept.com/swfobject/). |
---|
62 | // |
---|
63 | // Notes: |
---|
64 | // Note that dojox.flash can currently only work with one Flash object |
---|
65 | // on the page; it does not yet support multiple Flash objects on |
---|
66 | // the same page. |
---|
67 | // |
---|
68 | // Your code can detect whether the Flash player is installing or having |
---|
69 | // its version revved in two ways. First, if dojox.flash detects that |
---|
70 | // Flash installation needs to occur, it sets dojox.flash.info.installing |
---|
71 | // to true. Second, you can detect if installation is necessary with the |
---|
72 | // following callback: |
---|
73 | // |
---|
74 | //| dojo.connect(dojox.flash, "installing", myInstance, "myCallback"); |
---|
75 | // |
---|
76 | // You can use this callback to delay further actions that might need Flash; |
---|
77 | // when installation is finished the full page will be refreshed and the |
---|
78 | // user will be placed back on your page with Flash installed. |
---|
79 | // |
---|
80 | // ------------------- |
---|
81 | // Todo/Known Issues |
---|
82 | // ------------------- |
---|
83 | // |
---|
84 | // * On Internet Explorer, after doing a basic install, the page is |
---|
85 | // not refreshed or does not detect that Flash is now available. The way |
---|
86 | // to fix this is to create a custom small Flash file that is pointed to |
---|
87 | // during installation; when it is finished loading, it does a callback |
---|
88 | // that says that Flash installation is complete on IE, and we can proceed |
---|
89 | // to initialize the dojox.flash subsystem. |
---|
90 | // * Things aren't super tested for sending complex objects to Flash |
---|
91 | // methods, since Dojo Storage only needs strings |
---|
92 | // |
---|
93 | // Author- Brad Neuberg, http://codinginparadise.org |
---|
94 | } |
---|
95 | |
---|
96 | dojox.flash = { |
---|
97 | ready: false, |
---|
98 | url: null, |
---|
99 | |
---|
100 | _visible: true, |
---|
101 | _loadedListeners: [], |
---|
102 | _installingListeners: [], |
---|
103 | |
---|
104 | setSwf: function(/* String */ url, /* boolean? */ visible){ |
---|
105 | // summary: Sets the SWF files and versions we are using. |
---|
106 | // url: String |
---|
107 | // The URL to this Flash file. |
---|
108 | // visible: boolean? |
---|
109 | // Whether the Flash file is visible or not. If it is not visible we hide |
---|
110 | // it off the screen. This defaults to true (i.e. the Flash file is |
---|
111 | // visible). |
---|
112 | this.url = url; |
---|
113 | |
---|
114 | this._visible = true; |
---|
115 | if(visible !== null && visible !== undefined){ |
---|
116 | this._visible = visible; |
---|
117 | } |
---|
118 | |
---|
119 | // initialize ourselves |
---|
120 | this._initialize(); |
---|
121 | }, |
---|
122 | |
---|
123 | addLoadedListener: function(/* Function */ listener){ |
---|
124 | // summary: |
---|
125 | // Adds a listener to know when Flash is finished loading. |
---|
126 | // Useful if you don't want a dependency on dojo.event. |
---|
127 | // listener: Function |
---|
128 | // A function that will be called when Flash is done loading. |
---|
129 | |
---|
130 | this._loadedListeners.push(listener); |
---|
131 | }, |
---|
132 | |
---|
133 | addInstallingListener: function(/* Function */ listener){ |
---|
134 | // summary: |
---|
135 | // Adds a listener to know if Flash is being installed. |
---|
136 | // Useful if you don't want a dependency on dojo.event. |
---|
137 | // listener: Function |
---|
138 | // A function that will be called if Flash is being |
---|
139 | // installed |
---|
140 | |
---|
141 | this._installingListeners.push(listener); |
---|
142 | }, |
---|
143 | |
---|
144 | loaded: function(){ |
---|
145 | // summary: Called back when the Flash subsystem is finished loading. |
---|
146 | // description: |
---|
147 | // A callback when the Flash subsystem is finished loading and can be |
---|
148 | // worked with. To be notified when Flash is finished loading, add a |
---|
149 | // loaded listener: |
---|
150 | // |
---|
151 | // dojox.flash.addLoadedListener(loadedListener); |
---|
152 | |
---|
153 | dojox.flash.ready = true; |
---|
154 | if(dojox.flash._loadedListeners.length){ // FIXME: redundant if? use forEach? |
---|
155 | for(var i = 0;i < dojox.flash._loadedListeners.length; i++){ |
---|
156 | dojox.flash._loadedListeners[i].call(null); |
---|
157 | } |
---|
158 | } |
---|
159 | }, |
---|
160 | |
---|
161 | installing: function(){ |
---|
162 | // summary: Called if Flash is being installed. |
---|
163 | // description: |
---|
164 | // A callback to know if Flash is currently being installed or |
---|
165 | // having its version revved. To be notified if Flash is installing, connect |
---|
166 | // your callback to this method using the following: |
---|
167 | // |
---|
168 | // dojo.event.connect(dojox.flash, "installing", myInstance, "myCallback"); |
---|
169 | |
---|
170 | if(dojox.flash._installingListeners.length){ // FIXME: redundant if? use forEach? |
---|
171 | for(var i = 0; i < dojox.flash._installingListeners.length; i++){ |
---|
172 | dojox.flash._installingListeners[i].call(null); |
---|
173 | } |
---|
174 | } |
---|
175 | }, |
---|
176 | |
---|
177 | // Initializes dojox.flash. |
---|
178 | _initialize: function(){ |
---|
179 | //console.debug("dojox.flash._initialize"); |
---|
180 | // see if we need to rev or install Flash on this platform |
---|
181 | var installer = new dojox.flash.Install(); |
---|
182 | dojox.flash.installer = installer; |
---|
183 | |
---|
184 | if(installer.needed()){ |
---|
185 | installer.install(); |
---|
186 | }else{ |
---|
187 | // write the flash object into the page |
---|
188 | dojox.flash.obj = new dojox.flash.Embed(this._visible); |
---|
189 | dojox.flash.obj.write(); |
---|
190 | |
---|
191 | // setup the communicator |
---|
192 | dojox.flash.comm = new dojox.flash.Communicator(); |
---|
193 | } |
---|
194 | } |
---|
195 | }; |
---|
196 | |
---|
197 | |
---|
198 | dojox.flash.Info = function(){ |
---|
199 | // summary: A class that helps us determine whether Flash is available. |
---|
200 | // description: |
---|
201 | // A class that helps us determine whether Flash is available, |
---|
202 | // it's major and minor versions, and what Flash version features should |
---|
203 | // be used for Flash/JavaScript communication. Parts of this code |
---|
204 | // are adapted from the automatic Flash plugin detection code autogenerated |
---|
205 | // by the Macromedia Flash 8 authoring environment. |
---|
206 | // |
---|
207 | // An instance of this class can be accessed on dojox.flash.info after |
---|
208 | // the page is finished loading. |
---|
209 | |
---|
210 | this._detectVersion(); |
---|
211 | } |
---|
212 | |
---|
213 | dojox.flash.Info.prototype = { |
---|
214 | // version: String |
---|
215 | // The full version string, such as "8r22". |
---|
216 | version: -1, |
---|
217 | |
---|
218 | // versionMajor, versionMinor, versionRevision: String |
---|
219 | // The major, minor, and revisions of the plugin. For example, if the |
---|
220 | // plugin is 8r22, then the major version is 8, the minor version is 0, |
---|
221 | // and the revision is 22. |
---|
222 | versionMajor: -1, |
---|
223 | versionMinor: -1, |
---|
224 | versionRevision: -1, |
---|
225 | |
---|
226 | // capable: Boolean |
---|
227 | // Whether this platform has Flash already installed. |
---|
228 | capable: false, |
---|
229 | |
---|
230 | // installing: Boolean |
---|
231 | // Set if we are in the middle of a Flash installation session. |
---|
232 | installing: false, |
---|
233 | |
---|
234 | isVersionOrAbove: function( |
---|
235 | /* int */ reqMajorVer, |
---|
236 | /* int */ reqMinorVer, |
---|
237 | /* int */ reqVer){ /* Boolean */ |
---|
238 | // summary: |
---|
239 | // Asserts that this environment has the given major, minor, and revision |
---|
240 | // numbers for the Flash player. |
---|
241 | // description: |
---|
242 | // Asserts that this environment has the given major, minor, and revision |
---|
243 | // numbers for the Flash player. |
---|
244 | // |
---|
245 | // Example- To test for Flash Player 7r14: |
---|
246 | // |
---|
247 | // dojox.flash.info.isVersionOrAbove(7, 0, 14) |
---|
248 | // returns: |
---|
249 | // Returns true if the player is equal |
---|
250 | // or above the given version, false otherwise. |
---|
251 | |
---|
252 | // make the revision a decimal (i.e. transform revision 14 into |
---|
253 | // 0.14 |
---|
254 | reqVer = parseFloat("." + reqVer); |
---|
255 | |
---|
256 | if(this.versionMajor >= reqMajorVer && this.versionMinor >= reqMinorVer |
---|
257 | && this.versionRevision >= reqVer){ |
---|
258 | return true; |
---|
259 | }else{ |
---|
260 | return false; |
---|
261 | } |
---|
262 | }, |
---|
263 | |
---|
264 | _detectVersion: function(){ |
---|
265 | var versionStr; |
---|
266 | |
---|
267 | // loop backwards through the versions until we find the newest version |
---|
268 | for(var testVersion = 25; testVersion > 0; testVersion--){ |
---|
269 | if(dojo.isIE){ |
---|
270 | var axo; |
---|
271 | try{ |
---|
272 | if(testVersion > 6){ |
---|
273 | axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." |
---|
274 | + testVersion); |
---|
275 | }else{ |
---|
276 | axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"); |
---|
277 | } |
---|
278 | if(typeof axo == "object"){ |
---|
279 | if(testVersion == 6){ |
---|
280 | axo.AllowScriptAccess = "always"; |
---|
281 | } |
---|
282 | versionStr = axo.GetVariable("$version"); |
---|
283 | } |
---|
284 | }catch(e){ |
---|
285 | continue; |
---|
286 | } |
---|
287 | }else{ |
---|
288 | versionStr = this._JSFlashInfo(testVersion); |
---|
289 | } |
---|
290 | |
---|
291 | if(versionStr == -1 ){ |
---|
292 | this.capable = false; |
---|
293 | return; |
---|
294 | }else if(versionStr != 0){ |
---|
295 | var versionArray; |
---|
296 | if(dojo.isIE){ |
---|
297 | var tempArray = versionStr.split(" "); |
---|
298 | var tempString = tempArray[1]; |
---|
299 | versionArray = tempString.split(","); |
---|
300 | }else{ |
---|
301 | versionArray = versionStr.split("."); |
---|
302 | } |
---|
303 | |
---|
304 | this.versionMajor = versionArray[0]; |
---|
305 | this.versionMinor = versionArray[1]; |
---|
306 | this.versionRevision = versionArray[2]; |
---|
307 | |
---|
308 | // 7.0r24 == 7.24 |
---|
309 | var versionString = this.versionMajor + "." + this.versionRevision; |
---|
310 | this.version = parseFloat(versionString); |
---|
311 | |
---|
312 | this.capable = true; |
---|
313 | |
---|
314 | break; |
---|
315 | } |
---|
316 | } |
---|
317 | }, |
---|
318 | |
---|
319 | // JavaScript helper required to detect Flash Player PlugIn version |
---|
320 | // information. Internet Explorer uses a corresponding Visual Basic |
---|
321 | // version to interact with the Flash ActiveX control. |
---|
322 | _JSFlashInfo: function(testVersion){ |
---|
323 | // NS/Opera version >= 3 check for Flash plugin in plugin array |
---|
324 | if(navigator.plugins != null && navigator.plugins.length > 0){ |
---|
325 | if(navigator.plugins["Shockwave Flash 2.0"] || |
---|
326 | navigator.plugins["Shockwave Flash"]){ |
---|
327 | var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : ""; |
---|
328 | var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description; |
---|
329 | var descArray = flashDescription.split(" "); |
---|
330 | var tempArrayMajor = descArray[2].split("."); |
---|
331 | var versionMajor = tempArrayMajor[0]; |
---|
332 | var versionMinor = tempArrayMajor[1]; |
---|
333 | var tempArrayMinor = (descArray[3] || descArray[4]).split("r"); |
---|
334 | var versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0; |
---|
335 | var version = versionMajor + "." + versionMinor + "." + versionRevision; |
---|
336 | |
---|
337 | return version; |
---|
338 | } |
---|
339 | } |
---|
340 | |
---|
341 | return -1; |
---|
342 | } |
---|
343 | }; |
---|
344 | |
---|
345 | dojox.flash.Embed = function(visible){ |
---|
346 | // summary: A class that is used to write out the Flash object into the page. |
---|
347 | // description: |
---|
348 | // Writes out the necessary tags to embed a Flash file into the page. Note that |
---|
349 | // these tags are written out as the page is loaded using document.write, so |
---|
350 | // you must call this class before the page has finished loading. |
---|
351 | |
---|
352 | this._visible = visible; |
---|
353 | } |
---|
354 | |
---|
355 | dojox.flash.Embed.prototype = { |
---|
356 | // width: int |
---|
357 | // The width of this Flash applet. The default is the minimal width |
---|
358 | // necessary to show the Flash settings dialog. Current value is |
---|
359 | // 215 pixels. |
---|
360 | width: 215, |
---|
361 | |
---|
362 | // height: int |
---|
363 | // The height of this Flash applet. The default is the minimal height |
---|
364 | // necessary to show the Flash settings dialog. Current value is |
---|
365 | // 138 pixels. |
---|
366 | height: 138, |
---|
367 | |
---|
368 | // id: String |
---|
369 | // The id of the Flash object. Current value is 'flashObject'. |
---|
370 | id: "flashObject", |
---|
371 | |
---|
372 | // Controls whether this is a visible Flash applet or not. |
---|
373 | _visible: true, |
---|
374 | |
---|
375 | protocol: function(){ |
---|
376 | switch(window.location.protocol){ |
---|
377 | case "https:": |
---|
378 | return "https"; |
---|
379 | break; |
---|
380 | default: |
---|
381 | return "http"; |
---|
382 | break; |
---|
383 | } |
---|
384 | }, |
---|
385 | |
---|
386 | write: function(/* Boolean? */ doExpressInstall){ |
---|
387 | // summary: Writes the Flash into the page. |
---|
388 | // description: |
---|
389 | // This must be called before the page |
---|
390 | // is finished loading. |
---|
391 | // doExpressInstall: Boolean |
---|
392 | // Whether to write out Express Install |
---|
393 | // information. Optional value; defaults to false. |
---|
394 | |
---|
395 | // figure out the SWF file to get and how to write out the correct HTML |
---|
396 | // for this Flash version |
---|
397 | var objectHTML; |
---|
398 | var swfloc = dojox.flash.url; |
---|
399 | var swflocObject = swfloc; |
---|
400 | var swflocEmbed = swfloc; |
---|
401 | var dojoUrl = dojo.baseUrl; |
---|
402 | var xdomainBase = document.location.protocol + '//' + document.location.host; |
---|
403 | if(doExpressInstall){ |
---|
404 | // the location to redirect to after installing |
---|
405 | var redirectURL = escape(window.location); |
---|
406 | document.title = document.title.slice(0, 47) + " - Flash Player Installation"; |
---|
407 | var docTitle = escape(document.title); |
---|
408 | swflocObject += "?MMredirectURL=" + redirectURL |
---|
409 | + "&MMplayerType=ActiveX" |
---|
410 | + "&MMdoctitle=" + docTitle |
---|
411 | + "&baseUrl=" + escape(dojoUrl) |
---|
412 | + "&xdomain=" + escape(xdomainBase); |
---|
413 | swflocEmbed += "?MMredirectURL=" + redirectURL |
---|
414 | + "&MMplayerType=PlugIn" |
---|
415 | + "&baseUrl=" + escape(dojoUrl) |
---|
416 | + "&xdomain=" + escape(xdomainBase); |
---|
417 | }else{ |
---|
418 | // IE/Flash has an evil bug that shows up some time: if we load the |
---|
419 | // Flash and it isn't in the cache, ExternalInterface works fine -- |
---|
420 | // however, the second time when its loaded from the cache a timing |
---|
421 | // bug can keep ExternalInterface from working. The trick below |
---|
422 | // simply invalidates the Flash object in the cache all the time to |
---|
423 | // keep it loading fresh. -- Brad Neuberg |
---|
424 | swflocObject += "?cachebust=" + new Date().getTime(); |
---|
425 | swflocObject += "&baseUrl=" + escape(dojoUrl); |
---|
426 | swflocObject += "&xdomain=" + escape(xdomainBase); |
---|
427 | } |
---|
428 | |
---|
429 | if(swflocEmbed.indexOf("?") == -1){ |
---|
430 | swflocEmbed += '?baseUrl='+escape(dojoUrl); |
---|
431 | }else{ |
---|
432 | swflocEmbed += '&baseUrl='+escape(dojoUrl); |
---|
433 | } |
---|
434 | swflocEmbed += '&xdomain='+escape(xdomainBase); |
---|
435 | |
---|
436 | objectHTML = |
---|
437 | '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ' |
---|
438 | + 'codebase="' |
---|
439 | + this.protocol() |
---|
440 | + '://fpdownload.macromedia.com/pub/shockwave/cabs/flash/' |
---|
441 | + 'swflash.cab#version=8,0,0,0"\n ' |
---|
442 | + 'width="' + this.width + '"\n ' |
---|
443 | + 'height="' + this.height + '"\n ' |
---|
444 | + 'id="' + this.id + '"\n ' |
---|
445 | + 'name="' + this.id + '"\n ' |
---|
446 | + 'align="middle">\n ' |
---|
447 | + '<param name="allowScriptAccess" value="always"></param>\n ' |
---|
448 | + '<param name="movie" value="' + swflocObject + '"></param>\n ' |
---|
449 | + '<param name="quality" value="high"></param>\n ' |
---|
450 | + '<param name="bgcolor" value="#ffffff"></param>\n ' |
---|
451 | + '<embed src="' + swflocEmbed + '" ' |
---|
452 | + 'quality="high" ' |
---|
453 | + 'bgcolor="#ffffff" ' |
---|
454 | + 'width="' + this.width + '" ' |
---|
455 | + 'height="' + this.height + '" ' |
---|
456 | + 'id="' + this.id + 'Embed' + '" ' |
---|
457 | + 'name="' + this.id + '" ' |
---|
458 | + 'swLiveConnect="true" ' |
---|
459 | + 'align="middle" ' |
---|
460 | + 'allowScriptAccess="always" ' |
---|
461 | + 'type="application/x-shockwave-flash" ' |
---|
462 | + 'pluginspage="' |
---|
463 | + this.protocol() |
---|
464 | +'://www.macromedia.com/go/getflashplayer" ' |
---|
465 | + '></embed>\n' |
---|
466 | + '</object>\n'; |
---|
467 | |
---|
468 | // using same mechanism on all browsers now to write out |
---|
469 | // Flash object into page |
---|
470 | |
---|
471 | // document.write no longer works correctly due to Eolas patent workaround |
---|
472 | // in IE; nothing happens (i.e. object doesn't go into page if we use it) |
---|
473 | dojo.connect(dojo, "loaded", dojo.hitch(this, function(){ |
---|
474 | // Prevent putting duplicate SWFs onto the page |
---|
475 | var containerId = this.id + "Container"; |
---|
476 | if(dojo.byId(containerId)){ |
---|
477 | return; |
---|
478 | } |
---|
479 | |
---|
480 | var div = document.createElement("div"); |
---|
481 | div.id = this.id + "Container"; |
---|
482 | |
---|
483 | div.style.width = this.width + "px"; |
---|
484 | div.style.height = this.height + "px"; |
---|
485 | if(!this._visible){ |
---|
486 | div.style.position = "absolute"; |
---|
487 | div.style.zIndex = "10000"; |
---|
488 | div.style.top = "-1000px"; |
---|
489 | } |
---|
490 | |
---|
491 | div.innerHTML = objectHTML; |
---|
492 | |
---|
493 | var body = document.getElementsByTagName("body"); |
---|
494 | if(!body || !body.length){ |
---|
495 | throw new Error("No body tag for this page"); |
---|
496 | } |
---|
497 | body = body[0]; |
---|
498 | body.appendChild(div); |
---|
499 | })); |
---|
500 | }, |
---|
501 | |
---|
502 | get: function(){ /* Object */ |
---|
503 | // summary: Gets the Flash object DOM node. |
---|
504 | |
---|
505 | if(dojo.isIE || dojo.isWebKit){ |
---|
506 | //TODO: should this really be the else? |
---|
507 | return dojo.byId(this.id); |
---|
508 | }else{ |
---|
509 | // different IDs on OBJECT and EMBED tags or |
---|
510 | // else Firefox will return wrong one and |
---|
511 | // communication won't work; |
---|
512 | // also, document.getElementById() returns a |
---|
513 | // plugin but ExternalInterface calls don't |
---|
514 | // work on it so we have to use |
---|
515 | // document[id] instead |
---|
516 | return document[this.id + "Embed"]; |
---|
517 | } |
---|
518 | }, |
---|
519 | |
---|
520 | setVisible: function(/* Boolean */ visible){ |
---|
521 | //console.debug("setVisible, visible="+visible); |
---|
522 | |
---|
523 | // summary: Sets the visibility of this Flash object. |
---|
524 | var container = dojo.byId(this.id + "Container"); |
---|
525 | if(visible){ |
---|
526 | container.style.position = "absolute"; // IE -- Brad Neuberg |
---|
527 | container.style.visibility = "visible"; |
---|
528 | }else{ |
---|
529 | container.style.position = "absolute"; |
---|
530 | container.style.y = "-1000px"; |
---|
531 | container.style.visibility = "hidden"; |
---|
532 | } |
---|
533 | }, |
---|
534 | |
---|
535 | center: function(){ |
---|
536 | // summary: Centers the flash applet on the page. |
---|
537 | |
---|
538 | var elementWidth = this.width; |
---|
539 | var elementHeight = this.height; |
---|
540 | |
---|
541 | var viewport = dojo.window.getBox(); |
---|
542 | |
---|
543 | // compute the centered position |
---|
544 | var x = viewport.l + (viewport.w - elementWidth) / 2; |
---|
545 | var y = viewport.t + (viewport.h - elementHeight) / 2; |
---|
546 | |
---|
547 | // set the centered position |
---|
548 | var container = dojo.byId(this.id + "Container"); |
---|
549 | container.style.top = y + "px"; |
---|
550 | container.style.left = x + "px"; |
---|
551 | } |
---|
552 | }; |
---|
553 | |
---|
554 | |
---|
555 | dojox.flash.Communicator = function(){ |
---|
556 | // summary: |
---|
557 | // A class that is used to communicate between Flash and JavaScript. |
---|
558 | // description: |
---|
559 | // This class helps mediate Flash and JavaScript communication. Internally |
---|
560 | // it uses Flash 8's ExternalInterface API, but adds functionality to fix |
---|
561 | // various encoding bugs that ExternalInterface has. |
---|
562 | } |
---|
563 | |
---|
564 | dojox.flash.Communicator.prototype = { |
---|
565 | // Registers the existence of a Flash method that we can call with |
---|
566 | // JavaScript, using Flash 8's ExternalInterface. |
---|
567 | _addExternalInterfaceCallback: function(methodName){ |
---|
568 | //console.debug("addExternalInterfaceCallback, methodName="+methodName); |
---|
569 | var wrapperCall = dojo.hitch(this, function(){ |
---|
570 | // some browsers don't like us changing values in the 'arguments' array, so |
---|
571 | // make a fresh copy of it |
---|
572 | var methodArgs = new Array(arguments.length); |
---|
573 | for(var i = 0; i < arguments.length; i++){ |
---|
574 | methodArgs[i] = this._encodeData(arguments[i]); |
---|
575 | } |
---|
576 | |
---|
577 | var results = this._execFlash(methodName, methodArgs); |
---|
578 | results = this._decodeData(results); |
---|
579 | |
---|
580 | return results; |
---|
581 | }); |
---|
582 | |
---|
583 | this[methodName] = wrapperCall; |
---|
584 | }, |
---|
585 | |
---|
586 | // Encodes our data to get around ExternalInterface bugs that are still |
---|
587 | // present even in Flash 9. |
---|
588 | _encodeData: function(data){ |
---|
589 | //console.debug("encodeData, data=", data); |
---|
590 | if(!data || typeof data != "string"){ |
---|
591 | return data; |
---|
592 | } |
---|
593 | |
---|
594 | // transforming \ into \\ doesn't work; just use a custom encoding |
---|
595 | data = data.replace("\\", "&custom_backslash;"); |
---|
596 | |
---|
597 | // also use custom encoding for the null character to avoid problems |
---|
598 | data = data.replace(/\0/g, "&custom_null;"); |
---|
599 | |
---|
600 | return data; |
---|
601 | }, |
---|
602 | |
---|
603 | // Decodes our data to get around ExternalInterface bugs that are still |
---|
604 | // present even in Flash 9. |
---|
605 | _decodeData: function(data){ |
---|
606 | //console.debug("decodeData, data=", data); |
---|
607 | // wierdly enough, Flash sometimes returns the result as an |
---|
608 | // 'object' that is actually an array, rather than as a String; |
---|
609 | // detect this by looking for a length property; for IE |
---|
610 | // we also make sure that we aren't dealing with a typeof string |
---|
611 | // since string objects have length property there |
---|
612 | if(data && data.length && typeof data != "string"){ |
---|
613 | data = data[0]; |
---|
614 | } |
---|
615 | |
---|
616 | if(!data || typeof data != "string"){ |
---|
617 | return data; |
---|
618 | } |
---|
619 | |
---|
620 | // needed for IE; \0 is the NULL character |
---|
621 | data = data.replace(/\&custom_null\;/g, "\0"); |
---|
622 | |
---|
623 | // certain XMLish characters break Flash's wire serialization for |
---|
624 | // ExternalInterface; these are encoded on the |
---|
625 | // DojoExternalInterface side into a custom encoding, rather than |
---|
626 | // the standard entity encoding, because otherwise we won't be able to |
---|
627 | // differentiate between our own encoding and any entity characters |
---|
628 | // that are being used in the string itself |
---|
629 | data = data.replace(/\&custom_lt\;/g, "<") |
---|
630 | .replace(/\&custom_gt\;/g, ">") |
---|
631 | .replace(/\&custom_backslash\;/g, '\\'); |
---|
632 | |
---|
633 | return data; |
---|
634 | }, |
---|
635 | |
---|
636 | // Executes a Flash method; called from the JavaScript wrapper proxy we |
---|
637 | // create on dojox.flash.comm. |
---|
638 | _execFlash: function(methodName, methodArgs){ |
---|
639 | //console.debug("execFlash, methodName="+methodName+", methodArgs=", methodArgs); |
---|
640 | var plugin = dojox.flash.obj.get(); |
---|
641 | methodArgs = (methodArgs) ? methodArgs : []; |
---|
642 | |
---|
643 | // encode arguments that are strings |
---|
644 | for(var i = 0; i < methodArgs; i++){ |
---|
645 | if(typeof methodArgs[i] == "string"){ |
---|
646 | methodArgs[i] = this._encodeData(methodArgs[i]); |
---|
647 | } |
---|
648 | } |
---|
649 | |
---|
650 | // we use this gnarly hack below instead of |
---|
651 | // plugin[methodName] for two reasons: |
---|
652 | // 1) plugin[methodName] has no call() method, which |
---|
653 | // means we can't pass in multiple arguments dynamically |
---|
654 | // to a Flash method -- we can only have one |
---|
655 | // 2) On IE plugin[methodName] returns undefined -- |
---|
656 | // plugin[methodName] used to work on IE when we |
---|
657 | // used document.write but doesn't now that |
---|
658 | // we use dynamic DOM insertion of the Flash object |
---|
659 | // -- Brad Neuberg |
---|
660 | var flashExec = function(){ |
---|
661 | return eval(plugin.CallFunction( |
---|
662 | "<invoke name=\"" + methodName |
---|
663 | + "\" returntype=\"javascript\">" |
---|
664 | + __flash__argumentsToXML(methodArgs, 0) |
---|
665 | + "</invoke>")); |
---|
666 | }; |
---|
667 | var results = flashExec.call(methodArgs); |
---|
668 | |
---|
669 | if(typeof results == "string"){ |
---|
670 | results = this._decodeData(results); |
---|
671 | } |
---|
672 | |
---|
673 | return results; |
---|
674 | } |
---|
675 | } |
---|
676 | |
---|
677 | // FIXME: dojo.declare()-ify this |
---|
678 | |
---|
679 | // TODO: I did not test the Install code when I refactored Dojo Flash from 0.4 to |
---|
680 | // 1.0, so am not sure if it works. If Flash is not present I now prefer |
---|
681 | // that Gears is installed instead of Flash because GearsStorageProvider is |
---|
682 | // much easier to work with than Flash's hacky ExternalInteface. |
---|
683 | // -- Brad Neuberg |
---|
684 | dojox.flash.Install = function(){ |
---|
685 | // summary: Helps install Flash plugin if needed. |
---|
686 | // description: |
---|
687 | // Figures out the best way to automatically install the Flash plugin |
---|
688 | // for this browser and platform. Also determines if installation or |
---|
689 | // revving of the current plugin is needed on this platform. |
---|
690 | } |
---|
691 | |
---|
692 | dojox.flash.Install.prototype = { |
---|
693 | needed: function(){ /* Boolean */ |
---|
694 | // summary: |
---|
695 | // Determines if installation or revving of the current plugin is |
---|
696 | // needed. |
---|
697 | |
---|
698 | // do we even have flash? |
---|
699 | if(!dojox.flash.info.capable){ |
---|
700 | return true; |
---|
701 | } |
---|
702 | |
---|
703 | // Must have ExternalInterface which came in Flash 8 |
---|
704 | if(!dojox.flash.info.isVersionOrAbove(8, 0, 0)){ |
---|
705 | return true; |
---|
706 | } |
---|
707 | |
---|
708 | // otherwise we don't need installation |
---|
709 | return false; |
---|
710 | }, |
---|
711 | |
---|
712 | install: function(){ |
---|
713 | // summary: Performs installation or revving of the Flash plugin. |
---|
714 | var installObj; |
---|
715 | |
---|
716 | // indicate that we are installing |
---|
717 | dojox.flash.info.installing = true; |
---|
718 | dojox.flash.installing(); |
---|
719 | |
---|
720 | if(dojox.flash.info.capable == false){ // we have no Flash at all |
---|
721 | // write out a simple Flash object to force the browser to prompt |
---|
722 | // the user to install things |
---|
723 | installObj = new dojox.flash.Embed(false); |
---|
724 | installObj.write(); // write out HTML for Flash |
---|
725 | }else if(dojox.flash.info.isVersionOrAbove(6, 0, 65)){ // Express Install |
---|
726 | installObj = new dojox.flash.Embed(false); |
---|
727 | installObj.write(true); // write out HTML for Flash 8 version+ |
---|
728 | installObj.setVisible(true); |
---|
729 | installObj.center(); |
---|
730 | }else{ // older Flash install than version 6r65 |
---|
731 | alert("This content requires a more recent version of the Macromedia " |
---|
732 | +" Flash Player."); |
---|
733 | window.location.href = + dojox.flash.Embed.protocol() + |
---|
734 | "://www.macromedia.com/go/getflashplayer"; |
---|
735 | } |
---|
736 | }, |
---|
737 | |
---|
738 | // Called when the Express Install is either finished, failed, or was |
---|
739 | // rejected by the user. |
---|
740 | _onInstallStatus: function(msg){ |
---|
741 | if (msg == "Download.Complete"){ |
---|
742 | // Installation is complete. |
---|
743 | dojox.flash._initialize(); |
---|
744 | }else if(msg == "Download.Cancelled"){ |
---|
745 | alert("This content requires a more recent version of the Macromedia " |
---|
746 | +" Flash Player."); |
---|
747 | window.location.href = dojox.flash.Embed.protocol() + |
---|
748 | "://www.macromedia.com/go/getflashplayer"; |
---|
749 | }else if (msg == "Download.Failed"){ |
---|
750 | // The end user failed to download the installer due to a network failure |
---|
751 | alert("There was an error downloading the Flash Player update. " |
---|
752 | + "Please try again later, or visit macromedia.com to download " |
---|
753 | + "the latest version of the Flash plugin."); |
---|
754 | } |
---|
755 | } |
---|
756 | } |
---|
757 | |
---|
758 | // find out if Flash is installed |
---|
759 | dojox.flash.info = new dojox.flash.Info(); |
---|
760 | |
---|
761 | // vim:ts=4:noet:tw=0: |
---|