Refactor win.js into globals.js.

This commit is contained in:
Lars Jung 2016-06-03 22:40:05 +02:00
parent 58cbad2bfd
commit 1cba9290b6
49 changed files with 106 additions and 118 deletions

2
ghu.js
View File

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

View File

@ -1,6 +1,5 @@
(function check(win) {
/* eslint-disable func-names,no-console,no-var */
/* eslint-disable func-names,no-var */
(function (win) {
if (typeof win !== 'object' || win.window !== win || !win.document) {
throw new Error('no-window');
}
@ -14,7 +13,6 @@
docEl.className = noBrowser;
throw new Error(noBrowser + ': ' + msg);
}
win.console.log('checked: ' + msg);
}
assert('console', win.console && typeof win.console.log === 'function');
@ -37,9 +35,8 @@
return false;
}
}()));
/* eslint-enable no-var */
}(this));
/* eslint-enable */
// @include "vendor/*.js"

View File

@ -1,9 +1,9 @@
const {request} = require('./core/server');
const config = module.exports = {
_update: data => {
return request(data).then(newConfig => {
Object.assign(config, newConfig);
_update: query => {
return request(query).then(response => {
Object.assign(config, response);
return config;
});
}

View File

@ -1,4 +1,4 @@
const {_: lo} = require('../win');
const {lo} = require('../globals');
const subscriptions = {};

View File

@ -1,4 +1,4 @@
const {_: lo} = require('../win');
const {lo} = require('../globals');
const decimalMetric = {
t: 1000.0,

View File

@ -1,2 +1,2 @@
const config = require('../config');
module.exports = Object.assign({}, config.langs);
const {langs} = require('../config');
module.exports = Object.assign({}, langs);

View File

@ -1,11 +1,11 @@
const {window: win, document: doc, _: lo} = require('../win');
const {win, lo} = require('../globals');
const {request} = require('./server');
const allsettings = require('./settings');
const event = require('./event');
const notification = require('../view/notification');
const doc = win.document;
const settings = lo.extend({
fastBrowsing: true,
unmanagedInNewWindow: true

View File

@ -1,4 +1,4 @@
const {_: lo} = require('../win');
const {lo} = require('../globals');
const config = require('../config');
const settings = require('./settings');

View File

@ -1,4 +1,4 @@
const {jQuery: jq, _: lo} = require('../win');
const {jq, lo} = require('../globals');
function request(data) {
return new Promise(resolve => {

View File

@ -1,4 +1,4 @@
const win = require('../win');
const {win} = require('../globals');
const store = win.localStorage;
const storekey = '_h5ai';

View File

@ -1,4 +1,4 @@
const {_: lo} = require('../win');
const {lo} = require('../globals');
const config = require('../config');
const reEndsWithSlash = /\/$/;

View File

@ -1,4 +1,4 @@
const {_: lo} = require('../win');
const {lo} = require('../globals');
function regularCmpFn(val1, val2) {
if (val1 < val2) {

View File

@ -1,4 +1,4 @@
const {setTimeout} = require('../win');
const {win} = require('../globals');
const event = require('../core/event');
const location = require('../core/location');
const allsettings = require('../core/settings');
@ -16,12 +16,12 @@ function heartbeat() {
}
function before() {
clearTimeout(timeoutId);
win.clearTimeout(timeoutId);
}
function after() {
clearTimeout(timeoutId);
timeoutId = setTimeout(heartbeat, settings.interval);
win.clearTimeout(timeoutId);
timeoutId = win.setTimeout(heartbeat, settings.interval);
}
function init() {

View File

@ -1,7 +1,8 @@
const {document: doc, jQuery: jq, _: lo} = require('../win');
const {win, jq, lo} = require('../globals');
const resource = require('../core/resource');
const allsettings = require('../core/settings');
const doc = win.document;
const settings = lo.extend({
enabled: false
}, allsettings.contextmenu);

View File

@ -1,4 +1,4 @@
const {jQuery: jq, _: lo} = require('../win');
const {jq, lo} = require('../globals');
const event = require('../core/event');
const location = require('../core/location');
const resource = require('../core/resource');

View File

@ -1,4 +1,4 @@
const {jQuery: jq, _: lo, marked} = require('../win');
const {jq, lo, marked} = require('../globals');
const event = require('../core/event');
const server = require('../core/server');
const allsettings = require('../core/settings');

View File

@ -1,4 +1,4 @@
const {jQuery: jq, _: lo} = require('../win');
const {jq, lo} = require('../globals');
const event = require('../core/event');
const location = require('../core/location');
const resource = require('../core/resource');

View File

@ -1,4 +1,4 @@
const {jQuery: jq, _: lo} = require('../win');
const {jq, lo} = require('../globals');
const event = require('../core/event');
const location = require('../core/location');
const resource = require('../core/resource');

View File

@ -1,4 +1,4 @@
const {window: win, _: lo} = require('../win');
const {win, lo} = require('../globals');
const event = require('../core/event');
const allsettings = require('../core/settings');

View File

@ -1,4 +1,4 @@
const {window: win, jQuery: jq, _: lo} = require('../win');
const {win, jq, lo} = require('../globals');
const event = require('../core/event');
const format = require('../core/format');
const resource = require('../core/resource');

View File

@ -1,4 +1,4 @@
const {navigator, jQuery: jq, _: lo} = require('../win');
const {win, jq, lo} = require('../globals');
const event = require('../core/event');
const format = require('../core/format');
const langs = require('../core/langs');
@ -89,7 +89,7 @@ function localize(languages, isoCode, useBrowserLang) {
if (languages[storedIsoCode]) {
isoCode = storedIsoCode;
} else if (useBrowserLang) {
const browserLang = navigator.language || navigator.browserLanguage;
const browserLang = win.navigator.language || win.navigator.browserLanguage;
if (browserLang) {
if (languages[browserLang]) {
isoCode = browserLang;

View File

@ -1,4 +1,4 @@
const {window: win, jQuery: jq, _: lo} = require('../win');
const {win, jq, lo} = require('../globals');
const allsettings = require('../core/settings');
const settings = lo.extend({

View File

@ -1,4 +1,4 @@
const {window: win, jQuery: jq, _: lo} = require('../win');
const {win, jq, lo} = require('../globals');
const event = require('../core/event');
const allsettings = require('../core/settings');

View File

@ -1,4 +1,4 @@
const {setTimeout, jQuery: jq, _: lo} = require('../win');
const {win, jq, lo} = require('../globals');
const event = require('../core/event');
const format = require('../core/format');
const allsettings = require('../core/settings');
@ -13,7 +13,7 @@ function preloadAudio(src, callback) {
const $audio = jq('<audio/>')
.one('loadedmetadata', () => {
callback($audio);
// setTimeout(function () { callback($img); }, 1000); // for testing
// win.setTimeout(function () { callback($img); }, 1000); // for testing
})
.attr('autoplay', 'autoplay')
.attr('controls', 'controls')
@ -46,7 +46,7 @@ function onEnter(items, idx) {
currentIdx = (currentIdx + rel + currentItems.length) % currentItems.length;
currentItem = currentItems[currentIdx];
const spinnerTimeout = setTimeout(() => preview.showSpinner(true), 200);
const spinnerTimeout = win.setTimeout(() => preview.showSpinner(true), 200);
if (jq('#pv-aud-audio').length) {
jq('#pv-aud-audio')[0].pause();
@ -61,11 +61,11 @@ function onEnter(items, idx) {
function swap(nuContent) {
jq('#pv-content').empty().append(nuContent.attr('id', 'pv-vid-audio')).fadeIn(200);
// small timeout, so nuContent is visible and therefore its width is available
setTimeout(updateMeta, 10);
win.setTimeout(updateMeta, 10);
}
function onReady($preloadedContent) {
clearTimeout(spinnerTimeout);
win.clearTimeout(spinnerTimeout);
preview.showSpinner(false);
jq('#pv-content').fadeOut(100, () => swap($preloadedContent));

View File

@ -1,4 +1,4 @@
const {setTimeout, jQuery: jq, _: lo} = require('../win');
const {win, jq, lo} = require('../globals');
const event = require('../core/event');
const server = require('../core/server');
const allsettings = require('../core/settings');
@ -42,7 +42,7 @@ function preloadImage(item, callback) {
callback(item, ev.target);
// for testing
// setTimeout(function () { callback(item, ev.target); }, 1000);
// win.setTimeout(function () { callback(item, ev.target); }, 1000);
})
.attr('src', src);
});
@ -81,8 +81,8 @@ function onIdxChange(rel) {
if (preview.isSpinnerVisible()) {
preview.showSpinner(true, currentItem.thumbSquare);
} else {
clearTimeout(spinnerTimeoutId);
spinnerTimeoutId = setTimeout(() => {
win.clearTimeout(spinnerTimeoutId);
spinnerTimeoutId = win.setTimeout(() => {
preview.showSpinner(true, currentItem.thumbSquare);
}, spinnerThreshold);
}
@ -92,7 +92,7 @@ function onIdxChange(rel) {
return;
}
clearTimeout(spinnerTimeoutId);
win.clearTimeout(spinnerTimeoutId);
preview.showSpinner(false);
jq('#pv-content')
.empty()

View File

@ -1,4 +1,4 @@
const {setTimeout, jQuery: jq, _: lo, marked, Prism: prism} = require('../win');
const {win, jq, lo, marked, prism} = require('../globals');
const event = require('../core/event');
const allsettings = require('../core/settings');
const preview = require('./preview');
@ -26,7 +26,7 @@ function preloadText(item, callback) {
callback(item, content);
// for testing
// setTimeout(function () { callback(item, content); }, 1000);
// win.setTimeout(function () { callback(item, content); }, 1000);
})
.fail((jqXHR, textStatus) => {
callback(item, '[ajax error] ' + textStatus);
@ -57,8 +57,8 @@ function onIdxChange(rel) {
if (preview.isSpinnerVisible()) {
preview.showSpinner(true, currentItem.icon);
} else {
clearTimeout(spinnerTimeoutId);
spinnerTimeoutId = setTimeout(() => {
win.clearTimeout(spinnerTimeoutId);
spinnerTimeoutId = win.setTimeout(() => {
preview.showSpinner(true, currentItem.icon);
}, spinnerThreshold);
}
@ -86,13 +86,13 @@ function onIdxChange(rel) {
$code.empty().html(prism.highlight(textContent, prism.languages[type]));
} else {
$code.empty().text(textContent);
setTimeout(() => {
win.setTimeout(() => {
$code.empty().html(prism.highlight(textContent, prism.languages[type]));
}, 300);
}
}
clearTimeout(spinnerTimeoutId);
win.clearTimeout(spinnerTimeoutId);
preview.showSpinner(false);
jq('#pv-content')
.empty()

View File

@ -1,4 +1,4 @@
const {setTimeout, jQuery: jq, _: lo} = require('../win');
const {win, jq, lo} = require('../globals');
const event = require('../core/event');
const allsettings = require('../core/settings');
const preview = require('./preview');
@ -12,7 +12,7 @@ function preloadVideo(src, callback) {
const $video = jq('<video/>')
.one('loadedmetadata', () => {
callback($video);
// setTimeout(function () { callback($video); }, 1000); // for testing
// win.setTimeout(function () { callback($video); }, 1000); // for testing
})
.attr('autoplay', 'autoplay')
.attr('controls', 'controls')
@ -46,7 +46,7 @@ function onEnter(items, idx) {
currentIdx = (currentIdx + rel + currentItems.length) % currentItems.length;
currentItem = currentItems[currentIdx];
const spinnerTimeout = setTimeout(() => preview.showSpinner(true), 200);
const spinnerTimeout = win.setTimeout(() => preview.showSpinner(true), 200);
if (jq('#pv-vid-video').length) {
jq('#pv-vid-video')[0].pause();
@ -61,11 +61,11 @@ function onEnter(items, idx) {
function swap(nuContent) {
jq('#pv-content').empty().append(nuContent.attr('id', 'pv-vid-video')).fadeIn(200);
// small timeout, so nuContent is visible and therefore its width is available
setTimeout(updateMeta, 10);
win.setTimeout(updateMeta, 10);
}
function onReady($preloadedContent) {
clearTimeout(spinnerTimeout);
win.clearTimeout(spinnerTimeout);
preview.showSpinner(false);
jq('#pv-content').fadeOut(100, () => swap($preloadedContent));

View File

@ -1,4 +1,4 @@
const {window: win, setTimeout, jQuery: jq, _: lo} = require('../win');
const {win, jq, lo} = require('../globals');
const resource = require('../core/resource');
const allsettings = require('../core/settings');
const store = require('../core/store');
@ -89,11 +89,11 @@ function onPrevious() {
}
function userAlive() {
clearTimeout(userAliveTimeoutId);
win.clearTimeout(userAliveTimeoutId);
jq('#pv-overlay .hof').stop(true, true).fadeIn(200);
if (isFullscreen) {
userAliveTimeoutId = setTimeout(() => {
userAliveTimeoutId = win.setTimeout(() => {
jq('#pv-overlay .hof').stop(true, true).fadeOut(2000);
}, 2000);
}

View File

@ -1,4 +1,4 @@
const {jQuery: jq, _: lo} = require('../win');
const {jq, lo} = require('../globals');
const event = require('../core/event');
const location = require('../core/location');
const resource = require('../core/resource');

View File

@ -1,9 +1,10 @@
const {document: doc, jQuery: jq, _: lo} = require('../win');
const {win, jq, lo} = require('../globals');
const event = require('../core/event');
const resource = require('../core/resource');
const allsettings = require('../core/settings');
const doc = win.document;
const settings = lo.extend({
enabled: false,
clickndrag: false,

View File

@ -1,4 +1,4 @@
const {jQuery: jq, _: lo} = require('../win');
const {jq, lo} = require('../globals');
const event = require('../core/event');
const resource = require('../core/resource');
const allsettings = require('../core/settings');

View File

@ -1,4 +1,4 @@
const {_: lo} = require('../win');
const {lo} = require('../globals');
const event = require('../core/event');
const server = require('../core/server');
const allsettings = require('../core/settings');

View File

@ -1,8 +1,9 @@
const {document: doc, _: lo} = require('../win');
const {win, lo} = require('../globals');
const event = require('../core/event');
const allsettings = require('../core/settings');
const doc = win.document;
const settings = lo.extend({
enabled: false
}, allsettings.title);

View File

@ -1,4 +1,4 @@
const {jQuery: jq, _: lo} = require('../win');
const {jq, lo} = require('../globals');
const event = require('../core/event');
const location = require('../core/location');
const resource = require('../core/resource');

View File

@ -0,0 +1,14 @@
const globals = module.exports = {};
const publish = (id, name) => {
if (!global[id]) {
throw new Error(`no-global: ${id}`);
}
globals[name] = global[id];
};
publish('window', 'win');
publish('_', 'lo');
publish('jQuery', 'jq');
publish('marked', 'marked');
publish('Prism', 'prism');

View File

@ -1,8 +1,8 @@
// const {jQuery: jq} = require('./win');
// const {jq} = require('./globals');
// const config = require('./config');
//
// const name = jq('script[data-module]').data('module');
// const request = {
// const query = {
// action: 'get',
// setup: true,
// options: true,
@ -10,26 +10,26 @@
// };
//
// if (name === 'index') {
// request.theme = true;
// request.langs = true;
// query.theme = true;
// query.langs = true;
// } else if (name === 'info') {
// request.refresh = true;
// query.refresh = true;
// } else {
// throw new Error(`no-main-module: '${name}'`);
// }
//
// config._update(request).then(() => {
// config._update(query).then(() => {
// jq(() => require(`./main/${name}`));
// });
module.exports = (deps = {}) => {
const {
jq = require('./win').jQuery,
jq = require('./globals').jq,
config = require('./config')
} = deps;
const name = jq('script[data-module]').data('module');
const request = {
const query = {
action: 'get',
setup: true,
options: true,
@ -37,15 +37,15 @@ module.exports = (deps = {}) => {
};
if (name === 'index') {
request.theme = true;
request.langs = true;
query.theme = true;
query.langs = true;
} else if (name === 'info') {
request.refresh = true;
query.refresh = true;
} else {
throw new Error(`no-main-module: '${name}'`);
}
config._update(request).then(() => {
config._update(query).then(() => {
jq(() => require(`./main/${name}`));
});
};

View File

@ -1,4 +1,4 @@
const {document: doc} = require('../win');
const {win} = require('../globals');
const location = require('../core/location');
require('../view/viewmode');
@ -25,4 +25,4 @@ require('../ext/thumbnails');
require('../ext/title');
require('../ext/tree');
location.setLocation(doc.location.href, true);
location.setLocation(win.document.location.href, true);

View File

@ -1,4 +1,4 @@
const {window: win, jQuery: jq} = require('../win');
const {win, jq} = require('../globals');
const config = require('../config');
const resource = require('../core/resource');
const server = require('../core/server');

View File

@ -1,4 +1,4 @@
const {_: lo} = require('../win');
const {lo} = require('../globals');
const location = require('../core/location');
const server = require('../core/server');
const settings = require('../core/settings');

View File

@ -1,4 +1,4 @@
const {jQuery: jq} = require('../win');
const {jq} = require('../globals');
const mainrow = require('./mainrow');
const $el = jq('<div id="content"/>').appendTo(mainrow.$el);

View File

@ -1,4 +1,4 @@
const {jQuery: jq} = require('../win');
const {jq} = require('../globals');
const root = require('./root');
const $el = jq('<div id="mainrow"/>').appendTo(root.$el);

View File

@ -1,4 +1,4 @@
const {jQuery: jq} = require('../win');
const {jq} = require('../globals');
const root = require('./root');
const $el = jq('<div id="notification"/>').hide().appendTo(root.$el);

View File

@ -1,4 +1,4 @@
const {jQuery: jq} = require('../win');
const {jq} = require('../globals');
const $el = jq('body').attr('id', 'root');

View File

@ -1,4 +1,4 @@
const {jQuery: jq} = require('../win');
const {jq} = require('../globals');
const resource = require('../core/resource');
const store = require('../core/store');
const mainrow = require('./mainrow');

View File

@ -1,4 +1,4 @@
const {jQuery: jq} = require('../win');
const {jq} = require('../globals');
const root = require('./root');
const tplTopbar =

View File

@ -1,4 +1,4 @@
const {jQuery: jq, _: lo} = require('../win');
const {jq, lo} = require('../globals');
const event = require('../core/event');
const format = require('../core/format');
const location = require('../core/location');

View File

@ -1,4 +1,4 @@
const {jQuery: jq, _: lo} = require('../win');
const {jq, lo} = require('../globals');
const event = require('../core/event');
const resource = require('../core/resource');
const allsettings = require('../core/settings');

View File

@ -1,5 +0,0 @@
const win = module.exports = global.window;
if (typeof win !== 'object' || win.window !== win || !win.document) {
throw new Error('no-window');
}

View File

@ -15,29 +15,8 @@
uniq: false
sinon: false
ecmaFeatures:
arrowFunctions: false
binaryLiterals: false
blockBindings: false
classes: false
defaultParams: false
destructuring: false
forOf: false
generators: false
globalReturn: false
jsx: false
modules: false
objectLiteralComputedProperties: false
objectLiteralDuplicateProperties: false
objectLiteralShorthandMethods: false
objectLiteralShorthandProperties: false
octalLiterals: false
regexUFlag: false
regexYFlag: false
spread: false
superInFunctions: false
templateStrings: false
unicodeCodePointEscapes: false
parserOptions:
ecmaVersion: 6
rules:
consistent-this: 0