-
Notifications
You must be signed in to change notification settings - Fork 2
/
module.js
executable file
·219 lines (205 loc) · 6.54 KB
/
module.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
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
/**
* @file Javascript file to handle the audio/video recording
* of the mediacapture plugin
*/
M.repository_mediacapture = {};
M.repository_mediacapture.init = function(Y) {
Y.one('*[name="browserplugins"]').set('value', JSON.stringify(BrowserPlugins));
Y.one('*[name="browserdetect"]').set('value', JSON.stringify(BrowserDetect));
var audio = Y.one("#id_recordaudio"),
video = Y.one("#id_recordvideo");
if (audio) {
audio.on("click", function (e) {
Y.one('*[name="type"]').set('value', 'audio');
Y.one('#mform1').submit();
});
}
if (video) {
video.on("click", function (e) {
Y.one('*[name="type"]').set('value', 'video');
Y.one('#mform1').submit();
});
}
}
/*
* Returns an object with found plugins and their versions
* BrowserPlugins['java'] returns version of JRE
* BrowserPlugins['quicktime'] returns version of Apple QT player
* BrowserPlugins['flash'] returns Adobe Flash player version
*/
var BrowserPlugins = (function(){
var found = {};
var version_reg = /[0-9]+.[0-9]+/;
/*
* Differentiate between IE (detection via ActiveXObject)
* and the rest (detection via navigator.plugins)
*/
if (window.ActiveXObject) {
var plugin_list = {
flash: 'ShockwaveFlash.ShockwaveFlash.1',
quicktime: 'QuickTime.QuickTime'
}
for (var plugin in plugin_list){
var version = msieDetect(plugin_list[plugin]);
if (version){
var version_reg_val = version_reg.exec(version);
found[plugin] = (version_reg_val && version_reg_val[0]) || '';
}
}
if (navigator.javaEnabled()){
found['java'] = '';
}
} else {
var plugins = navigator.plugins;
var reg = /Flash|Java|QuickTime/;
for (var i = 0; i < plugins.length; i++) {
var reg_val = reg.exec(plugins[i].description);
if (reg_val){
var plugin = reg_val[0].toLowerCase();
/*
* Search in version property, if not available concat name and description
* and search for a version number in there
*/
var version = plugins[i].version ||
(plugins[i].name + ' ' + plugins[i].description);
var version_reg_val = version_reg.exec(version);
if (!found[plugin]) {
found[plugin] = (version_reg_val && version_reg_val[0]) || '';
}
}
}
}
return found;
/*
* Return version number if plugin installed
* Return true if plugin is installed but no version number found
* Return false if plugin not found
*/
function msieDetect(name){
try {
var active_x_obj = new ActiveXObject(name);
try {
return active_x_obj.GetVariable('$version');
} catch(e) {
try {
return active_x_obj.GetVersions();
} catch (e) {
try {
var version;
for (var i = 1; i < 9; i++) {
if (active_x_obj.isVersionSupported(i + '.0')){
version = i;
}
}
return version || true;
} catch (e) {
return true;
}
}
}
} catch(e){
return false;
}
}
})();
/*
* Returns an object with the browser name, version and OS details
* BrowserDetect.browser returns browser name
* BrowserDetect.version returns browser version
* BrowserDetect.OS returns Operating System, Win, Mac, Linux
*/
var BrowserDetect = {
init: function () {
this.browser = this.searchString(this.dataBrowser) || "an unknown browser";
this.version = this.searchVersion(navigator.userAgent)
|| this.searchVersion(navigator.appVersion)
|| "an unknown version";
this.OS = this.searchString(this.dataOS) || "an unknown OS";
},
searchString: function (data) {
for(var i = 0; i < data.length; i++) {
var dataString = data[i].string;
var dataProp = data[i].prop;
this.versionSearchString = data[i].versionSearch || data[i].identity;
if (dataString) {
if (dataString.indexOf(data[i].subString) != -1) {
return data[i].identity;
}
}
else if (dataProp) {
return data[i].identity;
}
}
},
searchVersion: function (dataString) {
var index = dataString.indexOf(this.versionSearchString);
if (index == -1) {
return;
}
return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
},
dataBrowser: [
{
string: navigator.userAgent,
subString: "Chrome",
identity: "Chrome"
},
{
string: navigator.vendor,
subString: "Apple",
identity: "Safari",
versionSearch: "Version"
},
{
prop: window.opera,
identity: "Opera",
versionSearch: "Version"
},
{
string: navigator.userAgent,
subString: "Firefox",
identity: "Firefox"
},
{
string: navigator.userAgent,
subString: "MSIE",
identity: "Explorer",
versionSearch: "MSIE"
},
{
string: navigator.userAgent,
subString: "Gecko",
identity: "Mozilla",
versionSearch: "rv"
},
{ // for older Netscapes (4-)
string: navigator.userAgent,
subString: "Mozilla",
identity: "Netscape",
versionSearch: "Mozilla"
}
],
dataOS : [
{
string: navigator.platform,
subString: "Win",
identity: "Windows"
},
{
string: navigator.platform,
subString: "Mac",
identity: "Mac"
},
{
string: navigator.userAgent,
subString: "iPhone",
identity: "iPhone/iPod"
},
{
string: navigator.platform,
subString: "Linux",
identity: "Linux"
}
]
};
BrowserDetect.init();