/** * Image LightBox - A touch-friendly image lightbox, without bells and whistles. * @version v0.2.0 * @link https://victorhaggqvist.github.io/touch-imagelightbox * @license MIT * @author Victor Häggqvist (https://victorhaggqvist.com/) */ var LightBox=LightBox||{};LightBox.Core=function(t){function e(n){if(i[n])return i[n].exports;var o=i[n]={exports:{},id:n,loaded:!1};return t[n].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var i={};return e.m=t,e.c=i,e.p="",e(0)}([function(t,e,i){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var o=function(){function t(t,e){for(var i=0;ithis.targets.length-1?this.target=this.targets[0]:0>e?this.target=this.targets[this.targets.length-1]:this.target=this.targets[e],this.loadImage()}}},{key:"documentClick",value:function(){a.debug("document click"),null!==this.image&&this.target.href===this.image.src&&(a.info("quitting"),this.options.quitOnDocClick&&this.quitLightbox())}},{key:"quitLightbox",value:function(){var t=this;a.debug("quitLightbox"),null!==this.image&&(r.CSSUtil.setTransitionProperty(this.image,"opacity "+this.options.animationSpeed/1e3+"s linear"),setTimeout(function(){t.image.style.opacity=0},5),setTimeout(function(){t.removeImage(),t.inProgress=!1,t.onEndListeners.forEach(function(t){return t()})},this.options.animationSpeed))}},{key:"onImageClick",value:function(t){a.debug(t);var e=t.srcElement.parentElement;return this.isTargetValid(e)?(t.preventDefault(),void(this.inProgress||(this.inProgress=!1,this.onStartListeners.forEach(function(t){return t()}),this.target=e,this.loadImage()))):!0}},{key:"isTargetValid",value:function(t){if(this.options.restrictTypes===!1)return!0;var e=new RegExp("(.("+this.options.allowedTypes+")$)");return"a"===t.tagName.toLowerCase()&&e.test(t.href)}},{key:"loadImage",value:function(){var e=this,i=arguments.length<=0||void 0===arguments[0]?!1:arguments[0];if(a.info("loadImage"),this.inProgress)return!1;if(a.debug("not progress"),null!==this.image){if(a.debug("has current image"),i!==!1&&(this.targets.length<2||this.options.quitOnEnd===!0&&(i===s.LightDirection.RIGHT&&0===Array.prototype.indexOf(this.targets,this.target)||i===s.LightDirection.LEFT&&Array.prototype.indexOf(this.targets,this.target)===targets.length-1)))return this.quitLightbox(),!1;a.debug("unload"),r.CSSUtil.setTransitionProperty(this.image,"opacity "+this.options.animationSpeed/1e3+"s linear");var n="0px";i!==!1&&(n=100*i-this.swipeDiff+"px"),this.image.style.transform="translateX("+n+")",setTimeout(function(){e.image.style.opacity=0},5),setTimeout(function(){a.debug("remove from dom"),e.removeImage()},this.options.animationSpeed),this.swipeDiff=0}this.inProgress=!0,this.onLoadStartListeners.forEach(function(t){return t()}),setTimeout(function(){a.debug("loadImage in");var i=new Image;e.image=i,i.onload=function(){i.id=e.options.selectorId,a.debug("img loaded"),document.body.appendChild(i),e.setImage(),i.style.opacity=0;var t=e.options.animationSpeed/1e3;if(a.debug(t),r.CSSUtil.setTransitionProperty(i,"opacity "+t+"s ease"),i.style.transform="translateX(0px)",setTimeout(function(){i.style.opacity=1},10),setTimeout(function(){e.inProgress=!1,e.onLoadEndListeners.forEach(function(t){return t()})},e.options.animationSpeed),e.options.preloadNext){var n=Array.prototype.indexOf.call(e.targets,e.target),o=e.targets[n+1];if(null!==o&&void 0!==o){a.debug("preloading next");var s=new Image;s.src=o.href}else a.debug("no preloading")}},i.src=e.target.href,e.swipeStart=0,e.swipeEnd=0,t.HAS_POINTERS?(i.addEventListener("pointerup",e.imageClickEvent.bind(e)),i.addEventListener("MSPointerUp",e.imageClickEvent.bind(e))):i.addEventListener("click",e.imageClickEvent.bind(e)),["touchstart","pointerdown","MSPointerDown"].forEach(function(t){i.addEventListener(t,e.imageTouchStart.bind(e))}),["touchmove","pointermove","MSPointerMove"].forEach(function(t){i.addEventListener(t,e.imageTouchMove.bind(e))}),["touchend","touchcancel","pointerup","MSPointerUp"].forEach(function(t){i.addEventListener(t,e.imageTouchEnd.bind(e))})},this.options.animationSpeed+100)}},{key:"removeImage",value:function(){var t=document.querySelector("#"+this.options.selectorId);document.body.removeChild(t),this.image=null}},{key:"imageClickEvent",value:function(t){if(t.preventDefault(),a.debug("click"),this.options.quitOnImgClick)return this.quitLightbox(),!1;if(this.wasTouched(t))return!0;var e=t.pageX-t.target.offsetLeft;a.debug(e);var i=Array.prototype.indexOf.call(this.targets,this.target)-(this.imageWidth/2>e?1:-1);i>this.targets.length-1?this.target=this.targets[0]:0>i?this.target=this.targets[this.targets.length-1]:this.target=this.targets[i],this.loadImage()}},{key:"imageTouchStart",value:function(t){return!this.wasTouched(t)||this.options.quitOnImgClick?!0:void(this.swipeStart=t.pageX||t.touches[0].pageX)}},{key:"imageTouchMove",value:function(t){return!this.wasTouched(t)||this.options.quitOnImgClick?!0:(t.preventDefault(),this.swipeEnd=t.pageX||t.touches[0].pageX,this.swipeDiff=this.swipeStart-this.swipeEnd,void(this.image.style.transform="translateX("+-this.swipeDiff+"px)"))}},{key:"imageTouchEnd",value:function(t){if(!this.wasTouched(t)||this.options.quitOnImgClick)return!0;if(a.debug(this.swipeDiff),Math.abs(this.swipeDiff)>50){var e=Array.prototype.indexOf.call(this.targets,this.target)-(this.swipeDiff<0?1:-1);e>this.targets.length-1?this.target=this.targets[0]:0>e?this.target=this.targets[this.targets.length-1]:this.target=this.targets[e];var i=this.swipeDiff>0?s.LightDirection.RIGHT:s.LightDirection.LEFT;this.loadImage(i)}else this.image.style.transform="translateX(0px)"}},{key:"setImage",value:function(){var t=this;if(!this.image)return!1;var e=.8*window.innerWidth,i=.9*window.innerHeight,n=new Image;n.src=this.image.src,n.onload=function(){if(t.imageWidth=n.width,t.imageHeight=n.height,t.imageWidth>e||t.imageHeight>i){var o=t.imageWidth/t.imageHeight>e/i?t.imageWidth/e:t.imageHeight/i;t.imageWidth/=o,t.imageHeight/=o}t.image.style.width=t.imageWidth+"px",t.image.style.height=t.imageHeight+"px",t.image.style.top=(window.innerHeight-t.imageHeight)/2+"px",t.image.style.left=(window.innerWidth-t.imageWidth)/2+"px"}}},{key:"wasTouched",value:function(e){if(t.HAS_TOUCH)return!0;if(!t.HAS_POINTERS||"undefined"==typeof e||"undefined"==typeof e.pointerType)return!1;if("undefined"!=typeof e.MSPOINTER_TYPE_MOUSE){if(e.MSPOINTER_TYPE_MOUSE!==e.pointerType)return!0}else if("mouse"!==e.pointerType)return!0;return!1}},{key:"switchToIndex",value:function(t){t>=0&&ti?a:this.methodFactory(n,t,e)}}function o(e,n,o){return t(e)||i.apply(this,arguments)}function s(t,e,i){function s(t){var e=(l[t]||"silent").toUpperCase();try{return void(window.localStorage[h]=e)}catch(i){}try{window.document.cookie=encodeURIComponent(h)+"="+e+";"}catch(i){}}function a(){var t;try{t=window.localStorage[h]}catch(e){}if(("undefined"==typeof t?"undefined":r(t))===u)try{var i=window.document.cookie,n=i.indexOf(encodeURIComponent(h)+"=");n&&(t=/^([^;]+)/.exec(i.slice(n))[1])}catch(e){}return void 0===c.levels[t]&&(t=void 0),t}var d,c=this,h="loglevel";t&&(h+=":"+t),c.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},c.methodFactory=i||o,c.getLevel=function(){return d},c.setLevel=function(e,i){if("string"==typeof e&&void 0!==c.levels[e.toUpperCase()]&&(e=c.levels[e.toUpperCase()]),!("number"==typeof e&&e>=0&&e<=c.levels.SILENT))throw"log.setLevel() called with invalid level: "+e;return d=e,i!==!1&&s(e),n.call(c,e,t),("undefined"==typeof console?"undefined":r(console))===u&&e