/
jquerySupportHTML5.js
97 lines (92 loc) · 4.55 KB
/
jquerySupportHTML5.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
/*
Author : Olivier Gorzalka (http://clearideaz.com)
Adapted from the DiveIntoHTML5 Article
http://diveintohtml5.org/everything.html
Usage : $.support.audio to test the Audio support or jQuery.support.color to test the input[type=color] implementation
*/
/*
Adapted form the DiveIntoHTML5 Article
http://diveintohtml5.org/everything.html
Usage : $.support.audio to test the Audio support or jQuery.support.color to test the input[type=color] implementation
*/
;(function ($) {
var doc = document,
a = doc.createElement('audio'),
b = doc.createElement('canvas'),
c = doc.createElement('iframe'),
d = doc.createElement('input'),
e = doc.createElement('video'),
f = doc.createElement('div'),
g = ['color', 'email', 'number', 'range', 'search', 'tel', 'url', 'date', 'time', 'datetime', 'datetime-local', 'month', 'week'];
f.innerHTML = '<svg></svg>';
for (i = 0; i < g.length; i++) {
g[g[i]] = doc.createElement('input');
g[g[i]].setAttribute('type', g[i])
}
function sessionStorage() {
try {
return ('sessionStorage' in window) && window['sessionStorage'] !== null;
} catch(e) {
return false;
}
}
$.extend($.support, {
audio: !! doc.createElement('audio').canPlayType,
audioMp3: !! (a.canPlayType && a.canPlayType('audio/mpeg;').replace(/no/, '')),
audioVorbis: !! (a.canPlayType && a.canPlayType('audio/ogg; codecs="vorbis"').replace(/no/, '')),
audioWav: !! (a.canPlayType && a.canPlayType('audio/wav; codecs="1"').replace(/no/, '')),
audioAAC: !! (a.canPlayType && a.canPlayType('audio/mp4; codecs="mp4aud.40.2"').replace(/no/, '')),
canvas: !! b.getContext,
canvasTxt: b.getContext && typeof b.getContext('2d').fillText == 'function',
command: 'type' in doc.createElement('command'),
datalist: 'options' in doc.createElement('datalist'),
details: 'open' in doc.createElement('details'),
device: 'type' in doc.createElement('device'),
formConstraints: 'noValidate' in c,
iframeSandbox: 'sandbox' in c,
iframeSrcDoc: 'srcdoc' in c,
autofocus: 'autofocus' in d,
placeholder: 'placeholder' in d,
color: g.color.type !== 'text',
email: g.email.type !== 'text',
number: g.number.type !== 'text',
range: g.range.type !== 'text',
search: g.search.type !== 'text',
tel: g.tel.type !== 'text',
url: g.url.type !== 'text',
date: g.date.type !== 'text',
time: g.time.type !== 'text',
datetime: g.datetime.type !== 'text',
'datetime-local': g['datetime-local'].type !== 'text',
month: g.month.type !== 'text',
week: g.week.type !== 'text',
meter: 'value' in doc.createElement('meter'),
output: 'value' in doc.createElement('output'),
progress: 'value' in doc.createElement('progress'),
time: 'valueAsDate' in doc.createElement('time'),
video: !! doc.createElement('video').canPlayType,
videoCaptions: 'track' in doc.createElement('track'),
videoPoster: 'poster' in doc.createElement('video'),
videoWebM: !! (e.canPlayType && e.canPlayType('video/webm; codecs="vp8, vorbis"').replace(/no/, '')),
videoH264: !! (e.canPlayType && e.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"').replace(/no/, '')),
videoTheora: !! (e.canPlayType && e.canPlayType('video/ogg; codecs="theora, vorbis"').replace(/no/, '')),
contentEditable: 'contentEditable' in document.createElement('div'),
crossDocumentMessaging: !! window.postMessage,
dragAndDrop: 'draggable' in doc.createElement('span'),
fileAPI: typeof FileReader != 'undefined',
geoLocation: !! navigator.geolocation,
history: !! (window.history && window.history.pushState && window.history.popState),
localStorage: (('localStorage' in window) && window['localStorage'] !== null),
microdata: !! doc.getItems,
applicationCache: !! window.applicationCache,
eventSource: typeof EventSource !== 'undefined',
sessionStorage: sessionStorage(),
svg: !! (doc.createElementNS && doc.createElementNS('http://www.w3.org/2000/svg', 'svg').createSVGRect),
svgInHtml: !! (window.SVGSVGElement && f.firstChild instanceof window.SVGSVGElement),
webSimpleDB: !! window.indexedDB,
webSocket: !! window.WebSocket,
openDatabase: !! window.openDatabase,
webWorkers: !! window.Worker,
undo: typeof UndoManager !== 'undefined'
})
})(jQuery);