_base.js 25 KB

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