Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

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