sync
This commit is contained in:
@ -109,6 +109,20 @@ function applyLanguage(dom, result) {
|
||||
}
|
||||
}
|
||||
|
||||
export function domLoad() {
|
||||
if (document.readyState === 'loading') {
|
||||
return new Promise((resolve, reject) => {
|
||||
let tid = setTimeout(() => reject('timeout'), 30000);
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
clearTimeout(tid);
|
||||
tid = void 0;
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
export async function init(dom = document.body, options = {}) {
|
||||
const lgid = getCurrentLgId();
|
||||
let lgres = localStorage.getItem(getStorageKey(lgid));
|
||||
@ -126,20 +140,7 @@ export async function init(dom = document.body, options = {}) {
|
||||
}
|
||||
|
||||
try {
|
||||
if (document.readyState === 'loading') {
|
||||
return await new Promise((resolve, reject) => {
|
||||
let tid = setTimeout(() => reject('timeout'), 30000);
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
clearTimeout(tid);
|
||||
tid = void 0;
|
||||
if (typeof options.callback === 'function') {
|
||||
options.callback(result);
|
||||
}
|
||||
applyLanguage(dom, result);
|
||||
resolve(result);
|
||||
});
|
||||
});
|
||||
}
|
||||
await domLoad();
|
||||
if (typeof options.callback === 'function') {
|
||||
options.callback(result);
|
||||
}
|
||||
|
Reference in New Issue
Block a user