Replace modernizr with custom setup.

This commit is contained in:
Lars Jung 2015-05-29 15:27:44 +02:00
parent fc3f84da6e
commit 34aeac9787
10 changed files with 126 additions and 14 deletions

View File

@ -1,4 +1,4 @@
modulejs.define('core/location', ['_', 'modernizr', 'core/event', 'core/settings', 'view/notification'], function (_, modernizr, event, allsettings, notification) {
modulejs.define('core/location', ['_', 'core/event', 'core/modernizr', 'core/settings', 'view/notification'], function (_, event, modernizr, allsettings, notification) {
var settings = _.extend({
fastBrowsing: true,

View File

@ -0,0 +1,28 @@
modulejs.define('core/modernizr', function () {
var hasCanvas = (function () {
var elem = document.createElement('canvas');
return Boolean(elem.getContext && elem.getContext('2d'));
}());
var hasHistory = Boolean(window.history && history.pushState);
var hasLocalStorage = (function () {
var key = '#test#';
try {
localStorage.setItem(key, key);
localStorage.removeItem(key);
return true;
} catch (e) {
return false;
}
}());
return {
canvas: hasCanvas,
history: hasHistory,
localstorage: hasLocalStorage
};
});

View File

@ -1,4 +1,4 @@
modulejs.define('core/store', ['modernizr'], function (modernizr) {
modulejs.define('core/store', ['core/modernizr'], function (modernizr) {
var store = modernizr.localstorage ? window.localStorage : {};
var storekey = '_h5ai';

View File

@ -1,4 +1,4 @@
modulejs.define('ext/info', ['_', '$', 'modernizr', 'core/event', 'core/format', 'core/resource', 'core/settings', 'core/store'], function (_, $, modernizr, event, format, resource, allsettings, store) {
modulejs.define('ext/info', ['_', '$', 'core/event', 'core/format', 'core/modernizr', 'core/resource', 'core/settings', 'core/store'], function (_, $, event, format, modernizr, resource, allsettings, store) {
var settings = _.extend({
enabled: false,

File diff suppressed because one or more lines are too long

View File

@ -1,17 +1,17 @@
(function () {
'use strict';
document.documentElement.className = '';
var el = document.createElement('i');
el.innerHTML = '<!--[if lt IE 10]><br><![endif]-->';
var browser = el.getElementsByTagName('br').length === 0;
if (!browser) {
document.documentElement.className = 'js no-browser';
document.documentElement.className = 'no-browser';
throw 'no-browser';
}
}());
// @include 'lib/modernizr-*.js'
// @include 'lib/jquery-*.js'
// @include 'lib/jquery.*.js'
// @include 'lib/lodash-*.js'
@ -26,7 +26,6 @@
modulejs.define('_', function () { return win._; });
modulejs.define('$', function () { return win.jQuery; });
modulejs.define('marked', function () { return win.marked; });
modulejs.define('modernizr', function () { return win.Modernizr; });
modulejs.define('prism', function () { return win.Prism; });
// @include 'inc/**/*.js'

View File

@ -2,7 +2,7 @@
'use strict';
var ID = 'core/location';
var DEPS = ['_', 'modernizr', 'core/event', 'core/settings', 'view/notification'];
var DEPS = ['_', 'core/event', 'core/modernizr', 'core/settings', 'view/notification'];
describe('module \'' + ID + '\'', function () {
@ -30,7 +30,7 @@ describe('module \'' + ID + '\'', function () {
this.xEvent.sub.reset();
this.xNotification.set.reset();
return this.definition.fn(_, this.xModernizr, this.xEvent, this.xSettings, this.xNotification);
return this.definition.fn(_, this.xEvent, this.xModernizr, this.xSettings, this.xNotification);
};
});

View File

@ -0,0 +1,90 @@
(function () {
'use strict';
var ID = 'core/modernizr';
var DEPS = [];
describe('module \'' + ID + '\'', function () {
before(function () {
this.definition = modulejs._private.definitions[ID];
this.applyFn = function () {
return this.definition.fn();
};
});
describe('definition', function () {
it('is defined', function () {
assert.isPlainObject(this.definition);
});
it('has correct id', function () {
assert.strictEqual(this.definition.id, ID);
});
it('requires correct', function () {
assert.deepEqual(this.definition.deps, DEPS);
});
it('args for each request', function () {
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
});
it('has no instance', function () {
assert.notProperty(modulejs._private.instances, ID);
});
it('inits without errors', function () {
this.applyFn();
});
});
describe('application', function () {
it('returns plain object with 3 properties', function () {
var instance = this.applyFn();
assert.isPlainObject(instance);
assert.lengthOf(_.keys(instance), 3);
});
});
describe('.canvas', function () {
it('is boolean', function () {
var instance = this.applyFn();
assert.isBoolean(instance.canvas);
});
});
describe('.history', function () {
it('is boolean', function () {
var instance = this.applyFn();
assert.isBoolean(instance.history);
});
});
describe('.localstorage', function () {
it('is boolean', function () {
var instance = this.applyFn();
assert.isBoolean(instance.localstorage);
});
});
});
}());

View File

@ -2,7 +2,7 @@
'use strict';
var ID = 'core/store';
var DEPS = ['modernizr'];
var DEPS = ['core/modernizr'];
describe('module \'' + ID + '\'', function () {

View File

@ -7,7 +7,6 @@ describe('libs', function () {
_: window._,
$: window.jQuery,
marked: window.marked,
modernizr: window.Modernizr,
prism: window.Prism
};