mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-08-10 07:54:00 +02:00
Turn onReady/Load into promised code.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const {dom, onLoad} = require('../util');
|
||||
const {dom, awaitLoad} = require('../util');
|
||||
const event = require('../core/event');
|
||||
const allsettings = require('../core/settings');
|
||||
|
||||
@@ -21,7 +21,7 @@ const init = () => {
|
||||
let piwikTracker = null;
|
||||
|
||||
dom('<script></script>').attr('src', pkBaseURL + 'piwik.js').appTo('body');
|
||||
onLoad(() => {
|
||||
awaitLoad().then(() => {
|
||||
piwikTracker = win.Piwik && win.Piwik.getTracker(pkBaseURL + 'piwik.php', settings.idSite);
|
||||
if (piwikTracker) {
|
||||
piwikTracker.enableLinkTracking();
|
||||
|
@@ -1,4 +1,4 @@
|
||||
const {dom, onReady} = require('./util');
|
||||
const {dom, awaitReady} = require('./util');
|
||||
const config = require('./config');
|
||||
|
||||
const name = dom('script[data-module]').attr('data-module');
|
||||
@@ -18,4 +18,6 @@ if (name === 'index') {
|
||||
throw new Error(`no-main-module: '${name}'`);
|
||||
}
|
||||
|
||||
config._update(query).then(() => onReady(() => require(`./main/${name}`)));
|
||||
config._update(query)
|
||||
.then(() => awaitReady())
|
||||
.then(() => require(`./main/${name}`));
|
||||
|
@@ -1,6 +1,5 @@
|
||||
const location = require('../core/location');
|
||||
|
||||
require('../view/viewmode');
|
||||
|
||||
require('../ext/autorefresh');
|
||||
require('../ext/contextmenu');
|
||||
require('../ext/crumb');
|
||||
@@ -19,4 +18,5 @@ require('../ext/thumbnails');
|
||||
require('../ext/title');
|
||||
require('../ext/tree');
|
||||
|
||||
location.setLocation(global.window.document.location.href, true);
|
||||
const href = global.window.document.location.href;
|
||||
require('../core/location').setLocation(href, true);
|
||||
|
@@ -48,15 +48,19 @@ const isElDocWin = x => isElement(x) || isDocument(x) || isWindow(x);
|
||||
const addListener = (el, type, fn) => el.addEventListener(type, fn);
|
||||
const removeListener = (el, type, fn) => el.removeEventListener(type, fn);
|
||||
|
||||
const onReady = fn => {
|
||||
const readyPromise = new Promise(resolve => {
|
||||
if (/^(i|c|loade)/.test(doc.readyState)) {
|
||||
fn();
|
||||
resolve();
|
||||
} else {
|
||||
addListener(doc, 'DOMContentLoaded', fn);
|
||||
addListener(doc, 'DOMContentLoaded', () => resolve());
|
||||
}
|
||||
};
|
||||
});
|
||||
const awaitReady = () => readyPromise;
|
||||
|
||||
const onLoad = fn => addListener(win, 'load', fn);
|
||||
const loadPromise = new Promise(resolve => {
|
||||
addListener(win, 'load', () => resolve());
|
||||
});
|
||||
const awaitLoad = () => loadPromise;
|
||||
|
||||
const dom = arg => {
|
||||
if (isInstanceOf(arg, dom)) {
|
||||
@@ -267,7 +271,7 @@ dom.prototype = {
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
onReady,
|
||||
onLoad,
|
||||
awaitReady,
|
||||
awaitLoad,
|
||||
dom
|
||||
};
|
||||
|
Reference in New Issue
Block a user