-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswf.js
More file actions
224 lines (191 loc) · 7.04 KB
/
swf.js
File metadata and controls
224 lines (191 loc) · 7.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/**
@Name: sb.swf
@Description: A constructor used to embed macromedia flash swf, youtube videos, etc. Do not set the sb.swf object's id property to the same name as the object itself. e.g. if your swf object = var mySwf do not set it's id property to 'mySwf' as Internet Explorer will throw an error.
@Param: Object params An objectw ith all the properties of the swf should have once embedded
src - the url of the flash swf to be loaded
width - The width that the swf file is displayed at
height - The height that the swf file is displayed at
bgColor - The backgroudn color fo the swf file
version - The minimum version of flash required to display the swf, else the instances alt property data is returned when running the instances toHTML() or embed() method
alt - Alternative data to be displayed if the user does not have the minimum version of flash required. This can be HTML or string data.
id - the id of the new node returned
flashvars - an object whose properties are converted to key/value pairs and passed to the swf objects FlashVars property
@Return: Object An sb.swf instance with the properties specifed in the param argument and by sb.swf.prototype
@Example:
var mySwf = new sb.swf({
src : 'surebert.swf',
bgColor : '#000000',
wmode : 'transparent',
width : 400,
height : 300,
version : 8,
id : 'swify',
flashvars : {
name : 'paul',
age : 30
},
alt : '<div>You need at least flashplayer 8 to play the swf</div>'
});
*/
sb.swf = function(params){
if(typeof params == 'object'){
sb.objects.infuse(params, this);
}
this.width = this.width || '400px';
this.height = this.height || '300px';
this.bgColor = this.bgColor || '#FFFFFF';
this.version = this.version || 5;
this.allowFullScreen = this.allowFullScreen || 'true';
this.alt = this.alt || '';
this.src = this.src || '';
this.wmode = this.wmode || '';
if(typeof this.id =='undefined'){
this.id = 'sb_swf_'+sb.swf.instanceId;
sb.swf.instanceId++;
}
};
/**
@Name: sb.swf.prototype
@Description: The properties of any sb.swf instance. All sb.swf.prototype examples below assume the following sb.swf example object was created
@Example:
var mySwf = new sb.swf({
src : 'surebert.swf',
bgColor : '#000000',
wmode : 'transparent',
width : 400,
height : 300,
version : 8,
id : 'swify',
alt : '<div>You need at least flashplayer 8 to play the swf</div>'
});
*/
sb.swf.prototype = {
getInterface : function(){
var movieName = this.id;
if (navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName];
} else {
return document.getElementById(movieName);
}
},
/**
@Name: sb.swf.prototype.toHTML
@Description: Converts the sb.swf into the appropriate swf code for the browser being used by the client
@Return: String The HTML code required to embed the flash swf into the DOM, can be used as the innerHTML of another element
@Example:
var string = mySwf.toHTML();
//on embed style browsers returns
<embed type="application/x-shockwave-flash" src="mySwf.swf" id="mySwf" wmode="transparent" allowScriptAccess="always" bgcolor="#000000" width="400" height="300" />
//on explorer returns
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="300" id="mySwf"><param name="movie" value="mySwf.swf" /><param name="bgcolor" value="#000000" /><param name="wmode" value="transparent" /><param name="allowScriptAccess" value="always" /></object>
*/
toHTML : function(){
var html='';
if(this.version > sb.swf.version){
return this.alt;
}
if(sb.swf.format=='embed'){
html = '<embed type="application/x-shockwave-flash" src="'+this.src+'" id="'+this.id+'" name="'+this.id+'" wmode="'+this.wmode+'" allowScriptAccess="always" allowFullScreen="'+this.allowFullScreen+'" bgcolor="'+this.bgColor+'" ';
if(typeof this.flashvars =='object'){
html +='FlashVars="'+sb.objects.serialize(this.flashvars)+'" ';
}
html +=' width="'+this.width+'" height="'+this.height+'" />';
} else if(sb.swf.format=='object'){
html = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="'+this.width+'" height="'+this.height+'" id="'+this.id+'" ><param name="movie" value="'+this.src+'" /><param name="bgcolor" value="'+this.bgColor+'" /><param name="wmode" value="'+this.wmode+'" /><param name="allowFullScreen" value="'+this.allowFullScreen+'" /><param name="allowScriptAccess" value="always" />';
if(typeof this.flashvars =='object'){
html +='<param name="FlashVars" value="'+sb.objects.serialize(this.flashvars)+'">';
}
html +='</object>';
}
return html;
},
/**
@Name: sb.swf.prototype.embed
@Description: Converts the sb.swf into the appropriate swf code for the browser being used by the client and inserts that code into the element specified
@Param: element el Either an object reference to a dom element or a string reference that can be passed through sb.$ e.g. use the elements id '#someElement'
@Return: String The HTML code required to embed the flash swf into the DOM, can be used as the innerHTML of another element
@Example:
mySwf.embed('#someElement');
*/
embed : function(el){
el = sb.$(el);
el.innerHTML = this.toHTML();
return el;
}
};
sb.swf.infuse = sb.objects.infuse;
sb.swf.infuse({
/**
@Name: sb.swf.version
@Description: Integer The major version number
*/
version : 0,
/**
@Name: sb.swf.fullVersion
@Description: String The full version with revision numbers comma delimited
*/
fullVersion : '0,0,0',
/**
@Name: sb.swf.swfs
@Description: Used Internally
*/
swfs : [],
/**
@Name: sb.swf.instanceId
@Description: Used Internally
*/
instanceId : 0,
/**
@Name: sb.swf.cleanup
@Description: Used Internally
*/
cleanup : function() {
try{
sb.$('object').forEach(function(obj){
obj.style.display='none';
for(var prop in obj){
if(typeof obj == 'function'){obj[prop] = function(){};}
}
});
}catch(e){}
},
/**
@Name: sb.swf.unload
@Description: Used Internally
*/
unload : function() {
__flash_unloadHandler = function(){};
__flash_savedUnloadHandler = function(){};
window.attachEvent( "onunload", sb.swf.cleanup );
},
/**
@Name: sb.swf.detect
@Description: Used Internally
*/
detect : function(){
this.fullVersion = '0,0,0';
try {
if(navigator && navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]){
if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){
this.fullVersion = (navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1];
}
this.format = 'embed';
} else {
this.fullVersion = new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
this.format = 'object';
}
} catch(e) {}
this.version = this.fullVersion.split(',')[0];
}
});
sb.swf.detect();
if(sb.browser.ie6){
//fix for bad adobe code in IE
var __flash__removeCallback = function(instance, name){
if(typeof instance != 'null'){
instance[name] = null;
}
};
//cleanup flash players for IE
window.attachEvent( "onbeforeunload", sb.swf.unload);
}