forked from boronia/ableplayer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrowser.js
More file actions
162 lines (145 loc) · 5.02 KB
/
browser.js
File metadata and controls
162 lines (145 loc) · 5.02 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
(function ($) {
AblePlayer.prototype.getUserAgent = function() {
// Whenever possible we avoid browser sniffing. Better to do feature detection.
// However, in case it's needed...
// this function defines a userAgent array that can be used to query for common browsers and OSs
// NOTE: This would be much simpler with jQuery.browser but that was removed from jQuery 1.9
// http://api.jquery.com/jQuery.browser/
this.userAgent = {};
this.userAgent.browser = {};
// Test for common browsers
if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
this.userAgent.browser.name = 'Firefox';
this.userAgent.browser.version = RegExp.$1; // capture x.x portion
}
else if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x (IE10 or lower)
this.userAgent.browser.name = 'Internet Explorer';
this.userAgent.browser.version = RegExp.$1;
}
else if (/Trident.*rv[ :]*(\d+\.\d+)/.test(navigator.userAgent)) { // test for IE11 or higher
this.userAgent.browser.name = 'Internet Explorer';
this.userAgent.browser.version = RegExp.$1;
}
else if (/Edge[\/\s](\d+\.\d+)/.test(navigator.userAgent)) { // test for MS Edge
this.userAgent.browser.name = 'Edge';
this.userAgent.browser.version = RegExp.$1;
}
else if (/OPR\/(\d+\.\d+)/i.test(navigator.userAgent)) { // Opera 15 or over
this.userAgent.browser.name = 'Opera';
this.userAgent.browser.version = RegExp.$1;
}
else if (/Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor)) {
this.userAgent.browser.name = 'Chrome';
if (/Chrome[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
this.userAgent.browser.version = RegExp.$1;
}
}
else if (/Safari/.test(navigator.userAgent) && /Apple Computer/.test(navigator.vendor)) {
this.userAgent.browser.name = 'Safari';
if (/Version[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
this.userAgent.browser.version = RegExp.$1;
}
}
else {
this.userAgent.browser.name = 'Unknown';
this.userAgent.browser.version = 'Unknown';
}
// Now test for common operating systems
if (window.navigator.userAgent.indexOf("Windows NT 6.2") != -1) {
this.userAgent.os = "Windows 8";
}
else if (window.navigator.userAgent.indexOf("Windows NT 6.1") != -1) {
this.userAgent.os = "Windows 7";
}
else if (window.navigator.userAgent.indexOf("Windows NT 6.0") != -1) {
this.userAgent.os = "Windows Vista";
}
else if (window.navigator.userAgent.indexOf("Windows NT 5.1") != -1) {
this.userAgent.os = "Windows XP";
}
else if (window.navigator.userAgent.indexOf("Windows NT 5.0") != -1) {
this.userAgent.os = "Windows 2000";
}
else if (window.navigator.userAgent.indexOf("Mac")!=-1) {
this.userAgent.os = "Mac/iOS";
}
else if (window.navigator.userAgent.indexOf("X11")!=-1) {
this.userAgent.os = "UNIX";
}
else if (window.navigator.userAgent.indexOf("Linux")!=-1) {
this.userAgent.os = "Linux";
}
if (this.debug) {
console.log('User agent:' + navigator.userAgent);
console.log('Vendor: ' + navigator.vendor);
console.log('Browser: ' + this.userAgent.browser.name);
console.log('Version: ' + this.userAgent.browser.version);
console.log('OS: ' + this.userAgent.os);
}
};
AblePlayer.prototype.isUserAgent = function(which) {
var userAgent = navigator.userAgent.toLowerCase();
if (this.debug) {
console.log('User agent: ' + userAgent);
}
if (userAgent.indexOf(which.toLowerCase()) !== -1) {
return true;
}
else {
return false;
}
};
AblePlayer.prototype.isIOS = function(version) {
// return true if this is IOS
// if version is provided check for a particular version
var userAgent, iOS;
userAgent = navigator.userAgent.toLowerCase();
iOS = /ipad|iphone|ipod/.exec(userAgent);
if (iOS) {
if (typeof version !== 'undefined') {
if (userAgent.indexOf('os ' + version) !== -1) {
// this is the target version of iOS
return true;
}
else {
return false;
}
}
else {
// no version was specified
return true;
}
}
else {
// this is not IOS
return false;
}
};
AblePlayer.prototype.browserSupportsVolume = function() {
// ideally we could test for volume support
// However, that doesn't seem to be reliable
// http://stackoverflow.com/questions/12301435/html5-video-tag-volume-support
var userAgent, noVolume;
userAgent = navigator.userAgent.toLowerCase();
noVolume = /ipad|iphone|ipod|android|blackberry|windows ce|windows phone|webos|playbook/.exec(userAgent);
if (noVolume) {
if (noVolume[0] === 'android' && /firefox/.test(userAgent)) {
// Firefox on android DOES support changing the volume:
return true;
}
else {
return false;
}
}
else {
// as far as we know, this userAgent supports volume control
return true;
}
};
AblePlayer.prototype.nativeFullscreenSupported = function () {
return document.fullscreenEnabled ||
document.webkitFullscreenEnabled ||
document.mozFullScreenEnabled ||
document.msFullscreenEnabled;
};
})(jQuery);