2 Copyright (c) 2009, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.net/yui/license.txt
7 YAHOO.namespace("widget");
12 var UA = YAHOO.env.ua;
13 var sF = "ShockwaveFlash";
15 if (UA.gecko || UA.webkit || UA.opera) {
16 if ((mF = navigator.mimeTypes['application/x-shockwave-flash'])) {
17 if ((eP = mF.enabledPlugin)) {
19 vS = eP.description.replace(/\s[rd]/g, '.').replace(/[A-Za-z\s]+/g, '').split('.');
20 version = vS[0] + '.';
21 switch((vS[2].toString()).length)
31 version = parseFloat(version);
38 var ax6 = new ActiveXObject(sF + "." + sF + ".6");
39 ax6.AllowScriptAccess = "always";
51 var ax = new ActiveXObject(sF + "." + sF);
53 vS = ax.GetVariable("$version").replace(/[A-Za-z\s]+/g, '').split(',');
54 version = vS[0] + '.';
55 switch((vS[2].toString()).length)
65 version = parseFloat(version);
73 YAHOO.util.SWFDetect = {
74 getFlashVersion : function () {
78 isFlashVersionAtLeast : function (ver) {
79 return version >= ver;
83 var Dom = YAHOO.util.Dom,
84 Event = YAHOO.util.Event,
85 SWFDetect = YAHOO.util.SWFDetect,
89 FLASH_CID = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000",
90 FLASH_TYPE = "application/x-shockwave-flash",
92 EXPRESS_INSTALL_URL = "http://fpdownload.macromedia.com/pub/flashplayer/update/current/swf/autoUpdater.swf?" + Math.random(),
93 EVENT_HANDLER = "YAHOO.widget.SWF.eventHandler",
94 possibleAttributes = {align:"", allowNetworking:"", allowScriptAccess:"", base:"", bgcolor:"", menu:"", name:"", quality:"", salign:"", scale:"", tabindex:"", wmode:""};
97 * The SWF utility is a tool for embedding Flash applications in HTMl pages.
100 * @requires yahoo, dom, event
101 * @namespace YAHOO.widget
105 * Creates the SWF instance and keeps the configuration data
108 * @extends YAHOO.util.Element
110 * @param {String|HTMLElement} id The id of the element, or the element itself that the SWF will be inserted into.
111 * The width and height of the SWF will be set to the width and height of this container element.
112 * @param {String} swfURL The URL of the SWF to be embedded into the page.
113 * @param {Object} p_oAttributes (optional) Configuration parameters for the Flash application and values for Flashvars
114 * to be passed to the SWF.
117 YAHOO.widget.SWF = function (p_oElement /*:String*/, swfURL /*:String*/, p_oAttributes /*:Object*/ ) {
119 this._queue = this._queue || [];
120 this._events = this._events || {};
121 this._configs = this._configs || {};
124 * The DOM id of this instance of the element. Automatically generated.
128 this._id = Dom.generateId(null, "yuiswf");
130 if(p_oAttributes.host) this._host = p_oAttributes.host;
133 var oElement = Dom.get(p_oElement);
134 var flashVersion = (p_oAttributes["version"] || FLASH_VER);
135 var isFlashVersionRight = SWFDetect.isFlashVersionAtLeast(flashVersion);
136 var canExpressInstall = (UA.flash >= 8.0);
137 var shouldExpressInstall = canExpressInstall && !isFlashVersionRight && p_oAttributes["useExpressInstall"];
138 var flashURL = (shouldExpressInstall)?EXPRESS_INSTALL_URL:swfURL;
139 var objstring = '<object ';
141 var flashvarstring = "YUISwfId=" + _id + "&YUIBridgeCallback=" + EVENT_HANDLER;
143 YAHOO.widget.SWF._instances[_id] = this;
145 if (oElement && (isFlashVersionRight || shouldExpressInstall) && flashURL) {
146 objstring += 'id="' + _id + '" ';
148 objstring += 'classid="' + FLASH_CID + '" '
151 objstring += 'type="' + FLASH_TYPE + '" data="' + flashURL + '" ';
157 objstring += 'width="' + w + '" height="' + h + '">';
160 objstring += '<param name="movie" value="' + flashURL + '"/>';
163 for (var attribute in p_oAttributes.fixedAttributes) {
164 if (possibleAttributes.hasOwnProperty(attribute)) {
165 objstring += '<param name="' + attribute + '" value="' + p_oAttributes.fixedAttributes[attribute] + '"/>';
169 for (var flashvar in p_oAttributes.flashVars) {
170 var fvar = p_oAttributes.flashVars[flashvar];
171 if (Lang.isString(fvar)) {
172 flashvarstring += "&" + flashvar + "=" + encodeURIComponent(fvar);
176 if (flashvarstring) {
177 objstring += '<param name="flashVars" value="' + flashvarstring + '"/>';
180 objstring += "</object>";
182 oElement.innerHTML = objstring;
185 YAHOO.widget.SWF.superclass.constructor.call(this, Dom.get(_id));
186 this._swf = Dom.get(_id);
190 * The static collection of all instances of the SWFs on the page.
191 * @property _instances
196 YAHOO.widget.SWF._instances = YAHOO.widget.SWF._instances || {};
199 * Handles an event coming from within the SWF and delegate it
200 * to a specific instance of SWF.
201 * @method eventHandler
202 * @param swfid {String} the id of the SWF dispatching the event
203 * @param event {Object} the event being transmitted.
206 YAHOO.widget.SWF.eventHandler = function (swfid, event) {
207 YAHOO.widget.SWF._instances[swfid]._eventHandler(event);
210 YAHOO.extend(YAHOO.widget.SWF, YAHOO.util.Element, {
211 _eventHandler: function(event)
213 if (event.type == "swfReady")
215 this.createEvent("swfReady", {fireOnce:true});
216 this.fireEvent("swfReady", event);
218 else if(event.type == "log")
220 YAHOO.log(event.message, event.category, this._host ? this._host.toString() : this.toString());
224 if(this._host && this._host.fireEvent)
226 this._host.fireEvent(event.type, event);
230 this.fireEvent(event.type, event);
236 * Calls a specific function exposed by the SWF's
239 * @param func {String} the name of the function to call
240 * @param args {Object} the set of arguments to pass to the function.
242 callSWF: function (func, args)
248 if (this._swf[func]) {
249 return(this._swf[func].apply(this._swf, args));
256 * Public accessor to the unique name of the SWF instance.
259 * @return {String} Unique name of the SWF instance.
263 return "SWF " + this._id;
269 YAHOO.register("swf", YAHOO.widget.SWF, {version: "2.8.0r4", build: "2449"});