text: ﻿(function(n){"use strict";typeof define=="function"&&define.amd?define(["./blueimp-helper"],n):(window.blueimp=window.blueimp||{},window.blueimp.Gallery=n(window.blueimp.helper||window.jQuery))})(function(n){"use strict";function t(n,i){if(document.body.style.maxHeight===undefined)return null;if(!this||this.options!==t.prototype.options)return new t(n,i);if(!n||!n.length){this.console.log("blueimp Gallery: No or empty list provided as first argument.",n);return}this.list=n;this.num=n.length;this.initOptions(i);this.initialize()}return n.extend(t.prototype,{options:{container:"#blueimp-gallery",slidesContainer:"div",titleElement:"h3",displayClass:"blueimp-gallery-display",controlsClass:"blueimp-gallery-controls",singleClass:"blueimp-gallery-single",leftEdgeClass:"blueimp-gallery-left",rightEdgeClass:"blueimp-gallery-right",playingClass:"blueimp-gallery-playing",slideClass:"slide",slideLoadingClass:"slide-loading",slideErrorClass:"slide-error",slideContentClass:"slide-content",toggleClass:"toggle",prevClass:"prev",nextClass:"next",closeClass:"close",playPauseClass:"play-pause",typeProperty:"type",titleProperty:"title",urlProperty:"href",displayTransition:!0,clearSlides:!0,stretchImages:!1,toggleControlsOnReturn:!0,toggleSlideshowOnSpace:!0,enableKeyboardNavigation:!0,closeOnEscape:!0,closeOnSlideClick:!0,closeOnSwipeUpOrDown:!0,emulateTouchEvents:!0,stopTouchEventsPropagation:!1,hidePageScrollbars:!0,disableScroll:!0,carousel:!1,continuous:!0,unloadElements:!0,startSlideshow:!1,slideshowInterval:5e3,index:0,preloadRange:2,transitionSpeed:400,slideshowTransitionSpeed:undefined,event:undefined,onopen:undefined,onopened:undefined,onslide:undefined,onslideend:undefined,onslidecomplete:undefined,onclose:undefined,onclosed:undefined},carouselOptions:{hidePageScrollbars:!1,toggleControlsOnReturn:!1,toggleSlideshowOnSpace:!1,enableKeyboardNavigation:!1,closeOnEscape:!1,closeOnSlideClick:!1,closeOnSwipeUpOrDown:!1,disableScroll:!1,startSlideshow:!0},console:window.console&&typeof window.console.log=="function"?window.console:{log:function(){}},support:function(t){var i={touch:window.ontouchstart!==undefined||window.DocumentTouch&&document instanceof DocumentTouch},r=function(){var n=i.transition,r,u;document.body.appendChild(t);n&&(r=n.name.slice(0,-9)+"ransform",t.style[r]!==undefined&&(t.style[r]="translateZ(0)",u=window.getComputedStyle(t).getPropertyValue(n.prefix+"transform"),i.transform={prefix:n.prefix,name:r,translate:!0,translateZ:!!u&&u!=="none"}));t.style.backgroundSize!==undefined&&(i.backgroundSize={},t.style.backgroundSize="contain",i.backgroundSize.contain=window.getComputedStyle(t).getPropertyValue("background-size")==="contain",t.style.backgroundSize="cover",i.backgroundSize.cover=window.getComputedStyle(t).getPropertyValue("background-size")==="cover");document.body.removeChild(t)};if(function(n,i){for(var r in i)if(i.hasOwnProperty(r)&&t.style[r]!==undefined){n.transition=i[r];n.transition.name=r;break}}(i,{webkitTransition:{end:"webkitTransitionEnd",prefix:"-webkit-"},MozTransition:{end:"transitionend",prefix:"-moz-"},OTransition:{end:"otransitionend",prefix:"-o-"},transition:{end:"transitionend",prefix:""}}),document.body)r();else n(document).on("DOMContentLoaded",r);return i}(document.createElement("div")),requestAnimationFrame:window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame,initialize:function(){if(this.initStartIndex(),this.initWidget()===!1)return!1;this.initEventListeners();this.onslide(this.index);this.ontransitionend();this.options.startSlideshow&&this.play()},slide:function(n,t){window.clearTimeout(this.timeout);var r=this.index,i,f,u;if(r!==n&&this.num!==1){if(t||(t=this.options.transitionSpeed),this.support.transform){for(this.options.continuous||(n=this.circle(n)),i=Math.abs(r-n)/(r-n),this.options.continuous&&(f=i,i=-this.positions[this.circle(n)]/this.slideWidth,i!==f&&(n=-i*this.num+n)),u=Math.abs(r-n)-1;u;)u-=1,this.move(this.circle((n>r?n:r)-u-1),this.slideWidth*i,0);n=this.circle(n);this.move(r,this.slideWidth*i,t);this.move(n,0,t);this.options.continuous&&this.move(this.circle(n-i),-(this.slideWidth*i),0)}else n=this.circle(n),this.animate(r*-this.slideWidth,n*-this.slideWidth,t);this.onslide(n)}},getIndex:function(){return this.index},getNumber:function(){return this.num},prev:function(){(this.options.continuous||this.index)&&this.slide(this.index-1)},next:function(){(this.options.continuous||this.index<this.num-1)&&this.slide(this.index+1)},play:function(n){var t=this;window.clearTimeout(this.timeout);this.interval=n||this.options.slideshowInterval;this.elements[this.index]>1&&(this.timeout=this.setTimeout(!this.requestAnimationFrame&&this.slide||function(n,i){t.animationFrameId=t.requestAnimationFrame.call(window,function(){t.slide(n,i)})},[this.index+1,this.options.slideshowTransitionSpeed],this.interval));this.container.addClass(this.options.playingClass)},pause:function(){window.clearTimeout(this.timeout);this.interval=null;this.container.removeClass(this.options.playingClass)},add:function(n){var t;for(n.concat||(n=Array.prototype.slice.call(n)),this.list.concat||(this.list=Array.prototype.slice.call(this.list)),this.list=this.list.concat(n),this.num=this.list.length,this.num>2&&this.options.continuous===null&&(this.options.continuous=!0,this.container.removeClass(this.options.leftEdgeClass)),this.container.removeClass(this.options.rightEdgeClass).removeClass(this.options.singleClass),t=this.num-n.length;t<this.num;t+=1)this.addSlide(t),this.positionSlide(t);this.positions.length=this.num;this.initSlides(!0)},resetSlides:function(){this.slidesContainer.empty();this.slides=[]},handleClose:function(){var n=this.options;this.destroyEventListeners();this.pause();this.container[0].style.display="none";this.container.removeClass(n.displayClass).removeClass(n.singleClass).removeClass(n.leftEdgeClass).removeClass(n.rightEdgeClass);n.hidePageScrollbars&&(document.body.style.overflow=this.bodyOverflowStyle);this.options.clearSlides&&this.resetSlides();this.options.onclosed&&this.options.onclosed.call(this)},close:function(){var n=this,t=function(i){i.target===n.container[0]&&(n.container.off(n.support.transition.end,t),n.handleClose())};if(this.options.onclose&&this.options.onclose.call(this),this.support.transition&&this.options.displayTransition){this.container.on(this.support.transition.end,t);this.container.removeClass(this.options.displayClass)}else this.handleClose()},circle:function(n){return(this.num+n%this.num)%this.num},move:function(n,t,i){this.translateX(n,t,i);this.positions[n]=t},translate:function(n,t,i,r){var u=this.slides[n].style,e=this.support.transition,f=this.support.transform;u[e.name+"Duration"]=r+"ms";u[f.name]="translate("+t+"px, "+i+"px)"+(f.translateZ?" translateZ(0)":"")},translateX:function(n,t,i){this.translate(n,t,0,i)},translateY:function(n,t,i){this.translate(n,0,t,i)},animate:function(n,t,i){if(!i){this.slidesContainer[0].style.left=t+"px";return}var r=this,u=(new Date).getTime(),f=window.setInterval(function(){var e=(new Date).getTime()-u;if(e>i){r.slidesContainer[0].style.left=t+"px";r.ontransitionend();window.clearInterval(f);return}r.slidesContainer[0].style.left=(t-n)*(Math.floor(e/i*100)/100)+n+"px"},4)},preventDefault:function(n){n.preventDefault?n.preventDefault():n.returnValue=!1},stopPropagation:function(n){n.stopPropagation?n.stopPropagation():n.cancelBubble=!0},onresize:function(){this.initSlides(!0)},onmousedown:function(n){if(n.which&&n.which===1&&n.target.nodeName!=="VIDEO"){n.preventDefault();(n.originalEvent||n).touches=[{pageX:n.pageX,pageY:n.pageY}];this.ontouchstart(n)}},onmousemove:function(n){if(this.touchStart){(n.originalEvent||n).touches=[{pageX:n.pageX,pageY:n.pageY}];this.ontouchmove(n)}},onmouseup:function(n){if(this.touchStart){this.ontouchend(n);delete this.touchStart}},onmouseout:function(t){if(this.touchStart){var r=t.target,i=t.relatedTarget;if(!i||i!==r&&!n.contains(r,i))this.onmouseup(t)}},ontouchstart:function(n){this.options.stopTouchEventsPropagation&&this.stopPropagation(n);var t=(n.originalEvent||n).touches[0];this.touchStart={x:t.pageX,y:t.pageY,time:Date.now()};this.isScrolling=undefined;this.touchDelta={}},ontouchmove:function(n){this.options.stopTouchEventsPropagation&&this.stopPropagation(n);var u=(n.originalEvent||n).touches[0],f=(n.originalEvent||n).scale,t=this.index,i,r;if(!(u.length>1)&&(!f||f===1))if(this.options.disableScroll&&n.preventDefault(),this.touchDelta={x:u.pageX-this.touchStart.x,y:u.pageY-this.touchStart.y},i=this.touchDelta.x,this.isScrolling===undefined&&(this.isScrolling=this.isScrolling||Math.abs(i)<Math.abs(this.touchDelta.y)),this.isScrolling)this.options.closeOnSwipeUpOrDown&&this.translateY(t,this.touchDelta.y+this.positions[t],0);else for(n.preventDefault(),window.clearTimeout(this.timeout),this.options.continuous?r=[this.circle(t+1),t,this.circle(t-1)]:(this.touchDelta.x=i=i/(!t&&i>0||t===this.num-1&&i<0?Math.abs(i)/this.slideWidth+1:1),r=[t],t&&r.push(t-1),t<this.num-1&&r.unshift(t+1));r.length;)t=r.pop(),this.translateX(t,i+this.positions[t],0)},ontouchend:function(n){this.options.stopTouchEventsPropagation&&this.stopPropagation(n);var t=this.index,i=this.options.transitionSpeed,r=this.slideWidth,s=Number(Date.now()-this.touchStart.time)<250,h=s&&Math.abs(this.touchDelta.x)>20||Math.abs(this.touchDelta.x)>r/2,c=!t&&this.touchDelta.x>0||t===this.num-1&&this.touchDelta.x<0,a=!h&&this.options.closeOnSwipeUpOrDown&&(s&&Math.abs(this.touchDelta.y)>20||Math.abs(this.touchDelta.y)>this.slideHeight/2),u,f,o,e,l;if(this.options.continuous&&(c=!1),u=this.touchDelta.x<0?-1:1,this.isScrolling)a?this.close():this.translateY(t,0,i);else if(h&&!c){f=t+u;o=t-u;e=r*u;l=-r*u;this.options.continuous?(this.move(this.circle(f),e,0),this.move(this.circle(t-2*u),l,0)):f>=0&&f<this.num&&this.move(f,e,0);this.move(t,this.positions[t]+e,i);this.move(this.circle(o),this.positions[this.circle(o)]+e,i);t=this.circle(o);this.onslide(t)}else this.options.continuous?(this.move(this.circle(t-1),-r,i),this.move(t,0,i),this.move(this.circle(t+1),r,i)):(t&&this.move(t-1,-r,i),this.move(t,0,i),t<this.num-1&&this.move(t+1,r,i))},ontouchcancel:function(n){if(this.touchStart){this.ontouchend(n);delete this.touchStart}},ontransitionend:function(n){var t=this.slides[this.index];n&&t!==n.target||(this.interval&&this.play(),this.setTimeout(this.options.onslideend,[this.index,t]))},oncomplete:function(t){var r=t.target||t.srcElement,i=r&&r.parentNode,u;r&&i&&(u=this.getNodeIndex(i),n(i).removeClass(this.options.slideLoadingClass),t.type==="error"?(n(i).addClass(this.options.slideErrorClass),this.elements[u]=3):this.elements[u]=2,r.clientHeight>this.container[0].clientHeight&&(r.style.maxHeight=this.container[0].clientHeight),this.interval&&this.slides[this.index]===i&&this.play(),this.setTimeout(this.options.onslidecomplete,[u,i]))},onload:function(n){this.oncomplete(n)},onerror:function(n){this.oncomplete(n)},onkeydown:function(n){switch(n.which||n.keyCode){case 13:this.options.toggleControlsOnReturn&&(this.preventDefault(n),this.toggleControls());break;case 27:this.options.closeOnEscape&&this.close();break;case 32:this.options.toggleSlideshowOnSpace&&(this.preventDefault(n),this.toggleSlideshow());break;case 37:this.options.enableKeyboardNavigation&&(this.preventDefault(n),this.prev());break;case 39:this.options.enableKeyboardNavigation&&(this.preventDefault(n),this.next())}},handleClick:function(t){var i=this.options,f=t.target||t.srcElement,u=f.parentNode,r=function(t){return n(f).hasClass(t)||n(u).hasClass(t)};r(i.toggleClass)?(this.preventDefault(t),this.toggleControls()):r(i.prevClass)?(this.preventDefault(t),this.prev()):r(i.nextClass)?(this.preventDefault(t),this.next()):r(i.closeClass)?(this.preventDefault(t),this.close()):r(i.playPauseClass)?(this.preventDefault(t),this.toggleSlideshow()):u===this.slidesContainer[0]?(this.preventDefault(t),i.closeOnSlideClick?this.close():this.toggleControls()):u.parentNode&&u.parentNode===this.slidesContainer[0]&&(this.preventDefault(t),this.toggleControls())},onclick:function(n){if(this.options.emulateTouchEvents&&this.touchDelta&&(Math.abs(this.touchDelta.x)>20||Math.abs(this.touchDelta.y)>20)){delete this.touchDelta;return}return this.handleClick(n)},updateEdgeClasses:function(n){n?this.container.removeClass(this.options.leftEdgeClass):this.container.addClass(this.options.leftEdgeClass);n===this.num-1?this.container.addClass(this.options.rightEdgeClass):this.container.removeClass(this.options.rightEdgeClass)},handleSlide:function(n){this.options.continuous||this.updateEdgeClasses(n);this.loadElements(n);this.options.unloadElements&&this.unloadElements(n);this.setTitle(n)},onslide:function(n){this.index=n;this.handleSlide(n);this.setTimeout(this.options.onslide,[n,this.slides[n]])},setTitle:function(n){var t=this.slides[n].firstChild.title,i=this.titleElement;i.length&&(this.titleElement.empty(),t&&i[0].appendChild(document.createTextNode(t)))},setTimeout:function(n,t,i){var r=this;return n&&window.setTimeout(function(){n.apply(r,t||[])},i||0)},imageFactory:function(t,i){var c=this,f=this.imagePrototype.cloneNode(!1),e=t,r=this.options.stretchImages,h,u,o=function(t){if(!h){if(t={type:t.type,target:u},!u.parentNode)return c.setTimeout(o,[t]);h=!0;n(f).off("load error",o);r&&t.type==="load"&&(u.style.background='url("'+e+'") center no-repeat',u.style.backgroundSize=r);i(t)}},s;typeof e!="string"&&(e=this.getItemProperty(t,this.options.urlProperty),s=this.getItemProperty(t,this.options.titleProperty));r===!0&&(r="contain");r=this.support.backgroundSize&&this.support.backgroundSize[r]&&r;r?u=this.elementPrototype.cloneNode(!1):(u=f,f.draggable=!1);s&&(u.title=s);n(f).on("load error",o);return f.src=e,u},createElement:function(t,i){var u=t&&this.getItemProperty(t,this.options.typeProperty),f=u&&this[u.split("/")[0]+"Factory"]||this.imageFactory,r=t&&f.call(this,t,i);return r||(r=this.elementPrototype.cloneNode(!1),this.setTimeout(i,[{type:"error",target:r}])),n(r).addClass(this.options.slideContentClass),r},loadElement:function(t){this.elements[t]||(this.slides[t].firstChild?this.elements[t]=n(this.slides[t]).hasClass(this.options.slideErrorClass)?3:2:(this.elements[t]=1,n(this.slides[t]).addClass(this.options.slideLoadingClass),this.slides[t].appendChild(this.createElement(this.list[t],this.proxyListener))))},loadElements:function(n){for(var r=Math.min(this.num,this.options.preloadRange*2+1),i=n,t=0;t<r;t+=1)i+=t*(t%2==0?-1:1),i=this.circle(i),this.loadElement(i)},unloadElements:function(n){var t,i,r;for(t in this.elements)this.elements.hasOwnProperty(t)&&(r=Math.abs(n-t),r>this.options.preloadRange&&r+this.options.preloadRange<this.num&&(i=this.slides[t],i.removeChild(i.firstChild),delete this.elements[t]))},addSlide:function(n){var t=this.slidePrototype.cloneNode(!1);t.setAttribute("data-index",n);this.slidesContainer[0].appendChild(t);this.slides.push(t)},positionSlide:function(n){var t=this.slides[n];t.style.width=this.slideWidth+"px";this.support.transform&&(t.style.left=n*-this.slideWidth+"px",this.move(n,this.index>n?-this.slideWidth:this.index<n?this.slideWidth:0,0))},initSlides:function(t){var r,i;for(t||(this.positions=[],this.positions.length=this.num,this.elements={},this.imagePrototype=document.createElement("img"),this.elementPrototype=document.createElement("div"),this.slidePrototype=document.createElement("div"),n(this.slidePrototype).addClass(this.options.slideClass),this.slides=this.slidesContainer[0].children,r=this.options.clearSlides||this.slides.length!==this.num),this.slideWidth=this.container[0].offsetWidth,this.slideHeight=this.container[0].offsetHeight,this.slidesContainer[0].style.width=this.num*this.slideWidth+"px",r&&this.resetSlides(),i=0;i<this.num;i+=1)r&&this.addSlide(i),this.positionSlide(i);this.options.continuous&&this.support.transform&&(this.move(this.circle(this.index-1),-this.slideWidth,0),this.move(this.circle(this.index+1),this.slideWidth,0));this.support.transform||(this.slidesContainer[0].style.left=this.index*-this.slideWidth+"px")},toggleControls:function(){var n=this.options.controlsClass;this.container.hasClass(n)?this.container.removeClass(n):this.container.addClass(n)},toggleSlideshow:function(){this.interval?this.pause():this.play()},getNodeIndex:function(n){return parseInt(n.getAttribute("data-index"),10)},getNestedProperty:function(n,t){return t.replace(/\[(?:'([^']+)'|"([^"]+)"|(\d+))\]|(?:(?:^|\.)([^\.\[]+))/g,function(t,i,r,u,f){var e=f||i||r||u&&parseInt(u,10);t&&n&&(n=n[e])}),n},getDataProperty:function(t,i){if(t.getAttribute){var r=t.getAttribute("data-"+i.replace(/([A-Z])/g,"-$1").toLowerCase());if(typeof r=="string"){if(/^(true|false|null|-?\d+(\.\d+)?|\{[\s\S]*\}|\[[\s\S]*\])$/.test(r))try{return n.parseJSON(r)}catch(u){}return r}}},getItemProperty:function(n,t){var i=n[t];return i===undefined&&(i=this.getDataProperty(n,t),i===undefined&&(i=this.getNestedProperty(n,t))),i},initStartIndex:function(){var n=this.options.index,i=this.options.urlProperty,t;if(n&&typeof n!="number")for(t=0;t<this.num;t+=1)if(this.list[t]===n||this.getItemProperty(this.list[t],i)===this.getItemProperty(n,i)){n=t;break}this.index=this.circle(parseInt(n,10)||0)},initEventListeners:function(){var i=this,r=this.slidesContainer,t=function(n){var t=i.support.transition&&i.support.transition.end===n.type?"transitionend":n.type;i["on"+t](n)};n(window).on("resize",t);n(document.body).on("keydown",t);this.container.on("click",t);if(this.support.touch)r.on("touchstart touchmove touchend touchcancel",t);else if(this.options.emulateTouchEvents&&this.support.transition)r.on("mousedown mousemove mouseup mouseout",t);if(this.support.transition)r.on(this.support.transition.end,t);this.proxyListener=t},destroyEventListeners:function(){var i=this.slidesContainer,t=this.proxyListener;n(window).off("resize",t);n(document.body).off("keydown",t);this.container.off("click",t);this.support.touch?i.off("touchstart touchmove touchend touchcancel",t):this.options.emulateTouchEvents&&this.support.transition&&i.off("mousedown mousemove mouseup mouseout",t);this.support.transition&&i.off(this.support.transition.end,t)},handleOpen:function(){this.options.onopened&&this.options.onopened.call(this)},initWidget:function(){var t=this,i=function(n){n.target===t.container[0]&&(t.container.off(t.support.transition.end,i),t.handleOpen())};if(this.container=n(this.options.container),!this.container.length)return this.console.log("blueimp Gallery: Widget container not found.",this.options.container),!1;if(this.slidesContainer=this.container.find(this.options.slidesContainer).first(),!this.slidesContainer.length)return this.console.log("blueimp Gallery: Slides container not found.",this.options.slidesContainer),!1;if(this.titleElement=this.container.find(this.options.titleElement).first(),this.num===1&&this.container.addClass(this.options.singleClass),this.options.onopen&&this.options.onopen.call(this),this.support.transition&&this.options.displayTransition)this.container.on(this.support.transition.end,i);else this.handleOpen();this.options.hidePageScrollbars&&(this.bodyOverflowStyle=document.body.style.overflow,document.body.style.overflow="hidden");this.container[0].style.display="block";this.initSlides();this.container.addClass(this.options.displayClass)},initOptions:function(t){this.options=n.extend({},this.options);(t&&t.carousel||this.options.carousel&&(!t||t.carousel!==!1))&&n.extend(this.options,this.carouselOptions);n.extend(this.options,t);this.num<3&&(this.options.continuous=this.options.continuous?null:!1);this.support.transition||(this.options.emulateTouchEvents=!1);this.options.event&&this.preventDefault(this.options.event)}}),t});