From a0488a2015e11d800c2fd9a91005da63cf8d08e4 Mon Sep 17 00:00:00 2001 From: Josef Kufner Date: Mon, 27 Mar 2017 14:00:50 +0200 Subject: [PATCH] Add preloadAfterLoad option to postpone preloading after the current image is fully loaded Fixes #75 --- src/js/gallery.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/js/gallery.js b/src/js/gallery.js index f73d68c7..6727c6a3 100644 --- a/src/js/gallery.js +++ b/src/js/gallery.js @@ -20,6 +20,7 @@ $.magnificPopup.registerModule('gallery', { enabled: false, arrowMarkup: '', preload: [0,2], + preloadAfterLoad: false, navigateByImgClick: true, arrows: true, @@ -89,14 +90,21 @@ $.magnificPopup.registerModule('gallery', { }); _mfpOn(CHANGE_EVENT+ns, function() { - if(mfp._preloadTimeout) clearTimeout(mfp._preloadTimeout); + if (!gSt.preloadAfterLoad) { + if(mfp._preloadTimeout) clearTimeout(mfp._preloadTimeout); - mfp._preloadTimeout = setTimeout(function() { - mfp.preloadNearbyImages(); - mfp._preloadTimeout = null; - }, 16); + mfp._preloadTimeout = setTimeout(function() { + mfp.preloadNearbyImages(); + mfp._preloadTimeout = null; + }, 16); + } }); + _mfpOn('ImageLoadComplete', function() { + if (gSt.preloadAfterLoad) { + mfp.preloadNearbyImages(); + } + }); _mfpOn(CLOSE_EVENT+ns, function() { _document.off(ns); @@ -161,4 +169,4 @@ $.magnificPopup.registerModule('gallery', { item.preloaded = true; } } -}); \ No newline at end of file +});