Fix "onload" events to support multiple
This commit is contained in:
parent
20b2da9cd0
commit
85a88000a7
2 changed files with 21 additions and 4 deletions
|
@ -1,5 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
window.onload = function () {
|
|
||||||
|
function bindKey() {
|
||||||
const adminLinkElement = document.querySelector("a#admin-link");
|
const adminLinkElement = document.querySelector("a#admin-link");
|
||||||
if (adminLinkElement === undefined || adminLinkElement === null) {
|
if (adminLinkElement === undefined || adminLinkElement === null) {
|
||||||
return;
|
return;
|
||||||
|
@ -11,3 +12,11 @@ window.onload = function () {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
((readyState) => {
|
||||||
|
if (readyState === "interactive") {
|
||||||
|
bindKey();
|
||||||
|
} else if (readyState === "loading") {
|
||||||
|
window.addEventListener("DOMContentLoaded", bindKey, false);
|
||||||
|
}
|
||||||
|
})(document.readyState);
|
||||||
|
|
|
@ -1,11 +1,19 @@
|
||||||
let preview = null;
|
let preview = null;
|
||||||
|
|
||||||
window.onload = function () {
|
function onLoad () {
|
||||||
const previewButton = document.querySelector("input#_live_preview");
|
const previewButton = document.querySelector("input#_live_preview");
|
||||||
if (previewButton) {
|
if (previewButton) {
|
||||||
previewButton.addEventListener("click", openPreviewPopup);
|
previewButton.addEventListener("click", openPreviewPopup);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
((readyState) => {
|
||||||
|
if (readyState === "interactive") {
|
||||||
|
onLoad();
|
||||||
|
} else if (readyState === "loading") {
|
||||||
|
window.addEventListener("DOMContentLoaded", onLoad, false);
|
||||||
|
}
|
||||||
|
})(document.readyState);
|
||||||
|
|
||||||
window.onbeforeunload = function () {
|
window.onbeforeunload = function () {
|
||||||
if (preview !== null) {
|
if (preview !== null) {
|
||||||
preview.close();
|
preview.close();
|
||||||
|
|
Reference in a new issue