-
Notifications
You must be signed in to change notification settings - Fork 15
/
sniffer.js
70 lines (51 loc) · 1.9 KB
/
sniffer.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
import Ember from 'ember';
const isString = value => {
return typeof value === 'string';
};
var lowercase = (string) => {
return isString(string) ? string.toLowerCase() : string;
};
function toInt(str) {
return parseInt(str, 10);
}
var SnifferService = Ember.Service.extend({
vendorPrefix: '',
transitions: false,
animations: false,
document: document,
window: window,
android: Ember.computed('', function() {
return toInt((/android (\d+)/.exec(lowercase((this.get('window').navigator || {}).userAgent)) || [])[1]);
}),
init() {
this._super(...arguments);
var bodyStyle = this.get('document').body && this.get('document').body.style;
var vendorPrefix;
var vendorRegex = /^(Moz|webkit|ms)(?=[A-Z])/;
var transitions = false;
var animations = false;
var match;
if (bodyStyle) {
for (var prop in bodyStyle) {
if (match = vendorRegex.exec(prop)) {
vendorPrefix = match[0];
vendorPrefix = vendorPrefix.substr(0, 1).toUpperCase() + vendorPrefix.substr(1);
break;
}
}
if (!vendorPrefix) {
vendorPrefix = ('WebkitOpacity' in bodyStyle) && 'webkit';
}
transitions = !!(('transition' in bodyStyle) || (vendorPrefix + 'Transition' in bodyStyle));
animations = !!(('animation' in bodyStyle) || (vendorPrefix + 'Animation' in bodyStyle));
if (this.get('android') && (!transitions || !animations)) {
transitions = isString(bodyStyle.webkitTransition);
animations = isString(bodyStyle.webkitAnimation);
}
}
this.set('transitions', transitions);
this.set('animations', animations);
this.set('vendorPrefix', vendorPrefix);
}
});
export default SnifferService;