swf-debug.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /*
  2. Copyright (c) 2009, Yahoo! Inc. All rights reserved.
  3. Code licensed under the BSD License:
  4. http://developer.yahoo.net/yui/license.txt
  5. version: 2.8.0r4
  6. */
  7. YAHOO.namespace("widget");
  8. (function () {
  9. var version = 0;
  10. var UA = YAHOO.env.ua;
  11. var sF = "ShockwaveFlash";
  12. if (UA.gecko || UA.webkit || UA.opera) {
  13. if ((mF = navigator.mimeTypes['application/x-shockwave-flash'])) {
  14. if ((eP = mF.enabledPlugin)) {
  15. var vS = [];
  16. vS = eP.description.replace(/\s[rd]/g, '.').replace(/[A-Za-z\s]+/g, '').split('.');
  17. version = vS[0] + '.';
  18. switch((vS[2].toString()).length)
  19. {
  20. case 1:
  21. version += "00";
  22. break;
  23. case 2:
  24. version += "0";
  25. break;
  26. }
  27. version += vS[2];
  28. version = parseFloat(version);
  29. }
  30. }
  31. }
  32. else if(UA.ie) {
  33. try
  34. {
  35. var ax6 = new ActiveXObject(sF + "." + sF + ".6");
  36. ax6.AllowScriptAccess = "always";
  37. }
  38. catch(e)
  39. {
  40. if(ax6 != null)
  41. {
  42. version = 6.0;
  43. }
  44. }
  45. if (version == 0) {
  46. try
  47. {
  48. var ax = new ActiveXObject(sF + "." + sF);
  49. var vS = [];
  50. vS = ax.GetVariable("$version").replace(/[A-Za-z\s]+/g, '').split(',');
  51. version = vS[0] + '.';
  52. switch((vS[2].toString()).length)
  53. {
  54. case 1:
  55. version += "00";
  56. break;
  57. case 2:
  58. version += "0";
  59. break;
  60. }
  61. version += vS[2];
  62. version = parseFloat(version);
  63. } catch (e) {}
  64. }
  65. }
  66. UA.flash = version;
  67. YAHOO.util.SWFDetect = {
  68. getFlashVersion : function () {
  69. return version;
  70. },
  71. isFlashVersionAtLeast : function (ver) {
  72. return version >= ver;
  73. }
  74. };
  75. var Dom = YAHOO.util.Dom,
  76. Event = YAHOO.util.Event,
  77. SWFDetect = YAHOO.util.SWFDetect,
  78. Lang = YAHOO.lang,
  79. // private
  80. FLASH_CID = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000",
  81. FLASH_TYPE = "application/x-shockwave-flash",
  82. FLASH_VER = "10.22",
  83. EXPRESS_INSTALL_URL = "http://fpdownload.macromedia.com/pub/flashplayer/update/current/swf/autoUpdater.swf?" + Math.random(),
  84. EVENT_HANDLER = "YAHOO.widget.SWF.eventHandler",
  85. possibleAttributes = {align:"", allowNetworking:"", allowScriptAccess:"", base:"", bgcolor:"", menu:"", name:"", quality:"", salign:"", scale:"", tabindex:"", wmode:""};
  86. /**
  87. * The SWF utility is a tool for embedding Flash applications in HTMl pages.
  88. * @module swf
  89. * @title SWF Utility
  90. * @requires yahoo, dom, event
  91. * @namespace YAHOO.widget
  92. */
  93. /**
  94. * Creates the SWF instance and keeps the configuration data
  95. *
  96. * @class SWF
  97. * @extends YAHOO.util.Element
  98. * @constructor
  99. * @param {String|HTMLElement} id The id of the element, or the element itself that the SWF will be inserted into.
  100. * The width and height of the SWF will be set to the width and height of this container element.
  101. * @param {String} swfURL The URL of the SWF to be embedded into the page.
  102. * @param {Object} p_oAttributes (optional) Configuration parameters for the Flash application and values for Flashvars
  103. * to be passed to the SWF.
  104. */
  105. YAHOO.widget.SWF = function (p_oElement /*:String*/, swfURL /*:String*/, p_oAttributes /*:Object*/ ) {
  106. this._queue = this._queue || [];
  107. this._events = this._events || {};
  108. this._configs = this._configs || {};
  109. /**
  110. * The DOM id of this instance of the element. Automatically generated.
  111. * @property _id
  112. * @type String
  113. */
  114. this._id = Dom.generateId(null, "yuiswf");
  115. if(p_oAttributes.host) this._host = p_oAttributes.host;
  116. var _id = this._id;
  117. var oElement = Dom.get(p_oElement);
  118. var flashVersion = (p_oAttributes["version"] || FLASH_VER);
  119. var isFlashVersionRight = SWFDetect.isFlashVersionAtLeast(flashVersion);
  120. var canExpressInstall = (UA.flash >= 8.0);
  121. var shouldExpressInstall = canExpressInstall && !isFlashVersionRight && p_oAttributes["useExpressInstall"];
  122. var flashURL = (shouldExpressInstall)?EXPRESS_INSTALL_URL:swfURL;
  123. var objstring = '<object ';
  124. var w, h;
  125. var flashvarstring = "YUISwfId=" + _id + "&YUIBridgeCallback=" + EVENT_HANDLER;
  126. YAHOO.widget.SWF._instances[_id] = this;
  127. if (oElement && (isFlashVersionRight || shouldExpressInstall) && flashURL) {
  128. objstring += 'id="' + _id + '" ';
  129. if (UA.ie) {
  130. objstring += 'classid="' + FLASH_CID + '" '
  131. }
  132. else {
  133. objstring += 'type="' + FLASH_TYPE + '" data="' + flashURL + '" ';
  134. }
  135. w = "100%";
  136. h = "100%";
  137. objstring += 'width="' + w + '" height="' + h + '">';
  138. if (UA.ie) {
  139. objstring += '<param name="movie" value="' + flashURL + '"/>';
  140. }
  141. for (var attribute in p_oAttributes.fixedAttributes) {
  142. if (possibleAttributes.hasOwnProperty(attribute)) {
  143. objstring += '<param name="' + attribute + '" value="' + p_oAttributes.fixedAttributes[attribute] + '"/>';
  144. }
  145. }
  146. for (var flashvar in p_oAttributes.flashVars) {
  147. var fvar = p_oAttributes.flashVars[flashvar];
  148. if (Lang.isString(fvar)) {
  149. flashvarstring += "&" + flashvar + "=" + encodeURIComponent(fvar);
  150. }
  151. }
  152. if (flashvarstring) {
  153. objstring += '<param name="flashVars" value="' + flashvarstring + '"/>';
  154. }
  155. objstring += "</object>";
  156. oElement.innerHTML = objstring;
  157. }
  158. YAHOO.widget.SWF.superclass.constructor.call(this, Dom.get(_id));
  159. this._swf = Dom.get(_id);
  160. };
  161. /**
  162. * The static collection of all instances of the SWFs on the page.
  163. * @property _instances
  164. * @private
  165. * @type Object
  166. */
  167. YAHOO.widget.SWF._instances = YAHOO.widget.SWF._instances || {};
  168. /**
  169. * Handles an event coming from within the SWF and delegate it
  170. * to a specific instance of SWF.
  171. * @method eventHandler
  172. * @param swfid {String} the id of the SWF dispatching the event
  173. * @param event {Object} the event being transmitted.
  174. * @private
  175. */
  176. YAHOO.widget.SWF.eventHandler = function (swfid, event) {
  177. YAHOO.widget.SWF._instances[swfid]._eventHandler(event);
  178. };
  179. YAHOO.extend(YAHOO.widget.SWF, YAHOO.util.Element, {
  180. _eventHandler: function(event)
  181. {
  182. if (event.type == "swfReady")
  183. {
  184. this.createEvent("swfReady", {fireOnce:true});
  185. this.fireEvent("swfReady", event);
  186. }
  187. else if(event.type == "log")
  188. {
  189. YAHOO.log(event.message, event.category, this._host ? this._host.toString() : this.toString());
  190. }
  191. else
  192. {
  193. if(this._host && this._host.fireEvent)
  194. {
  195. this._host.fireEvent(event.type, event);
  196. }
  197. else
  198. {
  199. this.fireEvent(event.type, event);
  200. }
  201. }
  202. },
  203. /**
  204. * Calls a specific function exposed by the SWF's
  205. * ExternalInterface.
  206. * @method callSWF
  207. * @param func {String} the name of the function to call
  208. * @param args {Object} the set of arguments to pass to the function.
  209. */
  210. callSWF: function (func, args)
  211. {
  212. if (!args) {
  213. args= [];
  214. };
  215. if (this._swf[func]) {
  216. return(this._swf[func].apply(this._swf, args));
  217. } else {
  218. return null;
  219. }
  220. },
  221. /**
  222. * Public accessor to the unique name of the SWF instance.
  223. *
  224. * @method toString
  225. * @return {String} Unique name of the SWF instance.
  226. */
  227. toString: function()
  228. {
  229. return "SWF " + this._id;
  230. }
  231. });
  232. })();
  233. YAHOO.register("swf", YAHOO.widget.SWF, {version: "2.8.0r4", build: "2449"});