comparison johndyer-mediaelement-13fa20a/src/js/me-plugindetector.js @ 0:032bc65ebafc

added core components
author George Fazekas <gyorgy.fazekas@eecs.qmul.ac.uk>
date Wed, 06 Mar 2013 15:45:48 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:032bc65ebafc
1
2 // Core detector, plugins are added below
3 mejs.PluginDetector = {
4
5 // main public function to test a plug version number PluginDetector.hasPluginVersion('flash',[9,0,125]);
6 hasPluginVersion: function(plugin, v) {
7 var pv = this.plugins[plugin];
8 v[1] = v[1] || 0;
9 v[2] = v[2] || 0;
10 return (pv[0] > v[0] || (pv[0] == v[0] && pv[1] > v[1]) || (pv[0] == v[0] && pv[1] == v[1] && pv[2] >= v[2])) ? true : false;
11 },
12
13 // cached values
14 nav: window.navigator,
15 ua: window.navigator.userAgent.toLowerCase(),
16
17 // stored version numbers
18 plugins: [],
19
20 // runs detectPlugin() and stores the version number
21 addPlugin: function(p, pluginName, mimeType, activeX, axDetect) {
22 this.plugins[p] = this.detectPlugin(pluginName, mimeType, activeX, axDetect);
23 },
24
25 // get the version number from the mimetype (all but IE) or ActiveX (IE)
26 detectPlugin: function(pluginName, mimeType, activeX, axDetect) {
27
28 var version = [0,0,0],
29 description,
30 i,
31 ax;
32
33 // Firefox, Webkit, Opera
34 if (typeof(this.nav.plugins) != 'undefined' && typeof this.nav.plugins[pluginName] == 'object') {
35 description = this.nav.plugins[pluginName].description;
36 if (description && !(typeof this.nav.mimeTypes != 'undefined' && this.nav.mimeTypes[mimeType] && !this.nav.mimeTypes[mimeType].enabledPlugin)) {
37 version = description.replace(pluginName, '').replace(/^\s+/,'').replace(/\sr/gi,'.').split('.');
38 for (i=0; i<version.length; i++) {
39 version[i] = parseInt(version[i].match(/\d+/), 10);
40 }
41 }
42 // Internet Explorer / ActiveX
43 } else if (typeof(window.ActiveXObject) != 'undefined') {
44 try {
45 ax = new ActiveXObject(activeX);
46 if (ax) {
47 version = axDetect(ax);
48 }
49 }
50 catch (e) { }
51 }
52 return version;
53 }
54 };
55
56 // Add Flash detection
57 mejs.PluginDetector.addPlugin('flash','Shockwave Flash','application/x-shockwave-flash','ShockwaveFlash.ShockwaveFlash', function(ax) {
58 // adapted from SWFObject
59 var version = [],
60 d = ax.GetVariable("$version");
61 if (d) {
62 d = d.split(" ")[1].split(",");
63 version = [parseInt(d[0], 10), parseInt(d[1], 10), parseInt(d[2], 10)];
64 }
65 return version;
66 });
67
68 // Add Silverlight detection
69 mejs.PluginDetector.addPlugin('silverlight','Silverlight Plug-In','application/x-silverlight-2','AgControl.AgControl', function (ax) {
70 // Silverlight cannot report its version number to IE
71 // but it does have a isVersionSupported function, so we have to loop through it to get a version number.
72 // adapted from http://www.silverlightversion.com/
73 var v = [0,0,0,0],
74 loopMatch = function(ax, v, i, n) {
75 while(ax.isVersionSupported(v[0]+ "."+ v[1] + "." + v[2] + "." + v[3])){
76 v[i]+=n;
77 }
78 v[i] -= n;
79 };
80 loopMatch(ax, v, 0, 1);
81 loopMatch(ax, v, 1, 1);
82 loopMatch(ax, v, 2, 10000); // the third place in the version number is usually 5 digits (4.0.xxxxx)
83 loopMatch(ax, v, 2, 1000);
84 loopMatch(ax, v, 2, 100);
85 loopMatch(ax, v, 2, 10);
86 loopMatch(ax, v, 2, 1);
87 loopMatch(ax, v, 3, 1);
88
89 return v;
90 });
91 // add adobe acrobat
92 /*
93 PluginDetector.addPlugin('acrobat','Adobe Acrobat','application/pdf','AcroPDF.PDF', function (ax) {
94 var version = [],
95 d = ax.GetVersions().split(',')[0].split('=')[1].split('.');
96
97 if (d) {
98 version = [parseInt(d[0], 10), parseInt(d[1], 10), parseInt(d[2], 10)];
99 }
100 return version;
101 });
102 */