From 110d9168750a71fdde26b5fa95bf759e6bc212ae Mon Sep 17 00:00:00 2001 From: Stav Geffen Date: Sat, 2 Jul 2016 22:51:11 +0300 Subject: [PATCH] Added loader hooks, fixed #10 --- intense.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/intense.js b/intense.js index ea495f1..d235d1f 100644 --- a/intense.js +++ b/intense.js @@ -47,6 +47,11 @@ var Intense = (function() { var active = false; + var loader = { + start: function(){}, + stop: function(){} + }; + /* ------------------------- /* UTILS /* -------------------------*/ @@ -299,8 +304,12 @@ var Intense = (function() { loop(); setState(element, 'viewing'); + + loader.stop(); } + loader.start(); + img.src = imageSource; } @@ -383,6 +392,22 @@ var Intense = (function() { function config(options){ if ('invertInteractionDirection' in options) invertInteractionDirection = options.invertInteractionDirection; + + if ('loader' in options){ + if (invalidProperties()){ + throw 'You need to pass callback functions under "start" and "stop" properties!'; + } + + loader = options.loader; + } + + function invalidProperties(){ + if (options.loader.start && typeof(options.loader.start) === 'function' + && options.loader.stop && typeof(options.loader.stop) === 'function') return false; + + return true; + } + } function main( element, configOptions ) {