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");
131 var oElement = Dom.get(p_oElement);
132 var flashVersion = (p_oAttributes["version"] || FLASH_VER);
133 var isFlashVersionRight = SWFDetect.isFlashVersionAtLeast(flashVersion);
134 var canExpressInstall = (UA.flash >= 8.0);
135 var shouldExpressInstall = canExpressInstall && !isFlashVersionRight && p_oAttributes["useExpressInstall"];
136 var flashURL = (shouldExpressInstall)?EXPRESS_INSTALL_URL:swfURL;
137 var objstring = '<object ';
139 var flashvarstring = "YUISwfId=" + _id + "&YUIBridgeCallback=" + EVENT_HANDLER + "&";
141 YAHOO.widget.SWF._instances[_id] = this;
143 if (oElement && (isFlashVersionRight || shouldExpressInstall) && flashURL) {
144 objstring += 'id="' + _id + '" ';
146 objstring += 'classid="' + FLASH_CID + '" '
149 objstring += 'type="' + FLASH_TYPE + '" data="' + flashURL + '" ';
155 objstring += 'width="' + w + '" height="' + h + '">';
158 objstring += '<param name="movie" value="' + flashURL + '"/>';
161 for (var attribute in p_oAttributes.fixedAttributes) {
162 if (possibleAttributes.hasOwnProperty(attribute)) {
163 objstring += '<param name="' + attribute + '" value="' + p_oAttributes.fixedAttributes[attribute] + '"/>';
167 for (var flashvar in p_oAttributes.flashVars) {
168 var fvar = p_oAttributes.flashVars[flashvar];
169 if (Lang.isString(fvar)) {
170 flashvarstring += "&" + flashvar + "=" + encodeURIComponent(fvar);
174 if (flashvarstring) {
175 objstring += '<param name="flashVars" value="' + flashvarstring + '"/>';
178 objstring += "</object>";
180 oElement.innerHTML = objstring;
183 YAHOO.widget.SWF.superclass.constructor.call(this, Dom.get(_id));
184 this._swf = Dom.get(_id);
188 * The static collection of all instances of the SWFs on the page.
189 * @property _instances
194 YAHOO.widget.SWF._instances = YAHOO.widget.SWF._instances || {};
197 * Handles an event coming from within the SWF and delegate it
198 * to a specific instance of SWF.
199 * @method eventHandler
200 * @param swfid {String} the id of the SWF dispatching the event
201 * @param event {Object} the event being transmitted.
204 YAHOO.widget.SWF.eventHandler = function (swfid, event) {
205 YAHOO.widget.SWF._instances[swfid]._eventHandler(event);
208 YAHOO.extend(YAHOO.widget.SWF, YAHOO.util.Element, {
209 _eventHandler: function(event)
211 if (event.type == "swfReady") {
212 this.createEvent("swfReady");
213 this.fireEvent("swfReady", event);
216 this.fireEvent(event.type, event);
220 * Calls a specific function exposed by the SWF's
223 * @param func {String} the name of the function to call
224 * @param args {Object} the set of arguments to pass to the function.
226 callSWF: function (func, args)
228 if (this._swf[func]) {
229 return(this._swf[func].apply(this._swf, args));
238 YAHOO.register("swf", YAHOO.widget.SWF, {version: "2.8.0r4", build: "2449"});