summaryrefslogtreecommitdiff
path: root/js/iframe.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/iframe.js')
-rwxr-xr-xjs/iframe.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/js/iframe.js b/js/iframe.js
new file mode 100755
index 0000000..a031872
--- /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