added Browser.version to the docs
[mootools/dkf.git] / Source / Utilities / Swiff.js
blob50c3b9f2b36c3418cc86daa2cd261bbce74da522
1 /*
2 ---
4 name: Swiff
6 description: Wrapper for embedding SWF movies. Supports External Interface Communication.
8 license: MIT-style license.
10 credits:
11   - Flash detection & Internet Explorer + Flash Player 9 fix inspired by SWFObject.
13 requires: [Options, Object, Element]
15 provides: Swiff
17 ...
20 (function(){
22 var Swiff = this.Swiff = new Class({
24         Implements: Options,
26         options: {
27                 id: null,
28                 height: 1,
29                 width: 1,
30                 container: null,
31                 properties: {},
32                 params: {
33                         quality: 'high',
34                         allowScriptAccess: 'always',
35                         wMode: 'window',
36                         swLiveConnect: true
37                 },
38                 callBacks: {},
39                 vars: {}
40         },
42         toElement: function(){
43                 return this.object;
44         },
46         initialize: function(path, options){
47                 this.instance = 'Swiff_' + String.uniqueID();
49                 this.setOptions(options);
50                 options = this.options;
51                 var id = this.id = options.id || this.instance;
52                 var container = document.id(options.container);
54                 Swiff.CallBacks[this.instance] = {};
56                 var params = options.params, vars = options.vars, callBacks = options.callBacks;
57                 var properties = Object.append({height: options.height, width: options.width}, options.properties);
59                 var self = this;
61                 for (var callBack in callBacks){
62                         Swiff.CallBacks[this.instance][callBack] = (function(option){
63                                 return function(){
64                                         return option.apply(self.object, arguments);
65                                 };
66                         })(callBacks[callBack]);
67                         vars[callBack] = 'Swiff.CallBacks.' + this.instance + '.' + callBack;
68                 }
70                 params.flashVars = Object.toQueryString(vars);
71                 if (Browser.ie){
72                         properties.classid = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
73                         params.movie = path;
74                 } else {
75                         properties.type = 'application/x-shockwave-flash';
76                 }
77                 properties.data = path;
79                 var build = '<object id="' + id + '"';
80                 for (var property in properties) build += ' ' + property + '="' + properties[property] + '"';
81                 build += '>';
82                 for (var param in params){
83                         if (params[param]) build += '<param name="' + param + '" value="' + params[param] + '" />';
84                 }
85                 build += '</object>';
86                 this.object = ((container) ? container.empty() : new Element('div')).set('html', build).firstChild;
87         },
89         replaces: function(element){
90                 element = document.id(element, true);
91                 element.parentNode.replaceChild(this.toElement(), element);
92                 return this;
93         },
95         inject: function(element){
96                 document.id(element, true).appendChild(this.toElement());
97                 return this;
98         },
100         remote: function(){
101                 return Swiff.remote.apply(Swiff, [this.toElement()].append(arguments));
102         }
106 Swiff.CallBacks = {};
108 Swiff.remote = function(obj, fn){
109         var rs = obj.CallFunction('<invoke name="' + fn + '" returntype="javascript">' + __flash__argumentsToXML(arguments, 2) + '</invoke>');
110         return eval(rs);
113 })();