mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-24 03:57:08 -04:00
Stricter browser checks. Drop IE support.
This commit is contained in:
parent
7ec2bdf16a
commit
f7187fb14b
5 changed files with 50 additions and 44 deletions
45
src/_h5ai/public/js/global.js
Normal file
45
src/_h5ai/public/js/global.js
Normal file
|
@ -0,0 +1,45 @@
|
|||
(function check(win) {
|
||||
/* eslint-disable func-names,no-console,no-var */
|
||||
|
||||
if (typeof win !== 'object' || win.window !== win || !win.document) {
|
||||
throw new Error('no-window');
|
||||
}
|
||||
|
||||
var noBrowser = 'no-browser';
|
||||
var docEl = win.document.documentElement;
|
||||
docEl.className = '';
|
||||
|
||||
function assert(msg, expr) {
|
||||
if (!expr) {
|
||||
docEl.className = noBrowser;
|
||||
throw new Error(noBrowser + ': ' + msg);
|
||||
}
|
||||
win.console.log('checked: ' + msg);
|
||||
}
|
||||
|
||||
assert('console', win.console && typeof win.console.log === 'function');
|
||||
assert('assign', win.Object && typeof win.Object.assign === 'function');
|
||||
assert('promise', win.Promise && typeof win.Promise === 'function');
|
||||
assert('history', win.history && typeof win.history.pushState === 'function');
|
||||
|
||||
assert('canvas', (function () {
|
||||
var elem = win.document.createElement('canvas');
|
||||
return elem.getContext && elem.getContext('2d');
|
||||
}()));
|
||||
|
||||
assert('storage', (function () {
|
||||
var key = '#test#';
|
||||
try {
|
||||
win.localStorage.setItem(key, key);
|
||||
win.localStorage.removeItem(key);
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}()));
|
||||
|
||||
/* eslint-enable no-var */
|
||||
}(this));
|
||||
|
||||
|
||||
// @include "vendor/*.js"
|
Loading…
Add table
Add a link
Reference in a new issue