2 Copyright (c) 2011, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
7 YAHOO.namespace("widget");
12 var UA = YAHOO.env.ua;
13 var sF = "ShockwaveFlash";
16 if (UA.gecko || UA.webkit || UA.opera) {
17 if ((mF = navigator.mimeTypes['application/x-shockwave-flash'])) {
18 if ((eP = mF.enabledPlugin)) {
20 vS = eP.description.replace(/\s[rd]/g, '.').replace(/[A-Za-z\s]+/g, '').split('.');
21 version = vS[0] + '.';
22 switch((vS[2].toString()).length)
32 version = parseFloat(version);
39 var ax6 = new ActiveXObject(sF + "." + sF + ".6");
40 ax6.AllowScriptAccess = "always";
52 var ax = new ActiveXObject(sF + "." + sF);
54 vS = ax.GetVariable("$version").replace(/[A-Za-z\s]+/g, '').split(',');
55 version = vS[0] + '.';
56 switch((vS[2].toString()).length)
66 version = parseFloat(version);
74 YAHOO.util.SWFDetect = {
75 getFlashVersion : function () {
79 isFlashVersionAtLeast : function (ver) {
80 return version >= ver;
83 parseFlashVersion : function (ver)
85 var flashVersion = ver;
86 if(YAHOO.lang.isString(ver))
88 var verSplit = ver.split(".");
89 if(verSplit.length > 2)
91 flashVersion = parseInt(verSplit[0]);
92 flashVersion += parseInt(verSplit[2]) * .001;
96 flashVersion = parseFloat(ver);
99 return YAHOO.lang.isNumber(flashVersion) ? flashVersion : null;
103 var Dom = YAHOO.util.Dom,
104 Event = YAHOO.util.Event,
105 SWFDetect = YAHOO.util.SWFDetect,
109 FLASH_CID = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000",
110 FLASH_TYPE = "application/x-shockwave-flash",
112 EXPRESS_INSTALL_URL = "http://fpdownload.macromedia.com/pub/flashplayer/update/current/swf/autoUpdater.swf?" + Math.random(),
113 EVENT_HANDLER = "YAHOO.widget.SWF.eventHandler",
114 possibleAttributes = {align:"", allowfullscreen: "", allownetworking:"", allowscriptaccess:"", base:"", bgcolor:"", devicefont: "", loop: "", menu:"", name:"", play: "", quality:"", salign:"", seamlesstabbing: "", scale:"", swliveconnect: "", tabindex:"", wmode:""};
117 * The SWF utility is a tool for embedding Flash applications in HTMl pages.
120 * @requires yahoo, dom, event
121 * @namespace YAHOO.widget
125 * Creates the SWF instance and keeps the configuration data
128 * @extends YAHOO.util.Element
130 * @param {String|HTMLElement} id The id of the element, or the element itself that the SWF will be inserted into.
131 * The width and height of the SWF will be set to the width and height of this container element.
132 * @param {String} swfURL The URL of the SWF to be embedded into the page.
133 * @param {Object} p_oAttributes (optional) Configuration parameters for the Flash application and values for Flashvars
134 * to be passed to the SWF.
137 YAHOO.widget.SWF = function (p_oElement /*:String*/, swfURL /*:String*/, p_oAttributes /*:Object*/ ) {
139 this._queue = this._queue || [];
140 this._events = this._events || {};
141 this._configs = this._configs || {};
144 * The DOM id of this instance of the element. Automatically generated.
148 this._id = Dom.generateId(null, "yuiswf");
150 if(p_oAttributes.host) this._host = p_oAttributes.host;
153 var oElement = Dom.get(p_oElement);
154 var flashVersion = SWFDetect.parseFlashVersion((p_oAttributes["version"]) || FLASH_VER);
155 var isFlashVersionRight = SWFDetect.isFlashVersionAtLeast(flashVersion);
156 var canExpressInstall = (UA.flash >= 8.0);
157 var shouldExpressInstall = canExpressInstall && !isFlashVersionRight && p_oAttributes["useExpressInstall"];
158 var flashURL = (shouldExpressInstall)?EXPRESS_INSTALL_URL:swfURL;
159 var objstring = '<object ';
161 var flashvarstring = "YUISwfId=" + _id + "&YUIBridgeCallback=" + EVENT_HANDLER;
163 YAHOO.widget.SWF._instances[_id] = this;
165 if (oElement && (isFlashVersionRight || shouldExpressInstall) && flashURL) {
166 objstring += 'id="' + _id + '" ';
168 objstring += 'classid="' + FLASH_CID + '" '
171 objstring += 'type="' + FLASH_TYPE + '" data="' + YAHOO.lang.escapeHTML(flashURL) + '" ';
177 objstring += 'width="' + w + '" height="' + h + '">';
180 objstring += '<param name="movie" value="' + YAHOO.lang.escapeHTML(flashURL) + '"/>';
183 for (var attribute in p_oAttributes.fixedAttributes) {
184 if (possibleAttributes.hasOwnProperty(attribute.toLowerCase())) {
185 objstring += '<param name="' + YAHOO.lang.escapeHTML(attribute.toLowerCase()) + '" value="' + YAHOO.lang.escapeHTML(p_oAttributes.fixedAttributes[attribute]) + '"/>';
189 for (var flashvar in p_oAttributes.flashVars) {
190 var fvar = p_oAttributes.flashVars[flashvar];
191 if (Lang.isString(fvar)) {
192 flashvarstring += "&" + YAHOO.lang.escapeHTML(flashvar) + "=" + YAHOO.lang.escapeHTML(encodeURIComponent(fvar));
196 if (flashvarstring) {
197 objstring += '<param name="flashVars" value="' + flashvarstring + '"/>';
200 objstring += "</object>";
202 oElement.innerHTML = objstring;
203 YAHOO.widget.SWF.superclass.constructor.call(this, Dom.get(_id));
204 this._swf = Dom.get(_id);
209 * The static collection of all instances of the SWFs on the page.
210 * @property _instances
215 YAHOO.widget.SWF._instances = YAHOO.widget.SWF._instances || {};
218 * Handles an event coming from within the SWF and delegate it
219 * to a specific instance of SWF.
220 * @method eventHandler
221 * @param swfid {String} the id of the SWF dispatching the event
222 * @param event {Object} the event being transmitted.
225 YAHOO.widget.SWF.eventHandler = function (swfid, event) {
226 YAHOO.widget.SWF._instances[swfid]._eventHandler(event);
229 YAHOO.extend(YAHOO.widget.SWF, YAHOO.util.Element, {
230 _eventHandler: function(event)
232 if (event.type == "swfReady")
234 this.createEvent("swfReady", {fireOnce:true});
235 this.fireEvent("swfReady", event);
237 else if(event.type == "log")
242 if(this._host && this._host.fireEvent)
244 this._host.fireEvent(event.type, event);
248 this.fireEvent(event.type, event);
254 * Calls a specific function exposed by the SWF's
257 * @param func {String} the name of the function to call
258 * @param args {Object} the set of arguments to pass to the function.
260 callSWF: function (func, args)
266 if (this._swf[func]) {
267 return(this._swf[func].apply(this._swf, args));
274 * Public accessor to the unique name of the SWF instance.
277 * @return {String} Unique name of the SWF instance.
281 return "SWF " + this._id;
287 YAHOO.register("swf", YAHOO.widget.SWF, {version: "2.9.0", build: "2800"});