From e8e6a0906702dc7b569ef4f0b2d9486d772ba562 Mon Sep 17 00:00:00 2001 From: Minteck Date: Sun, 31 Oct 2021 11:49:13 +0100 Subject: Initial commit --- js/iframe.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 js/iframe.js (limited to 'js/iframe.js') 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 -- cgit