diff options
author | Minteck <minteck@phoenixnet.tech> | 2021-10-31 11:49:13 +0100 |
---|---|---|
committer | Minteck <minteck@phoenixnet.tech> | 2021-10-31 11:49:13 +0100 |
commit | e8e6a0906702dc7b569ef4f0b2d9486d772ba562 (patch) | |
tree | fb1361db2820ee7182c5023f6fa03237c8f46367 /js/iframe.js | |
download | core-e8e6a0906702dc7b569ef4f0b2d9486d772ba562.tar.gz core-e8e6a0906702dc7b569ef4f0b2d9486d772ba562.tar.bz2 core-e8e6a0906702dc7b569ef4f0b2d9486d772ba562.zip |
Initial commit
Diffstat (limited to 'js/iframe.js')
-rw-r--r-- | js/iframe.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/js/iframe.js b/js/iframe.js new file mode 100644 index 0000000..415f095 --- /dev/null +++ b/js/iframe.js @@ -0,0 +1,48 @@ +function iframeURLChange(iframe, callback) { + var unloadHandler = function () { + setTimeout(function () { + callback(iframe.contentWindow.location.href); + }, 0); + }; + + function attachUnload() { + iframe.contentWindow.removeEventListener("pagehide", unloadHandler); + iframe.contentWindow.addEventListener("pagehide", unloadHandler); + iframe.contentWindow.removeEventListener("unload", unloadHandler); + iframe.contentWindow.addEventListener("unload", unloadHandler); + } + + iframe.addEventListener("load", attachUnload); + attachUnload(); +} + +Array.from(document.getElementsByTagName("iframe")).forEach((par) => { + iframeURLChange(par, function (newURL) { + $(".loader").fadeIn(200); + }); +}) + +function unload() { + $(".loader").fadeIn(200); +} + +Array.from(document.getElementsByTagName("iframe")).forEach((par) => { + par.onbeforeunload = unload +}) + +function loaded () { + $(".loader").fadeOut(200); + + setTimeout(() => { + $(".loader").fadeOut(200); + }, 300) + + setTimeout(() => { + $(".loader").fadeOut(200); + }, 1500); +} + +Array.from(document.getElementsByTagName("iframe")).forEach((par) => { + par.onload = loaded; + par.onabort = loaded; +})
\ No newline at end of file |