File: uploader_js_swf.js - YUI Library
Version 3.18.1
Show:

File: uploader/js/swf.js

  1. /**
  2. * This module provides a UI for file selection and multiple file upload capability using
  3. * Flash as a transport engine.
  4. * The supported features include: automatic upload queue management, upload progress
  5. * tracking, file filtering, server response retrieval and error reporting.
  6. *
  7. * @module uploader-flash
  8. * @deprecated
  9. */
  10. // Shorthands for external modules
  11. var substitute = Y.Lang.sub,
  12. UploaderQueue = Y.Uploader.Queue;
  13. /**
  14. * Embed a Flash applications in a standard manner and communicate with it
  15. * via External Interface.
  16. * @module swf
  17. */
  18. var Event = Y.Event,
  19. SWFDetect = Y.SWFDetect,
  20. Lang = Y.Lang,
  21. uA = Y.UA,
  22. Node = Y.Node,
  23. Escape = Y.Escape,
  24. // private
  25. FLASH_CID = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000",
  26. FLASH_TYPE = "application/x-shockwave-flash",
  27. FLASH_VER = "10.0.22",
  28. EXPRESS_INSTALL_URL = "http://fpdownload.macromedia.com/pub/flashplayer/update/current/swf/autoUpdater.swf?" + Math.random(),
  29. EVENT_HANDLER = "SWF.eventHandler",
  30. possibleAttributes = {align:"", allowFullScreen:"", allowNetworking:"", allowScriptAccess:"", base:"", bgcolor:"", loop:"", menu:"", name:"", play: "", quality:"", salign:"", scale:"", tabindex:"", wmode:""};
  31. /**
  32. * The SWF utility is a tool for embedding Flash applications in HTML pages.
  33. * @module swf
  34. * @title SWF Utility
  35. * @requires event-custom, node, swfdetect
  36. */
  37. /**
  38. * Creates the SWF instance and keeps the configuration data
  39. *
  40. * @class SWF
  41. * @uses Y.Event.Target
  42. * @constructor
  43. * @param {String|HTMLElement} id The id of the element, or the element itself that the SWF will be inserted into.
  44. * The width and height of the SWF will be set to the width and height of this container element.
  45. * @param {String} swfURL The URL of the SWF to be embedded into the page.
  46. * @param {Object} p_oAttributes (optional) Configuration parameters for the Flash application and values for Flashvars
  47. * to be passed to the SWF. The p_oAttributes object allows the following additional properties:
  48. * <dl>
  49. * <dt>version : String</dt>
  50. * <dd>The minimum version of Flash required on the user's machine.</dd>
  51. * <dt>fixedAttributes : Object</dt>
  52. * <dd>An object literal containing one or more of the following String keys and their values: <code>align,
  53. * allowFullScreen, allowNetworking, allowScriptAccess, base, bgcolor, menu, name, quality, salign, scale,
  54. * tabindex, wmode.</code> event from the thumb</dd>
  55. * </dl>
  56. */
  57. function SWF (p_oElement /*:String*/, swfURL /*:String*/, p_oAttributes /*:Object*/ ) {
  58. this._id = Y.guid("yuiswf");
  59. var _id = this._id;
  60. var oElement = Node.one(p_oElement);
  61. var p_oAttributes = p_oAttributes || {};
  62. var flashVersion = p_oAttributes.version || FLASH_VER;
  63. var flashVersionSplit = (flashVersion + '').split(".");
  64. var isFlashVersionRight = SWFDetect.isFlashVersionAtLeast(parseInt(flashVersionSplit[0], 10), parseInt(flashVersionSplit[1], 10), parseInt(flashVersionSplit[2], 10));
  65. var canExpressInstall = (SWFDetect.isFlashVersionAtLeast(8,0,0));
  66. var shouldExpressInstall = canExpressInstall && !isFlashVersionRight && p_oAttributes.useExpressInstall;
  67. var flashURL = (shouldExpressInstall)?EXPRESS_INSTALL_URL:swfURL;
  68. var objstring = '<object ';
  69. var w, h;
  70. var flashvarstring = "yId=" + Y.id + "&YUISwfId=" + _id + "&YUIBridgeCallback=" + EVENT_HANDLER + "&allowedDomain=" + document.location.hostname;
  71. Y.SWF._instances[_id] = this;
  72. if (oElement && (isFlashVersionRight || shouldExpressInstall) && flashURL) {
  73. objstring += 'id="' + _id + '" ';
  74. if (uA.ie) {
  75. objstring += 'classid="' + FLASH_CID + '" ';
  76. } else {
  77. objstring += 'type="' + FLASH_TYPE + '" data="' + Escape.html(flashURL) + '" ';
  78. }
  79. w = "100%";
  80. h = "100%";
  81. objstring += 'width="' + w + '" height="' + h + '">';
  82. if (uA.ie) {
  83. objstring += '<param name="movie" value="' + Escape.html(flashURL) + '"/>';
  84. }
  85. for (var attribute in p_oAttributes.fixedAttributes) {
  86. if (possibleAttributes.hasOwnProperty(attribute)) {
  87. objstring += '<param name="' + Escape.html(attribute) + '" value="' + Escape.html(p_oAttributes.fixedAttributes[attribute]) + '"/>';
  88. }
  89. }
  90. for (var flashvar in p_oAttributes.flashVars) {
  91. var fvar = p_oAttributes.flashVars[flashvar];
  92. if (Lang.isString(fvar)) {
  93. flashvarstring += "&" + Escape.html(flashvar) + "=" + Escape.html(encodeURIComponent(fvar));
  94. }
  95. }
  96. if (flashvarstring) {
  97. objstring += '<param name="flashVars" value="' + flashvarstring + '"/>';
  98. }
  99. objstring += "</object>";
  100. //using innerHTML as setHTML/setContent causes some issues with ExternalInterface for IE versions of the player
  101. oElement.set("innerHTML", objstring);
  102. this._swf = Node.one("#" + _id);
  103. } else {
  104. /**
  105. * Fired when the Flash player version on the user's machine is
  106. * below the required value.
  107. *
  108. * @event wrongflashversion
  109. */
  110. var event = {};
  111. event.type = "wrongflashversion";
  112. this.publish("wrongflashversion", {fireOnce:true});
  113. this.fire("wrongflashversion", event);
  114. }
  115. }
  116. /**
  117. * @private
  118. * The static collection of all instances of the SWFs on the page.
  119. * @property _instances
  120. * @type Object
  121. */
  122. SWF._instances = SWF._instances || {};
  123. /**
  124. * @private
  125. * Handles an event coming from within the SWF and delegate it
  126. * to a specific instance of SWF.
  127. * @method eventHandler
  128. * @param swfid {String} the id of the SWF dispatching the event
  129. * @param event {Object} the event being transmitted.
  130. */
  131. SWF.eventHandler = function (swfid, event) {
  132. SWF._instances[swfid]._eventHandler(event);
  133. };
  134. SWF.prototype = {
  135. /**
  136. * @private
  137. * Propagates a specific event from Flash to JS.
  138. * @method _eventHandler
  139. * @param event {Object} The event to be propagated from Flash.
  140. */
  141. _eventHandler: function(event) {
  142. if (event.type === "swfReady") {
  143. this.publish("swfReady", {fireOnce:true});
  144. this.fire("swfReady", event);
  145. } else if(event.type === "log") {
  146. Y.log(event.message, event.category, this.toString());
  147. } else {
  148. this.fire(event.type, event);
  149. }
  150. },
  151. /**
  152. * Calls a specific function exposed by the SWF's
  153. * ExternalInterface.
  154. * @method callSWF
  155. * @param func {String} the name of the function to call
  156. * @param args {Array} the set of arguments to pass to the function.
  157. */
  158. callSWF: function (func, args)
  159. {
  160. if (!args) {
  161. args= [];
  162. }
  163. if (this._swf._node[func]) {
  164. return(this._swf._node[func].apply(this._swf._node, args));
  165. } else {
  166. return null;
  167. }
  168. },
  169. /**
  170. * Public accessor to the unique name of the SWF instance.
  171. *
  172. * @method toString
  173. * @return {String} Unique name of the SWF instance.
  174. */
  175. toString: function()
  176. {
  177. return "SWF " + this._id;
  178. }
  179. };
  180. Y.augment(SWF, Y.EventTarget);
  181. Y.SWF = SWF;