-
Notifications
You must be signed in to change notification settings - Fork 1
/
has.js
112 lines (98 loc) · 2.79 KB
/
has.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
define([
'dojo/has'
], function(has){
// summary:
// Provides has() tests.
// description:
// This module pulls in dojo/has and any test it provides. It is
// suggested that you pull in this module into your own has module
// to provide additional tests.
//
var d = document;
var el = document.createElement('bv');
var vid = d.createElement('video');
var test_style = el.style;
var ua = navigator.userAgent;
var winSize = function(){
var element = (d.compatMode == 'BackCompat') ? d.body : d.documentElement;
return { w: element.clientWidth, h: element.clientHeight};
}
var cap = function(word){
return word.charAt(0).toUpperCase() + word.substr(1);
}
var testcss = function(prop){
var uc = cap(prop);
var props = [
prop,
'Webkit' + uc,
'Moz' + uc,
'O' + uc,
'ms' + uc,
'Khtml' + uc
];
for(var nm in props){
if(test_style[props[nm]] !== undefined) return props[nm];
}
return false;
}
has.add('transition', function(){
return testcss('transition');
});
has.add('transform', function(){
return testcss('transform');
});
has.add('transitionevent', function(){
// don't know if testing for an event is very reliable. Sniff!
if(has('opera')){
return "OTransitionEnd";
}else if(has('ff')){
return "transitionend";
}else if(has('webkit')){
return "webkitTransitionEnd"; // small w? wTF!
}
return false;
});
has.add('mp4', function(){
if(!has('video')) return false;
return vid.canPlayType('video/mp4; codecs="avc1.42E01E"');
});
has.add('video/mp4', function(){
return has('mp4');
});
has.add('ogg', function(){
if(!has('video')) return false;
return vid.canPlayType('video/ogg; codecs="theora"');
});
has.add('video/ogg', function(){
return has('ogg');
});
has.add('webm', function(){
if(!has('video')) return false;
return vid.canPlayType('video/webm; codecs="vp8, vorbis"');
});
has.add('video/webm', function(){
return has('webm');
});
has.add('video', function(){
return !!vid.canPlayType;
});
has.add('mobile', function(){
// Checking ua string for iPhone - this way, testing can be done
// on desktop Safari with dev mode UA set
if(/iPhone/.test(ua)) return true;
// checking touch + window size to determine if mobile
// 600 width is rather arbitrary
return has('touch') && winSize().w < 600;
});
has.add('fake-mobile', function(){
// Testing if we are in fake iPhone mode with desktop Safari and
// dev mode UA set
return has('iphone') && !(has('touch') && winSize().w < 600);
});
has.add('tablet', function(){
// checking touch + window size to determine if tablet
// 600 width is rather arbitrary
return has('touch') && winSize().w > 600;
});
return has;
});