-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
72 lines (64 loc) · 2.75 KB
/
index.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
'use strict';
const DF = (function () {
// Criação dos elementos
let elCanvas = document.createElement('canvas');
let elVideo = document.createElement('video');
let elInput = document.createElement('input');
// Mapeamento de funcionalidades da HTML5
let funcionalidades = {
canvas: false,
canvasText: false,
video: false,
videoH264: false,
videoOgg: false,
videoWebM: false,
localStorage: 'localStorage' in window,
webWorker: 'Worker' in window,
aplicacoesOffline: 'applicationCache' in window,
geolocation: 'geolocation' in navigator,
microdata: 'getItems' in document,
history: 'pushState' in history,
inputSearch: verificaSuporteInput('search'),
inputNumber: verificaSuporteInput('number'),
inputRange: verificaSuporteInput('range'),
inputColor: verificaSuporteInput('color'),
inputTel: verificaSuporteInput('tel'),
inputUrl: verificaSuporteInput('url'),
inputEmail: verificaSuporteInput('email'),
inputDate: verificaSuporteInput('date'),
inputMonth: verificaSuporteInput('month'),
inputWeek: verificaSuporteInput('week'),
inputTime: verificaSuporteInput('time'),
inputDateTime: verificaSuporteInput('datetime'),
inputDateTimeLocal: verificaSuporteInput('datetime-local'),
inputPlaceholder: 'placeholder' in elInput
};
// Verifica o suporte a canvas
funcionalidades.canvas = !!elCanvas.getContext;
// Verifica o suporte a texto no canvas
if (funcionalidades.canvas) {
let contexto = elCanvas.getContext('2d');
funcionalidades.canvasText = typeof contexto.fillText === 'function';
}
// Verifica o suporte a vídeo
funcionalidades.video = !!elVideo.canPlayType;
// Verifica o suporte aos formatos de vídeo
if (funcionalidades.video) {
funcionalidades.videoH264 = elVideo.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"');
funcionalidades.videoOgg = elVideo.canPlayType('video/ogg; codecs="theora, vorbis"');
funcionalidades.videoWebM = elVideo.canPlayType('video/webm; codecs="vp8, vorbis"');
}
/**
* Verifica o suporte aos diversos tipos de input. Se após setar o atributo 'type' do input para o tipo
* desejado o browser ignorar e o atributo continuar com o valor 'text', significa que o browser não
* dá suporte para o tipo de input informado.
*/
function verificaSuporteInput(tipo) {
let suporteOk = false;
elInput.setAttribute('type', tipo);
suporteOk = elInput.type !== 'text';
elInput.setAttribute('type', 'text'); // reseta para os demais testes
return suporteOk;
}
return funcionalidades;
}());