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