-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjwee-flash.js
192 lines (172 loc) · 5.61 KB
/
jwee-flash.js
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
//////////////////////////////////////////////////////////////////////////
// JWee JavaScript Framework & Toolkit
// Copyright (c) 2010 AUTHORS ([email protected])
// Licensed under the MIT and GPL (for now).
// http://www.jwee.org
//////////////////////////////////////////////////////////////////////////
// Flash
//////////////////////////////////////////////////////////////////////////
/*
@@namespace wee.flash
@@function getVersion
@desc Get the users's version of macromedia flash
@returns (float) complete numeric flash version
@@function add ( element/id, object args )
@desc Create the flash content easily. This function will auto-delay itself if called before page is loaded.
@arg The element or id of the container to put the flash.
@arg A object containing the parameters for the flash movie.
@@class Movie ( mixed )
@desc Display flash content easily, like SWFObject.
@@namespace wee.flash.Movie
@@method create ( [element where] )
@desc Create the flash <embed> or <object> element.
@arg (optional) Element or Element ID where to place flash content.
@returns The DOM flash embed element
@@method toString
@desc Generate the raw <embed> or <object> HTML code for your flash.
@returns The <embed> or <object> HTML.
*/
//////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////
var Flash = jwee.flash = {};
(function() {
var activex = window.ActiveXObject ? true : false;
Flash.Movie = Class.create( "Flash.Movie", (function() {
var
objectAttribs = ['id','name','classid', 'codeBase','width','height','type','src'],
param = function(n,v) { var el = document.createElement('param'); el.setAttribute('name',n); el.setAttribute('value',v); return el; };
return {
construct:
function(args) {
var t = typeof args, name;
Object.extend(this, Flash.Movie.DefaultAttributes);
if( t == 'object' ) {
for( var k in args ) {
if( k in this ) this[k] = args[k];
}
} else if( t == 'string' ) this.movie = args;
name = this.id ? this.id : this.name;
name = name ? name : jwee.getUniqueId('swf');
this.id = this.name = name;
},
properties: function() { return Object.keys(Flash.Movie.DefaultAttributes); },
prepare: function() {
if( this.movie && !this.src ) this.src = this.movie;
else if( this.src && !this.movie ) this.movie = this.src;
},
create: function(where) {
var me = this, ele, attribs = {};
this.prepare();
if( activex ) {
objectAttribs.each( function(k) { attribs[k] = me[k]; } );
ele = Elem.create('object',attribs);
this.properties().filter(objectAttribs).each( function(k) { if( me[k] !== null ) ele.appendChild( param(k,me[k]) ); });
} else {
this.properties().each( function(k) {attribs[k] = me[k] });
ele = Elem.create('embed',attribs);
}
if( where ) {
wee(where).truncate();
wee(where).appendChild(ele);
};
return ele;
},
toString: function() {
var str1 = [], me = this;
this.prepare();
if( activex ) {
str1.push('<object');
objectAttribs.each( function(k) { str1.push(k+'="' + me[k] + '"'); });
str1.push('>');
str1 = [str1.join(" ")];
this.properties().filter(objectAttribs).each( function(k) {
str1.push('<param name="' + k + '" value="' + me[k] + '" />');
});
str1.push('</object>');
} else {
str1.push('<embed');
this.properties().each( function(k) { str1.push(' ' + k+'="' + me[k] + '"'); });
str1.push('></embed>');
}
return str1.join("");
}
};
})());
Flash.Movie.DefaultAttributes = {
id: null,
name: null,
codeBase: "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0",
classid: "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",
type: "application/x-shockwave-flash",
width: "100",
height: "100",
movie: null,
src:null,
wmode: "transparent",
quality: "auto",
salign: "LT",
menu: "0",
scale: "ShowAll",
allowscriptaccess: "always",
allownetworking: "all",
allowfullscreen: "true"
};
Flash.add = function(where, args) {
if( document.loaded ) {
new Flash.Movie(args).create( wee(where) );
} else {
Event.onReady( function() { Flash.add(where, args); } );
}
};
Flash.getVersion = function() {
var version = 0, ax = null;
if( window.ActiveXObject ) {
try {
ax = new ActiveXObject("ShockwaveFlash" + "." + "ShockwaveFlash" + ".6");
ax.AllowScriptAccess = "always";
} catch(e) {
if(ax !== null) version = 6.0;
}
if( version === 0) {
try {
ax = new ActiveXObject("ShockwaveFlash" + "." + "ShockwaveFlash");
var vS = ax.GetVariable("$version").replace(/[A-Za-z\s]+/g, '').split(',');
version = vS[0] + '.';
switch((vS[2].toString()).length) {
case 1:
version += "00";
break;
case 2:
version += "0";
break;
}
version += vS[2];
version = parseFloat(version);
} catch (e) { }
}
} else {
var mF = navigator.mimeTypes['application/x-shockwave-flash'];
if ( mF ) {
eP = mF.enabledPlugin;
if (eP) {
var vS = eP.description.replace(/\s[rd]/g, '.').replace(/[A-Za-z\s]+/g, '').split('.');
version = vS[0] + '.';
switch((vS[2].toString()).length) {
case 1:
version += "00";
break;
case 2:
version += "0";
break;
}
version += vS[2];
version = parseFloat(version);
}
}
}
Flash.version = version;
return version;
}
//////////////////////////////////////////////////
})();
///////////////////////////////////////////////////