]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/javascript/yui3/build/swf/swf.js
Release 6.5.0
[Github/sugarcrm.git] / jssource / src_files / include / javascript / yui3 / build / swf / swf.js
1 /*
2 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
5 version: 3.3.0
6 build: 3167
7 */
8 YUI.add('swf', function(Y) {
9
10 /**
11  * Embed a Flash applications in a standard manner and communicate with it
12  * via External Interface.
13  * @module swf
14  */
15         
16         var Event = Y.Event,
17         SWFDetect = Y.SWFDetect,
18         Lang = Y.Lang,
19         uA = Y.UA,
20         Node = Y.Node,
21
22                 // private
23                 FLASH_CID = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000",
24                 FLASH_TYPE = "application/x-shockwave-flash",
25                 FLASH_VER = "10.0.22",
26                 EXPRESS_INSTALL_URL = "http://fpdownload.macromedia.com/pub/flashplayer/update/current/swf/autoUpdater.swf?" + Math.random(),
27                 EVENT_HANDLER = "SWF.eventHandler",
28                 possibleAttributes = {align:"", allowFullScreen:"", allowNetworking:"", allowScriptAccess:"", base:"", bgcolor:"", menu:"", name:"", quality:"", salign:"", scale:"", tabindex:"", wmode:""};
29                 
30                 /**
31                  * The SWF utility is a tool for embedding Flash applications in HTML pages.
32                  * @module swf
33                  * @title SWF Utility
34                  * @requires event-custom, node, swfdetect
35                  */
36
37                 /**
38                  * Creates the SWF instance and keeps the configuration data
39                  *
40                  * @class SWF
41                  * @augments Y.Event.Target
42                  * @constructor
43                  * @param {String|HTMLElement} id The id of the element, or the element itself that the SWF will be inserted into.  
44                  *        The width and height of the SWF will be set to the width and height of this container element.
45                  * @param {String} swfURL The URL of the SWF to be embedded into the page.
46                  * @param {Object} p_oAttributes (optional) Configuration parameters for the Flash application and values for Flashvars
47                  *        to be passed to the SWF. The p_oAttributes object allows the following additional properties:
48                  *        <dl>
49          *          <dt>version : String</dt>
50          *          <dd>The minimum version of Flash required on the user's machine.</dd>
51          *          <dt>fixedAttributes : Object</dt>
52          *          <dd>An object literal containing one or more of the following String keys and their values: <code>align, 
53          *              allowFullScreen, allowNetworking, allowScriptAccess, base, bgcolor, menu, name, quality, salign, scale,
54          *              tabindex, wmode.</code> event from the thumb</dd>
55          *        </dl>
56                  */
57                                 
58 function SWF (p_oElement /*:String*/, swfURL /*:String*/, p_oAttributes /*:Object*/ ) {
59         
60         this._id = Y.guid("yuiswf");
61         
62         
63         var _id = this._id;
64     var oElement = Node.one(p_oElement);
65         
66         var flashVersion = p_oAttributes["version"] || FLASH_VER;
67     var flashVersionSplit = (flashVersion + '').split(".");
68         var isFlashVersionRight = SWFDetect.isFlashVersionAtLeast(parseInt(flashVersionSplit[0]), parseInt(flashVersionSplit[1]), parseInt(flashVersionSplit[2]));
69         var canExpressInstall = (SWFDetect.isFlashVersionAtLeast(8,0,0));
70         var shouldExpressInstall = canExpressInstall && !isFlashVersionRight && p_oAttributes["useExpressInstall"];
71         var flashURL = (shouldExpressInstall)?EXPRESS_INSTALL_URL:swfURL;
72         var objstring = '<object ';
73         var w, h;
74         var flashvarstring = "yId=" + Y.id + "&YUISwfId=" + _id + "&YUIBridgeCallback=" + EVENT_HANDLER + "&allowedDomain=" + document.location.hostname;
75         
76         Y.SWF._instances[_id] = this;
77     if (oElement && (isFlashVersionRight || shouldExpressInstall) && flashURL) {
78                                 objstring += 'id="' + _id + '" '; 
79                                 if (uA.ie) {
80                                         objstring += 'classid="' + FLASH_CID + '" ';
81                                 }
82                                 else {
83                                         objstring += 'type="' + FLASH_TYPE + '" data="' + flashURL + '" ';
84                                 }
85                                 
86                 w = "100%";
87                                 h = "100%";
88                                 
89                                 objstring += 'width="' + w + '" height="' + h + '">';
90                                 
91                                 if (uA.ie) {
92                                         objstring += '<param name="movie" value="' + flashURL + '"/>';
93                                 }
94                                 
95                                 for (var attribute in p_oAttributes.fixedAttributes) {
96                                         if (possibleAttributes.hasOwnProperty(attribute)) {
97                                                 objstring += '<param name="' + attribute + '" value="' + p_oAttributes.fixedAttributes[attribute] + '"/>';
98                                         }
99                                 }
100
101                                 for (var flashvar in p_oAttributes.flashVars) {
102                                         var fvar = p_oAttributes.flashVars[flashvar];
103                                         if (Lang.isString(fvar)) {
104                                                 flashvarstring += "&" + flashvar + "=" + encodeURIComponent(fvar);
105                                         }
106                                 }
107                                 
108                                 if (flashvarstring) {
109                                         objstring += '<param name="flashVars" value="' + flashvarstring + '"/>';
110                                 }
111                                 
112                                 objstring += "</object>"; 
113                                 oElement.setContent(objstring);
114                         
115                                 this._swf = Node.one("#" + _id);
116                         }
117         /**
118         * Fired when the Flash player version on the user's machine is below the required value.
119         *
120         * @event wrongflashversion
121     */
122         else {
123                     var event = {};
124                     event.type = "wrongflashversion";
125                         this.publish("wrongflashversion", {fireOnce:true});
126                 this.fire("wrongflashversion", event);
127                 }               
128 };
129
130 /**
131  * @private
132  * The static collection of all instances of the SWFs on the page.
133  * @property _instances
134  * @type Object
135  */
136
137 SWF._instances = SWF._instances || {};
138
139 /**
140  * @private
141  * Handles an event coming from within the SWF and delegate it
142  * to a specific instance of SWF.
143  * @method eventHandler
144  * @param swfid {String} the id of the SWF dispatching the event
145  * @param event {Object} the event being transmitted.
146  */
147 SWF.eventHandler = function (swfid, event) {
148         SWF._instances[swfid]._eventHandler(event);
149 };
150
151 SWF.prototype = 
152 {
153         /**
154          * @private
155          * Propagates a specific event from Flash to JS.
156          * @method _eventHandler
157          * @param event {Object} The event to be propagated from Flash.
158          */
159         
160         _eventHandler: function(event)
161         {
162                 if (event.type === "swfReady") 
163                 {
164                         this.publish("swfReady", {fireOnce:true});
165                 this.fire("swfReady", event);
166         }
167                 else if(event.type === "log")
168                 {
169                 }
170         else
171                 {
172                         this.fire(event.type, event);
173         } 
174         },
175                 
176         /**
177          * Calls a specific function exposed by the SWF's
178          * ExternalInterface.
179          * @method callSWF
180          * @param func {String} the name of the function to call
181          * @param args {Object} the set of arguments to pass to the function.
182          */
183         
184         callSWF: function (func, args)
185         {
186                 if (!args) { 
187                           args= []; 
188                 };      
189                 if (this._swf._node[func]) {
190                 return(this._swf._node[func].apply(this._swf._node, args));
191             } else {
192                 return null;
193             }
194         },
195         
196         /**
197          * Public accessor to the unique name of the SWF instance.
198          *
199          * @method toString
200          * @return {String} Unique name of the SWF instance.
201          */
202         toString: function()
203         {
204                 return "SWF " + this._id;
205         }
206 };
207
208 Y.augment(SWF, Y.EventTarget);
209
210 Y.SWF = SWF;
211
212
213 }, '3.3.0' );