]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/javascript/yui/build/swf/swf.js
Release 6.5.0
[Github/sugarcrm.git] / include / javascript / yui / build / swf / swf.js
1 /*
2 Copyright (c) 2011, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
5 version: 2.9.0
6 */
7 YAHOO.namespace("widget");
8
9 (function () {
10         
11         var version = 0;
12         var UA = YAHOO.env.ua;
13         var sF = "ShockwaveFlash";
14     var mF, eP;
15
16                 if (UA.gecko || UA.webkit || UA.opera) {
17                            if ((mF = navigator.mimeTypes['application/x-shockwave-flash'])) {
18                               if ((eP = mF.enabledPlugin)) {
19                                          var vS = [];
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)
23                                         {
24                                                 case 1:
25                                                 version += "00";
26                                                 break;
27                                                 case 2: 
28                                                 version += "0";
29                                                 break;
30                                         }
31                                         version +=  vS[2];
32                                         version = parseFloat(version);
33                               }
34                            }
35                         }
36                         else if(UA.ie) {
37                             try
38                             {
39                                 var ax6 = new ActiveXObject(sF + "." + sF + ".6");
40                                 ax6.AllowScriptAccess = "always";
41                             }
42                             catch(e)
43                             {
44                                 if(ax6 != null)
45                                 {
46                                     version = 6.0;
47                                 }
48                             }
49                             if (version == 0) {
50                             try
51                             {
52                                 var ax  = new ActiveXObject(sF + "." + sF);
53                                 var vS = [];
54                                 vS = ax.GetVariable("$version").replace(/[A-Za-z\s]+/g, '').split(',');
55                                 version = vS[0] + '.';
56                                         switch((vS[2].toString()).length)
57                                         {
58                                                 case 1:
59                                                 version += "00";
60                                                 break;
61                                                 case 2: 
62                                                 version += "0";
63                                                 break;
64                                         }
65                                         version +=  vS[2];
66                                         version = parseFloat(version);
67
68                             } catch (e) {}
69                             }
70                         }
71
72                         UA.flash = version;
73
74         YAHOO.util.SWFDetect = {                
75                         getFlashVersion : function () {
76                                 return version;
77                         },
78
79                         isFlashVersionAtLeast : function (ver) {
80                                 return version >= ver;
81                         },
82                                         
83             parseFlashVersion : function (ver)          
84                      {  
85                         var flashVersion = ver;         
86                         if(YAHOO.lang.isString(ver))            
87                         {       
88                           var verSplit = ver.split(".");        
89                           if(verSplit.length > 2)       
90                           {     
91                             flashVersion = parseInt(verSplit[0]);               
92                             flashVersion += parseInt(verSplit[2]) * .001;       
93                           }     
94                           else  
95                           {
96                             flashVersion = parseFloat(ver);     
97                           }          
98                         }
99                         return YAHOO.lang.isNumber(flashVersion) ? flashVersion : null;
100                        }                
101                         };      
102         
103         var Dom = YAHOO.util.Dom,
104         Event = YAHOO.util.Event,
105         SWFDetect = YAHOO.util.SWFDetect,
106         Lang = YAHOO.lang,
107
108                 // private
109                 FLASH_CID = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000",
110                 FLASH_TYPE = "application/x-shockwave-flash",
111                 FLASH_VER = "10.22",
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:""};
115                 
116                 /**
117                  * The SWF utility is a tool for embedding Flash applications in HTMl pages.
118                  * @module swf
119                  * @title SWF Utility
120                  * @requires yahoo, dom, event
121                  * @namespace YAHOO.widget
122                  */
123
124                 /**
125                  * Creates the SWF instance and keeps the configuration data
126                  *
127                  * @class SWF
128                  * @extends YAHOO.util.Element
129                  * @constructor
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.
135                  */
136                                 
137 YAHOO.widget.SWF = function (p_oElement /*:String*/, swfURL /*:String*/, p_oAttributes /*:Object*/ ) {
138         
139         this._queue = this._queue || [];
140         this._events = this._events || {};
141         this._configs = this._configs || {};
142         
143         /**
144      * The DOM id of this instance of the element. Automatically generated.
145      * @property _id
146      * @type String
147      */
148         this._id = Dom.generateId(null, "yuiswf");
149         
150         if(p_oAttributes.host) this._host = p_oAttributes.host;
151         
152         var _id = this._id;
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 ';
160         var w, h;
161         var flashvarstring = "YUISwfId=" + _id + "&YUIBridgeCallback=" + EVENT_HANDLER;
162         
163         YAHOO.widget.SWF._instances[_id] = this;
164
165     if (oElement && (isFlashVersionRight || shouldExpressInstall) && flashURL) {
166                                 objstring += 'id="' + _id + '" '; 
167                                 if (UA.ie) {
168                                         objstring += 'classid="' + FLASH_CID + '" '
169                                 }
170                                 else {
171                                         objstring += 'type="' + FLASH_TYPE + '" data="' + YAHOO.lang.escapeHTML(flashURL) + '" ';
172                                 }
173                                 
174                 w = "100%";
175                                 h = "100%";
176                                 
177                                 objstring += 'width="' + w + '" height="' + h + '">';
178                                 
179                                 if (UA.ie) {
180                                         objstring += '<param name="movie" value="' + YAHOO.lang.escapeHTML(flashURL) + '"/>';
181                                 }
182                                 
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]) + '"/>';
186                                         }
187                                 }
188
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));
193                                         }
194                                 }
195                                 
196                                 if (flashvarstring) {
197                                         objstring += '<param name="flashVars" value="' + flashvarstring + '"/>';
198                                 }
199                                 
200                                 objstring += "</object>"; 
201
202                                 oElement.innerHTML = objstring;
203                                 YAHOO.widget.SWF.superclass.constructor.call(this, Dom.get(_id));
204                                 this._swf = Dom.get(_id);
205                         }
206 };
207
208 /**
209  * The static collection of all instances of the SWFs on the page.
210  * @property _instances
211  * @private
212  * @type Object
213  */
214
215 YAHOO.widget.SWF._instances = YAHOO.widget.SWF._instances || {};
216
217 /**
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.
223  * @private
224  */
225 YAHOO.widget.SWF.eventHandler = function (swfid, event) {
226         YAHOO.widget.SWF._instances[swfid]._eventHandler(event);
227 };
228
229 YAHOO.extend(YAHOO.widget.SWF, YAHOO.util.Element, {
230         _eventHandler: function(event)
231         {
232                 if (event.type == "swfReady") 
233                 {
234                         this.createEvent("swfReady", {fireOnce:true});
235                 this.fireEvent("swfReady", event);
236         }
237                 else if(event.type == "log")
238                 {
239                 }
240         else 
241                 {
242                 if(this._host && this._host.fireEvent) 
243                         {
244                                 this._host.fireEvent(event.type, event);
245                         }
246                         else
247                         {
248                                 this.fireEvent(event.type, event);
249                         }
250         } 
251         },
252                 
253         /**
254          * Calls a specific function exposed by the SWF's
255          * ExternalInterface.
256          * @method callSWF
257          * @param func {String} the name of the function to call
258          * @param args {Object} the set of arguments to pass to the function.
259          */
260         callSWF: function (func, args)
261         {
262                 if (!args) { 
263                           args= []; 
264                 };
265                 
266                 if (this._swf[func]) {
267                 return(this._swf[func].apply(this._swf, args));
268             } else {
269                 return null;
270             }
271         },
272         
273         /**
274          * Public accessor to the unique name of the SWF instance.
275          *
276          * @method toString
277          * @return {String} Unique name of the SWF instance.
278          */
279         toString: function()
280         {
281                 return "SWF " + this._id;
282         }
283 });
284
285         
286 })();
287 YAHOO.register("swf", YAHOO.widget.SWF, {version: "2.9.0", build: "2800"});