]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/javascript/yui/build/swfstore/swf.js
Release 6.2.1
[Github/sugarcrm.git] / include / javascript / yui / build / swfstore / swf.js
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
9 (function () {
10         
11         var version = 0;
12         var UA = YAHOO.env.ua;
13         var sF = "ShockwaveFlash";
14
15                 if (UA.gecko || UA.webkit || UA.opera) {
16                            if ((mF = navigator.mimeTypes['application/x-shockwave-flash'])) {
17                               if ((eP = mF.enabledPlugin)) {
18                                          var vS = [];
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)
22                                         {
23                                                 case 1:
24                                                 version += "00";
25                                                 break;
26                                                 case 2: 
27                                                 version += "0";
28                                                 break;
29                                         }
30                                         version +=  vS[2];
31                                         version = parseFloat(version);
32                               }
33                            }
34                         }
35                         else if(UA.ie) {
36                             try
37                             {
38                                 var ax6 = new ActiveXObject(sF + "." + sF + ".6");
39                                 ax6.AllowScriptAccess = "always";
40                             }
41                             catch(e)
42                             {
43                                 if(ax6 != null)
44                                 {
45                                     version = 6.0;
46                                 }
47                             }
48                             if (version == 0) {
49                             try
50                             {
51                                 var ax  = new ActiveXObject(sF + "." + sF);
52                                 var vS = [];
53                                 vS = ax.GetVariable("$version").replace(/[A-Za-z\s]+/g, '').split(',');
54                                 version = vS[0] + '.';
55                                         switch((vS[2].toString()).length)
56                                         {
57                                                 case 1:
58                                                 version += "00";
59                                                 break;
60                                                 case 2: 
61                                                 version += "0";
62                                                 break;
63                                         }
64                                         version +=  vS[2];
65                                         version = parseFloat(version);
66
67                             } catch (e) {}
68                             }
69                         }
70
71                         UA.flash = version;
72
73         YAHOO.util.SWFDetect = {                
74                         getFlashVersion : function () {
75                                 return version;
76                         },
77
78                         isFlashVersionAtLeast : function (ver) {
79                                 return version >= ver;
80                         }       
81                 };      
82         
83         var Dom = YAHOO.util.Dom,
84         Event = YAHOO.util.Event,
85         SWFDetect = YAHOO.util.SWFDetect,
86         Lang = YAHOO.lang,
87
88                 // private
89                 FLASH_CID = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000",
90                 FLASH_TYPE = "application/x-shockwave-flash",
91                 FLASH_VER = "10.22",
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:""};
95                 
96                 /**
97                  * The SWF utility is a tool for embedding Flash applications in HTMl pages.
98                  * @module swf
99                  * @title SWF Utility
100                  * @requires yahoo, dom, event
101                  * @namespace YAHOO.widget
102                  */
103
104                 /**
105                  * Creates the SWF instance and keeps the configuration data
106                  *
107                  * @class SWF
108                  * @extends YAHOO.util.Element
109                  * @constructor
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.
115                  */
116                                 
117 YAHOO.widget.SWF = function (p_oElement /*:String*/, swfURL /*:String*/, p_oAttributes /*:Object*/ ) {
118         
119         this._queue = this._queue || [];
120         this._events = this._events || {};
121         this._configs = this._configs || {};
122         
123         /**
124      * The DOM id of this instance of the element. Automatically generated.
125      * @property _id
126      * @type String
127      */
128         this._id = Dom.generateId(null, "yuiswf");
129         
130         var _id = this._id;
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 ';
138         var w, h;
139         var flashvarstring = "YUISwfId=" + _id + "&YUIBridgeCallback=" + EVENT_HANDLER + "&";
140         
141         YAHOO.widget.SWF._instances[_id] = this;
142
143     if (oElement && (isFlashVersionRight || shouldExpressInstall) && flashURL) {
144                                 objstring += 'id="' + _id + '" '; 
145                                 if (UA.ie) {
146                                         objstring += 'classid="' + FLASH_CID + '" '
147                                 }
148                                 else {
149                                         objstring += 'type="' + FLASH_TYPE + '" data="' + flashURL + '" ';
150                                 }
151                                 
152                 w = "100%";
153                                 h = "100%";
154                                 
155                                 objstring += 'width="' + w + '" height="' + h + '">';
156                                 
157                                 if (UA.ie) {
158                                         objstring += '<param name="movie" value="' + flashURL + '"/>';
159                                 }
160                                 
161                                 for (var attribute in p_oAttributes.fixedAttributes) {
162                                         if (possibleAttributes.hasOwnProperty(attribute)) {
163                                                 objstring += '<param name="' + attribute + '" value="' + p_oAttributes.fixedAttributes[attribute] + '"/>';
164                                         }
165                                 }
166
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);
171                                         }
172                                 }
173                                 
174                                 if (flashvarstring) {
175                                         objstring += '<param name="flashVars" value="' + flashvarstring + '"/>';
176                                 }
177                                 
178                                 objstring += "</object>"; 
179
180                                 oElement.innerHTML = objstring;
181                         }
182                         
183                         YAHOO.widget.SWF.superclass.constructor.call(this, Dom.get(_id));
184                         this._swf = Dom.get(_id);       
185 };
186
187 /**
188  * The static collection of all instances of the SWFs on the page.
189  * @property _instances
190  * @private
191  * @type Object
192  */
193
194 YAHOO.widget.SWF._instances = YAHOO.widget.SWF._instances || {};
195
196 /**
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.
202  * @private
203  */
204 YAHOO.widget.SWF.eventHandler = function (swfid, event) {
205         YAHOO.widget.SWF._instances[swfid]._eventHandler(event);
206 };
207
208 YAHOO.extend(YAHOO.widget.SWF, YAHOO.util.Element, {
209         _eventHandler: function(event)
210         {
211                 if (event.type == "swfReady") {
212                         this.createEvent("swfReady");
213                 this.fireEvent("swfReady", event);
214         }
215         else {
216                 this.fireEvent(event.type, event);
217         } 
218         },      
219         /**
220          * Calls a specific function exposed by the SWF's
221          * ExternalInterface.
222          * @method callSWF
223          * @param func {String} the name of the function to call
224          * @param args {Object} the set of arguments to pass to the function.
225          */
226         callSWF: function (func, args)
227         {
228                 if (this._swf[func]) {
229                 return(this._swf[func].apply(this._swf, args));
230             } else {
231                 return null;
232             }
233         }
234 });
235
236         
237 })();
238 YAHOO.register("swf", YAHOO.widget.SWF, {version: "2.8.0r4", build: "2449"});