From 3c3222ddd12f16691e3da7b234066cc5113e3493 Mon Sep 17 00:00:00 2001 From: zeldaroot Date: Wed, 9 Dec 2020 01:46:48 +0200 Subject: [PATCH] Added event load --- views/includes/footer.ejs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/views/includes/footer.ejs b/views/includes/footer.ejs index feceef1..8635206 100644 --- a/views/includes/footer.ejs +++ b/views/includes/footer.ejs @@ -37,15 +37,21 @@ (function() { var dataAllSrc = document.querySelectorAll('[data-cinemapress-src],[data-cinemapress-bg-src]'); var dataAllSrcCount = (dataAllSrc && dataAllSrc.length) || 0; + if (!dataAllSrcCount) return; var dataAllSrcCountComp = 0; var fSrc = { 'dataCountImage': function() { dataAllSrcCountComp = dataAllSrcCountComp+1; if (dataAllSrcCount && dataAllSrcCountComp >= dataAllSrcCount) { dataAllSrcCount = 0; - setTimeout(function() { - fSrc['checkLoad'](dataAllSrc, 'dataSetImage'); - }, 1); + var st; + window.addEventListener('load', function() { + clearTimeout(st); + fSrc['checkLoad']('dataSetImage'); + }); + st = setTimeout(function() { + fSrc['checkLoad']('dataSetImage'); + }, 5000); } }, 'dataSetImage': function(el) { @@ -59,9 +65,9 @@ else { el.style.backgroundImage = 'url("' + bgSrc + '")';} } }, - 'checkLoad': function(els, fn) { - if (!els) return; - els.forEach(function(src) { + 'checkLoad': function(fn) { + if (!dataAllSrc) return; + dataAllSrc.forEach(function(src) { if (typeof src.complete === 'undefined' || src.complete) { fSrc[fn](src); } else { @@ -72,7 +78,7 @@ }); } } - fSrc['checkLoad'](dataAllSrc, 'dataCountImage'); + fSrc['checkLoad']('dataCountImage'); })();