]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/javascript/yui/build/swf/swf-debug.js
Release 6.2.1
[Github/sugarcrm.git] / include / javascript / yui / build / swf / swf-debug.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         if(p_oAttributes.host) this._host = p_oAttributes.host;
131         
132         var _id = this._id;
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 ';
140         var w, h;
141         var flashvarstring = "YUISwfId=" + _id + "&YUIBridgeCallback=" + EVENT_HANDLER;
142         
143         YAHOO.widget.SWF._instances[_id] = this;
144
145     if (oElement && (isFlashVersionRight || shouldExpressInstall) && flashURL) {
146                                 objstring += 'id="' + _id + '" '; 
147                                 if (UA.ie) {
148                                         objstring += 'classid="' + FLASH_CID + '" '
149                                 }
150                                 else {
151                                         objstring += 'type="' + FLASH_TYPE + '" data="' + flashURL + '" ';
152                                 }
153                                 
154                 w = "100%";
155                                 h = "100%";
156                                 
157                                 objstring += 'width="' + w + '" height="' + h + '">';
158                                 
159                                 if (UA.ie) {
160                                         objstring += '<param name="movie" value="' + flashURL + '"/>';
161                                 }
162                                 
163                                 for (var attribute in p_oAttributes.fixedAttributes) {
164                                         if (possibleAttributes.hasOwnProperty(attribute)) {
165                                                 objstring += '<param name="' + attribute + '" value="' + p_oAttributes.fixedAttributes[attribute] + '"/>';
166                                         }
167                                 }
168
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);
173                                         }
174                                 }
175                                 
176                                 if (flashvarstring) {
177                                         objstring += '<param name="flashVars" value="' + flashvarstring + '"/>';
178                                 }
179                                 
180                                 objstring += "</object>"; 
181
182                                 oElement.innerHTML = objstring;
183                         }
184                         
185                         YAHOO.widget.SWF.superclass.constructor.call(this, Dom.get(_id));
186                         this._swf = Dom.get(_id);       
187 };
188
189 /**
190  * The static collection of all instances of the SWFs on the page.
191  * @property _instances
192  * @private
193  * @type Object
194  */
195
196 YAHOO.widget.SWF._instances = YAHOO.widget.SWF._instances || {};
197
198 /**
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.
204  * @private
205  */
206 YAHOO.widget.SWF.eventHandler = function (swfid, event) {
207         YAHOO.widget.SWF._instances[swfid]._eventHandler(event);
208 };
209
210 YAHOO.extend(YAHOO.widget.SWF, YAHOO.util.Element, {
211         _eventHandler: function(event)
212         {
213                 if (event.type == "swfReady") 
214                 {
215                         this.createEvent("swfReady", {fireOnce:true});
216                 this.fireEvent("swfReady", event);
217         }
218                 else if(event.type == "log")
219                 {
220                         YAHOO.log(event.message, event.category, this._host ? this._host.toString() : this.toString());
221                 }
222         else 
223                 {
224                 if(this._host && this._host.fireEvent) 
225                         {
226                                 this._host.fireEvent(event.type, event);
227                         }
228                         else
229                         {
230                                 this.fireEvent(event.type, event);
231                         }
232         } 
233         },
234                 
235         /**
236          * Calls a specific function exposed by the SWF's
237          * ExternalInterface.
238          * @method callSWF
239          * @param func {String} the name of the function to call
240          * @param args {Object} the set of arguments to pass to the function.
241          */
242         callSWF: function (func, args)
243         {
244                 if (!args) { 
245                           args= []; 
246                 };
247                 
248                 if (this._swf[func]) {
249                 return(this._swf[func].apply(this._swf, args));
250             } else {
251                 return null;
252             }
253         },
254         
255         /**
256          * Public accessor to the unique name of the SWF instance.
257          *
258          * @method toString
259          * @return {String} Unique name of the SWF instance.
260          */
261         toString: function()
262         {
263                 return "SWF " + this._id;
264         }
265 });
266
267         
268 })();
269 YAHOO.register("swf", YAHOO.widget.SWF, {version: "2.8.0r4", build: "2449"});