skip already queued in onDOMscripted
This commit is contained in:
parent
c15082fed4
commit
b91324992d
11
js/dom.js
11
js/dom.js
|
@ -68,14 +68,15 @@ function onDOMready() {
|
||||||
|
|
||||||
|
|
||||||
function onDOMscripted(scripts) {
|
function onDOMscripted(scripts) {
|
||||||
|
const queue = onDOMscripted.queue = onDOMscripted.queue || [];
|
||||||
if (scripts) {
|
if (scripts) {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
addResolver(resolve);
|
addResolver(resolve);
|
||||||
onDOMscripted.scriptQueue = scripts;
|
queue.push(...scripts.filter(el => !queue.includes(el)));
|
||||||
loadNextScript();
|
loadNextScript();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (onDOMscripted.scriptQueue) {
|
if (queue.length) {
|
||||||
return new Promise(resolve => addResolver(resolve));
|
return new Promise(resolve => addResolver(resolve));
|
||||||
}
|
}
|
||||||
if (document.readyState !== 'loading') {
|
if (document.readyState !== 'loading') {
|
||||||
|
@ -88,9 +89,9 @@ function onDOMscripted(scripts) {
|
||||||
return onDOMready().then(onDOMscripted);
|
return onDOMready().then(onDOMscripted);
|
||||||
|
|
||||||
function loadNextScript() {
|
function loadNextScript() {
|
||||||
const next = onDOMscripted.scriptQueue.shift();
|
const empty = !queue.length;
|
||||||
if (!next) {
|
const next = !empty && queue.shift();
|
||||||
onDOMscripted.scriptQueue = null;
|
if (empty) {
|
||||||
onDOMscripted();
|
onDOMscripted();
|
||||||
} else if (typeof next === 'function') {
|
} else if (typeof next === 'function') {
|
||||||
Promise.resolve(next())
|
Promise.resolve(next())
|
||||||
|
|
Loading…
Reference in New Issue
Block a user