Stricter browser checks. Drop IE support.

This commit is contained in:
Lars Jung 2016-06-03 17:36:42 +02:00
parent 7ec2bdf16a
commit f7187fb14b
5 changed files with 50 additions and 44 deletions

2
ghu.js
View file

@ -69,7 +69,7 @@ ghu.task('build:scripts', runtime => {
return read(`${SRC}/_h5ai/public/js/scripts.js`) return read(`${SRC}/_h5ai/public/js/scripts.js`)
.then(newerThan(mapper, `${SRC}/_h5ai/public/js/**`)) .then(newerThan(mapper, `${SRC}/_h5ai/public/js/**`))
.then(webpack(webpackConfig, {showStats: true})) .then(webpack(webpackConfig, {showStats: true}))
.then(wrap('\n\n// @include "vendor/*"\n\n')) .then(wrap('\n\n// @include "global.js"\n\n'))
.then(includeit()) .then(includeit())
.then(ife(() => runtime.args.production, uglify())) .then(ife(() => runtime.args.production, uglify()))
.then(wrap(runtime.commentJs)) .then(wrap(runtime.commentJs))

View file

@ -5,7 +5,6 @@ doctype html
html(class='no-js', lang='en') html(class='no-js', lang='en')
head head
<!--[if lt IE 10]><meta id='no-browser'><![endif]-->
meta(charset='utf-8') meta(charset='utf-8')
meta(http-equiv='x-ua-compatible', content='ie=edge') meta(http-equiv='x-ua-compatible', content='ie=edge')
title #{title} title #{title}

View 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"

View file

@ -1,25 +1,5 @@
const win = require('../win');
const hasCanvas = (() => {
const elem = win.document.createElement('canvas');
return !!(elem.getContext && elem.getContext('2d'));
})();
const hasHistory = !!(win.history && win.history.pushState);
const hasLocalStorage = (() => {
const key = '#test#';
try {
win.localStorage.setItem(key, key);
win.localStorage.removeItem(key);
return true;
} catch (e) {
return false;
}
})();
module.exports = { module.exports = {
canvas: hasCanvas, canvas: true,
history: hasHistory, history: true,
localstorage: hasLocalStorage localstorage: true
}; };

View file

@ -1,23 +1,5 @@
const win = window; // eslint-disable-line no-undef const win = module.exports = global.window;
if (typeof win !== 'object' || win.window !== win || !win.document) { if (typeof win !== 'object' || win.window !== win || !win.document) {
throw new Error('no-window'); throw new Error('no-window');
} }
const noBrowser = 'no-browser';
const doc = win.document;
const docEl = doc.documentElement;
docEl.className = '';
function assert(expr, hint) {
if (!expr) {
docEl.className = noBrowser;
throw new Error(`${noBrowser}: ${hint}`);
}
}
assert(!doc.getElementById(noBrowser), 'ie<10');
assert(typeof Object.assign === 'function', 'assign');
assert(typeof Promise === 'function', 'promise');
module.exports = win;