_base.js 25 KB

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