viewer.js 26.2 KB
/*!
 * Viewer.js v0.8.0
 * https://github.com/fengyuanchen/viewerjs
 *
 * Copyright (c) 2015-2017 Fengyuan Chen
 * Released under the MIT license
 *
 * Date: 2017-10-08T11:45:00.656Z
 */
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.Viewer=e()}(this,function(){"use strict";function t(t){return"string"==typeof t}function e(t){return"number"==typeof t&&!V(t)}function i(t){return void 0===t}function n(t){return"object"===(void 0===t?"undefined":H(t))&&null!==t}function s(t){if(!n(t))return!1;try{var e=t.constructor,i=e.prototype;return e&&i&&B.call(i,"isPrototypeOf")}catch(t){return!1}}function o(t){return"function"==typeof t}function a(t,i){if(t&&o(i))if(Array.isArray(t)||e(t.length)){var s=t.length,a=void 0;for(a=0;a<s&&!1!==i.call(t,t[a],a,t);a+=1);}else n(t)&&Object.keys(t).forEach(function(e){i.call(t,t[e],e,t)});return t}function r(t){for(var e=arguments.length,i=Array(e>1?e-1:0),s=1;s<e;s++)i[s-1]=arguments[s];if(n(t)&&i.length>0){if(Object.assign)return Object.assign.apply(Object,[t].concat(i));i.forEach(function(e){n(e)&&Object.keys(e).forEach(function(i){t[i]=e[i]})})}return t}function h(t,e){for(var i=arguments.length,n=Array(i>2?i-2:0),s=2;s<i;s++)n[s-2]=arguments[s];return function(){for(var i=arguments.length,s=Array(i),o=0;o<i;o++)s[o]=arguments[o];return t.apply(e,n.concat(s))}}function l(t,i){var n=t.style;a(i,function(t,i){K.test(i)&&e(t)&&(t+="px"),n[i]=t})}function c(t){return window.getComputedStyle?window.getComputedStyle(t,null):t.currentStyle}function u(t,e){return t.classList?t.classList.contains(e):t.className.indexOf(e)>-1}function d(t,i){if(i)if(e(t.length))a(t,function(t){d(t,i)});else if(t.classList)t.classList.add(i);else{var n=t.className.trim();n?n.indexOf(i)<0&&(t.className=n+" "+i):t.className=i}}function v(t,i){i&&(e(t.length)?a(t,function(t){v(t,i)}):t.classList?t.classList.remove(i):t.className.indexOf(i)>=0&&(t.className=t.className.replace(i,"")))}function f(t,i,n){i&&(e(t.length)?a(t,function(t){f(t,i,n)}):n?d(t,i):v(t,i))}function m(t){return t.replace(U,"$1-$2").toLowerCase()}function w(t,e){return n(t[e])?t[e]:t.dataset?t.dataset[e]:t.getAttribute("data-"+m(e))}function g(t,e,i){n(i)?t[e]=i:t.dataset?t.dataset[e]=i:t.setAttribute("data-"+m(e),i)}function p(t,e){if(n(t[e]))delete t[e];else if(t.dataset)try{delete t.dataset[e]}catch(i){t.dataset[e]=null}else t.removeAttribute("data-"+m(e))}function b(t,e,i){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},s=e.trim().split(Z);s.length>1?a(s,function(e){b(t,e,i)}):(o(i.onceListener)&&delete(i=i.onceListener).onceListener,t.removeEventListener?t.removeEventListener(e,i,n):t.detachEvent&&t.detachEvent("on"+e,i))}function y(t,e,i){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},s=e.trim().split(Z);if(s.length>1)a(s,function(e){y(t,e,i)});else{if(n.once){var o=i,r=function i(){for(var n=arguments.length,s=Array(n),a=0;a<n;a++)s[a]=arguments[a];return b(t,e,i),o.apply(t,s)};o.onceListener=r,i=r}t.addEventListener?t.addEventListener(e,i,n):t.attachEvent&&t.attachEvent("on"+e,i)}}function x(t,e,n){if(t.dispatchEvent){var s=void 0;return o(Event)&&o(CustomEvent)?s=i(n)?new Event(e,{bubbles:!0,cancelable:!0}):new CustomEvent(e,{detail:n,bubbles:!0,cancelable:!0}):i(n)?(s=document.createEvent("Event")).initEvent(e,!0,!0):(s=document.createEvent("CustomEvent")).initCustomEvent(e,!0,!0,n),t.dispatchEvent(s)}return!t.fireEvent||t.fireEvent("on"+e)}function k(t){var e=document.documentElement,i=t.getBoundingClientRect();return{left:i.left+((window.scrollX||e&&e.scrollLeft||0)-(e&&e.clientLeft||0)),top:i.top+((window.scrollY||e&&e.scrollTop||0)-(e&&e.clientTop||0))}}function z(t){for(;t.firstChild;)t.removeChild(t.firstChild)}function D(t){var i=t.rotate,n=t.scaleX,s=t.scaleY,o=[];e(i)&&0!==i&&o.push("rotate("+i+"deg)"),e(n)&&1!==n&&o.push("scaleX("+n+")"),e(s)&&1!==s&&o.push("scaleY("+s+")");var a=o.length?o.join(" "):"none";return{WebkitTransform:a,msTransform:a,transform:a}}function E(e){return t(e)?e.replace(/^.*\//,"").replace(/[?&#].*$/,""):""}function I(t,e){if(!t.naturalWidth||$){var i=document.createElement("img");i.onload=function(){e(i.width,i.height)},i.src=t.src}else e(t.naturalWidth,t.naturalHeight)}function T(t){switch(t){case 2:return A;case 3:return F;case 4:return X;default:return""}}function L(t){var e=r({},t),i=[];return a(t,function(t,n){delete e[n],a(e,function(e){var n=Math.abs(t.startX-e.startX),s=Math.abs(t.startY-e.startY),o=Math.abs(t.endX-e.endX),a=Math.abs(t.endY-e.endY),r=Math.sqrt(n*n+s*s),h=(Math.sqrt(o*o+a*a)-r)/r;i.push(h)})}),i.sort(function(t,e){return Math.abs(t)<Math.abs(e)}),i[0]}function S(t,e){var i=t.pageX,n=t.pageY,s={endX:i,endY:n};return e?s:r({startX:i,startY:n},s)}function N(t){var e=0,i=0,n=0;return a(t,function(t){var s=t.startX,o=t.startY;e+=s,i+=o,n+=1}),e/=n,i/=n,{pageX:e,pageY:i}}function C(t){if(Array.isArray(t)){for(var e=0,i=Array(t.length);e<t.length;e++)i[e]=t[e];return i}return Array.from(t)}function M(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var q={inline:!1,button:!0,navbar:!0,title:!0,toolbar:!0,tooltip:!0,movable:!0,zoomable:!0,rotatable:!0,scalable:!0,transition:!0,fullscreen:!0,keyboard:!0,interval:5e3,minWidth:200,minHeight:100,zoomRatio:.1,minZoomRatio:.01,maxZoomRatio:100,zIndex:2015,zIndexInline:0,url:"src",ready:null,show:null,shown:null,hide:null,hidden:null,view:null,viewed:null},Y=window.PointerEvent,X="viewer-hide-md-down",F="viewer-hide-sm-down",A="viewer-hide-xs-down",W="viewer-in",O="viewer-transition",R=Y?"pointerdown":"touchstart mousedown",P=Y?"pointermove":"mousemove touchmove",j=Y?"pointerup pointercancel":"touchend touchcancel mouseup",H="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},V=Number.isNaN||window.isNaN,B=Object.prototype.hasOwnProperty,K=/^(width|height|left|top|marginLeft|marginTop)$/,U=/([a-z\d])([A-Z])/g,Z=/\s+/,$=navigator&&/(Macintosh|iPhone|iPod|iPad).*AppleWebKit/i.test(navigator.userAgent),_={render:function(){this.initContainer(),this.initViewer(),this.initList(),this.renderViewer()},initContainer:function(){this.containerData={width:window.innerWidth,height:window.innerHeight}},initViewer:function(){var t=this.options,e=this.parent,i=void 0;t.inline&&(i={width:Math.max(e.offsetWidth,t.minWidth),height:Math.max(e.offsetHeight,t.minHeight)},this.parentData=i),!this.fulled&&i||(i=this.containerData),this.viewerData=r({},i)},renderViewer:function(){this.options.inline&&!this.fulled&&l(this.viewer,this.viewerData)},initList:function(){var e=this,i=this.element,n=this.options,s=this.list,r=[];a(this.images,function(e,i){var s=e.src,a=e.alt||E(s),h=n.url;s&&(t(h)?h=e.getAttribute(h):o(h)&&(h=h.call(e,e)),r.push('<li><img src="'+s+'" role="button" data-action="view" data-index="'+i+'" data-original-url="'+(h||s)+'" alt="'+a+'"></li>'))}),s.innerHTML=r.join(""),a(s.getElementsByTagName("img"),function(t){g(t,"filled",!0),y(t,"load",h(e.loadImage,e),{once:!0})}),this.items=s.getElementsByTagName("li"),n.transition&&y(i,"viewed",function(){d(s,O)},{once:!0})},renderList:function(t){var e=t||this.index,i=this.items[e].offsetWidth||30,n=i+1;l(this.list,{width:n*this.length,marginLeft:(this.viewerData.width-i)/2-n*e})},resetList:function(){z(this.list),v(this.list,O),l({marginLeft:0})},initImage:function(t){var e=this,i=this.options,n=this.image,s=this.viewerData,a=this.footer.offsetHeight,h=s.width,l=Math.max(s.height-a,a),c=this.ImageData||{};I(n,function(n,s){var a=n/s,u=h,d=l;l*a>h?d=h/a:u=l*a;var v={naturalWidth:n,naturalHeight:s,aspectRatio:a,ratio:(u=Math.min(.9*u,n))/n,width:u,height:d=Math.min(.9*d,s),left:(h-u)/2,top:(l-d)/2},f=r({},v);i.rotatable&&(v.rotate=c.rotate||0,f.rotate=0),i.scalable&&(v.scaleX=c.scaleX||1,v.scaleY=c.scaleY||1,f.scaleX=1,f.scaleY=1),e.imageData=v,e.initialImageData=f,o(t)&&t()})},renderImage:function(t){var e=this.image,i=this.imageData;l(e,r({width:i.width,height:i.height,marginLeft:i.left,marginTop:i.top},D(i))),o(t)&&(this.transitioning?y(e,"transitionend",t,{once:!0}):t())},resetImage:function(){var t=this.image;t&&(t.parentNode.removeChild(t),this.image=null)}},G={bind:function(){var t=this.element,e=this.options,i=this.viewer;o(e.view)&&y(t,"view",e.view),o(e.viewed)&&y(t,"viewed",e.viewed),y(i,"click",this.onClick=h(this.click,this)),y(i,"wheel mousewheel DOMMouseScroll",this.onWheel=h(this.wheel,this)),y(i,"dragstart",this.onDragStart=h(this.dragstart,this)),y(this.canvas,R,this.onPointerDown=h(this.pointerdown,this)),y(document,P,this.onPointerMove=h(this.pointermove,this)),y(document,j,this.onPointerUp=h(this.pointerup,this)),y(document,"keydown",this.onKeyDown=h(this.keydown,this)),y(window,"resize",this.onResize=h(this.resize,this))},unbind:function(){var t=this.element,e=this.options,i=this.viewer;o(e.view)&&b(t,"view",e.view),o(e.viewed)&&b(t,"viewed",e.viewed),b(i,"click",this.onClick),b(i,"wheel mousewheel DOMMouseScroll",this.onWheel),b(i,"dragstart",this.onDragStart),b(this.canvas,R,this.onPointerDown),b(document,P,this.onPointerMove),b(document,j,this.onPointerUp),b(document,"keydown",this.onKeyDown),b(window,"resize",this.onResize)}},J={click:function(t){var e=t.target,i=this.imageData;switch(w(e,"action")){case"mix":this.played?this.stop():this.options.inline?this.fulled?this.exit():this.full():this.hide();break;case"view":this.view(w(e,"index"));break;case"zoom-in":this.zoom(.1,!0);break;case"zoom-out":this.zoom(-.1,!0);break;case"one-to-one":this.toggle();break;case"reset":this.reset();break;case"prev":this.prev();break;case"play":this.play();break;case"next":this.next();break;case"rotate-left":this.rotate(-90);break;case"rotate-right":this.rotate(90);break;case"flip-horizontal":this.scaleX(-i.scaleX||-1);break;case"flip-vertical":this.scaleY(-i.scaleY||-1);break;default:this.played&&this.stop()}},load:function(){var t=this,e=this.options,i=this.image,n=this.index,s=this.viewerData;this.timeout&&(clearTimeout(this.timeout),this.timeout=!1),i&&(v(i,"viewer-invisible"),i.style.cssText="width:0;height:0;margin-left:"+s.width/2+"px;margin-top:"+s.height/2+"px;max-width:none!important;visibility:visible;",this.initImage(function(){f(i,O,e.transition),f(i,"viewer-move",e.movable),t.renderImage(function(){t.viewed=!0,x(t.element,"viewed",{originalImage:t.images[n],index:n,image:i})})}))},loadImage:function(t){var e=t.target,i=e.parentNode,n=i.offsetWidth||30,s=i.offsetHeight||50,o=!!w(e,"filled");I(e,function(t,i){var a=t/i,r=n,h=s;s*a>n?o?r=s*a:h=n/a:o?h=n/a:r=s*a,l(e,{width:r,height:h,marginLeft:(n-r)/2,marginTop:(s-h)/2})})},keydown:function(t){var e=this.options,i=t.keyCode||t.which||t.charCode;if(this.fulled&&e.keyboard)switch(i){case 27:this.played?this.stop():e.inline?this.fulled&&this.exit():this.hide();break;case 32:this.played&&this.stop();break;case 37:this.prev();break;case 38:t.preventDefault(),this.zoom(e.zoomRatio,!0);break;case 39:this.next();break;case 40:t.preventDefault(),this.zoom(-e.zoomRatio,!0);break;case 48:case 49:(t.ctrlKey||t.shiftKey)&&(t.preventDefault(),this.toggle())}},dragstart:function(t){"img"===t.target.tagName.toLowerCase()&&t.preventDefault()},pointerdown:function(t){var e=this.options,i=this.pointers;if(this.viewed&&!this.transitioning){t.changedTouches?a(t.changedTouches,function(t){i[t.identifier]=S(t)}):i[t.pointerId||0]=S(t);var n=!!e.movable&&"move";Object.keys(i).length>1?n="zoom":"touch"!==t.pointerType&&"touchmove"!==t.type||!this.isSwitchable()||(n="switch"),this.action=n}},pointermove:function(t){var e=this.options,i=this.pointers,n=this.action,s=this.image;this.viewed&&n&&(t.preventDefault(),t.changedTouches?a(t.changedTouches,function(t){r(i[t.identifier],S(t,!0))}):r(i[t.pointerId||0],S(t,!0)),"move"===n&&e.transition&&u(s,O)&&v(s,O),this.change(t))},pointerup:function(t){var e=this.action,i=this.pointers;this.viewed&&(t.changedTouches?a(t.changedTouches,function(t){delete i[t.identifier]}):delete i[t.pointerId||0],e&&("move"===e&&this.options.transition&&d(this.image,O),this.action=!1))},resize:function(){var t=this;if(this.initContainer(),this.initViewer(),this.renderViewer(),this.renderList(),this.viewed&&this.initImage(function(){t.renderImage()}),this.played){if(this.options.fullscreen&&this.fulled&&!document.fullscreenElement&&!document.mozFullScreenElement&&!document.webkitFullscreenElement&&!document.msFullscreenElement)return void this.stop();a(this.player.getElementsByTagName("img"),function(e){y(e,"load",h(t.loadImage,t),{once:!0}),x(e,"load")})}},start:function(t){var e=t.target;"img"===e.tagName.toLowerCase()&&(this.target=e,this.show())},wheel:function(t){var e=this;if(this.viewed&&(t.preventDefault(),!this.wheeling)){this.wheeling=!0,setTimeout(function(){e.wheeling=!1},50);var i=Number(this.options.zoomRatio)||.1,n=1;t.deltaY?n=t.deltaY>0?1:-1:t.wheelDelta?n=-t.wheelDelta/120:t.detail&&(n=t.detail>0?1:-1),this.zoom(-n*i,!0,t)}}},Q={show:function(){var t=this,e=this.element,i=this.options;if(i.inline||this.transitioning)return this;if(this.ready||this.build(),o(i.show)&&y(e,"show",i.show,{once:!0}),!1===x(e,"show"))return this;this.open();var n=this.viewer;return v(n,"viewer-hide"),y(e,"shown",function(){t.view(t.target?[].concat(C(t.images)).indexOf(t.target):t.index),t.target=!1},{once:!0}),i.transition?(this.transitioning=!0,d(n,O),n.offsetWidth,y(n,"transitionend",h(this.shown,this),{once:!0}),d(n,W)):(d(n,W),this.shown()),this},hide:function(){var t=this,e=this.element,i=this.options,n=this.viewer;return i.inline||this.transitioning||!this.visible?this:(o(i.hide)&&y(e,"hide",i.hide,{once:!0}),!1===x(e,"hide")?this:(this.viewed&&i.transition?(this.transitioning=!0,y(this.image,"transitionend",function(){y(n,"transitionend",h(t.hidden,t),{once:!0}),v(n,W)},{once:!0}),this.zoomTo(0,!1,!1,!0)):(v(n,W),this.hidden()),this))},view:function(t){var e=this,i=this.element,n=this.title,s=this.canvas;if(t=Number(t)||0,!this.ready||!this.visible||this.played||t<0||t>=this.length||this.viewed&&t===this.index)return this;var o=this.items[t],a=o.querySelector("img"),r=w(a,"originalUrl"),l=a.getAttribute("alt"),c=document.createElement("img");return c.src=r,c.alt=l,!1===x(i,"view",{originalImage:this.images[t],index:t,image:c})?this:(this.image=c,v(this.items[this.index],"viewer-active"),d(o,"viewer-active"),this.viewed=!1,this.index=t,this.imageData=null,d(c,"viewer-invisible"),z(s),s.appendChild(c),this.renderList(),z(n),y(i,"viewed",function(){var t=e.imageData;n.textContent=l+" ("+t.naturalWidth+" × "+t.naturalHeight+")"},{once:!0}),c.complete?this.load():(y(c,"load",h(this.load,this),{once:!0}),this.timeout&&clearTimeout(this.timeout),this.timeout=setTimeout(function(){v(c,"viewer-invisible"),e.timeout=!1},1e3)),this)},prev:function(){return this.view(Math.max(this.index-1,0)),this},next:function(){return this.view(Math.min(this.index+1,this.length-1)),this},move:function(t,e){var n=this.imageData;return this.moveTo(i(t)?t:n.left+Number(t),i(e)?e:n.top+Number(e)),this},moveTo:function(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,n=this.imageData;if(t=Number(t),i=Number(i),this.viewed&&!this.played&&this.options.movable){var s=!1;e(t)&&(n.left=t,s=!0),e(i)&&(n.top=i,s=!0),s&&this.renderImage()}return this},zoom:function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,n=this.imageData;return t=Number(t),t=t<0?1/(1-t):1+t,this.zoomTo(n.width*t/n.naturalWidth,e,i),this},zoomTo:function(t){var i=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,s=arguments.length>3&&void 0!==arguments[3]&&arguments[3],o=this.options,a=this.pointers,r=this.imageData;if(t=Math.max(0,t),e(t)&&this.viewed&&!this.played&&(s||o.zoomable)){if(!s){var h=Math.max(.01,o.minZoomRatio),l=Math.min(100,o.maxZoomRatio);t=Math.min(Math.max(t,h),l)}n&&t>.95&&t<1.05&&(t=1);var c=r.naturalWidth*t,u=r.naturalHeight*t;if(n){var d=k(this.viewer),v=a&&Object.keys(a).length?N(a):{pageX:n.pageX,pageY:n.pageY};r.left-=(c-r.width)*((v.pageX-d.left-r.left)/r.width),r.top-=(u-r.height)*((v.pageY-d.top-r.top)/r.height)}else r.left-=(c-r.width)/2,r.top-=(u-r.height)/2;r.width=c,r.height=u,r.ratio=t,this.renderImage(),i&&this.tooltip()}return this},rotate:function(t){return this.rotateTo((this.imageData.rotate||0)+Number(t)),this},rotateTo:function(t){var i=this.imageData;return t=Number(t),e(t)&&this.viewed&&!this.played&&this.options.rotatable&&(i.rotate=t,this.renderImage()),this},scaleX:function(t){return this.scale(t,this.imageData.scaleY),this},scaleY:function(t){return this.scale(this.imageData.scaleX,t),this},scale:function(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,n=this.imageData;if(t=Number(t),i=Number(i),this.viewed&&!this.played&&this.options.scalable){var s=!1;e(t)&&(n.scaleX=t,s=!0),e(i)&&(n.scaleY=i,s=!0),s&&this.renderImage()}return this},play:function(){var t=this,i=this.options,n=this.player,s=h(this.loadImage,this),o=[],r=0,l=0;if(!this.visible||this.played)return this;if(i.fullscreen&&this.requestFullscreen(),this.played=!0,this.onLoadWhenPlay=s,d(n,"viewer-show"),a(this.items,function(t,e){var a=t.querySelector("img"),h=document.createElement("img");h.src=w(a,"originalUrl"),h.alt=a.getAttribute("alt"),r+=1,d(h,"viewer-fade"),f(h,O,i.transition),u(t,"viewer-active")&&(d(h,W),l=e),o.push(h),y(h,"load",s,{once:!0}),n.appendChild(h)}),e(i.interval)&&i.interval>0){r>1&&function e(){t.playing=setTimeout(function(){v(o[l],W),d(o[l=(l+=1)<r?l:0],W),e()},i.interval)}()}return this},stop:function(){var t=this,e=this.player;return this.played?(this.options.fullscreen&&this.exitFullscreen(),this.played=!1,clearTimeout(this.playing),a(this.player.getElementsByTagName("img"),function(e){e.complete||b(e,"load",t.onLoadWhenPlay)}),v(e,"viewer-show"),z(e),this):this},full:function(){var t=this,e=this.options,i=this.viewer,n=this.image,s=this.list;return!this.visible||this.played||this.fulled||!e.inline?this:(this.fulled=!0,this.open(),d(this.button,"viewer-fullscreen-exit"),e.transition&&(v(n,O),v(s,O)),d(i,"viewer-fixed"),i.setAttribute("style",""),l(i,{zIndex:e.zIndex}),this.initContainer(),this.viewerData=r({},this.containerData),this.renderList(),this.initImage(function(){t.renderImage(function(){e.transition&&setTimeout(function(){d(n,O),d(s,O)},0)})}),this)},exit:function(){var t=this,e=this.options,i=this.viewer,n=this.image,s=this.list;return this.fulled?(this.fulled=!1,this.close(),v(this.button,"viewer-fullscreen-exit"),e.transition&&(v(n,O),v(s,O)),v(i,"viewer-fixed"),l(i,{zIndex:e.zIndexInline}),this.viewerData=r({},this.parentData),this.renderViewer(),this.renderList(),this.initImage(function(){t.renderImage(function(){e.transition&&setTimeout(function(){d(n,O),d(s,O)},0)})}),this):this},tooltip:function(){var t=this,e=this.options,i=this.tooltipBox,n=this.imageData;return this.viewed&&!this.played&&e.tooltip?(i.textContent=Math.round(100*n.ratio)+"%",this.tooltiping?clearTimeout(this.tooltiping):e.transition?(this.fading&&x(i,"transitionend"),d(i,"viewer-show"),d(i,"viewer-fade"),d(i,O),i.offsetWidth,d(i,W)):d(i,"viewer-show"),this.tooltiping=setTimeout(function(){e.transition?(y(i,"transitionend",function(){v(i,"viewer-show"),v(i,"viewer-fade"),v(i,O),t.fading=!1},{once:!0}),v(i,W),t.fading=!0):v(i,"viewer-show"),t.tooltiping=!1},1e3),this):this},toggle:function(){return 1===this.imageData.ratio?this.zoomTo(this.initialImageData.ratio,!0):this.zoomTo(1,!0),this},reset:function(){return this.viewed&&!this.played&&(this.imageData=r({},this.initialImageData),this.renderImage()),this},update:function(){var t=this,e=[];if(this.isImg&&!this.element.parentNode)return this.destroy();if(this.length=this.images.length,this.ready&&(a(this.items,function(i,n){var s=i.querySelector("img"),o=t.images[n];o?o.src!==s.src&&e.push(n):e.push(n)}),l(this.list,{width:"auto"}),this.initList(),this.visible))if(this.length){if(this.viewed){var i=e.indexOf(this.index);i>=0?(this.viewed=!1,this.view(Math.max(this.index-(i+1),0))):d(this.items[this.index],"viewer-active")}}else this.image=null,this.viewed=!1,this.index=0,this.imageData=null,z(this.canvas),z(this.title);return this},destroy:function(){var t=this.element;return this.options.inline?this.unbind():(this.visible&&this.unbind(),b(t,"click",this.onStart)),this.unbuild(),p(t,"viewer"),this}},tt=window.document,et={open:function(){var t=this.body;d(t,"viewer-open"),t.style.paddingRight=this.scrollbarWidth+"px"},close:function(){var t=this.body;v(t,"viewer-open"),t.style.paddingRight=0},shown:function(){var t=this.element,e=this.options;this.transitioning=!1,this.fulled=!0,this.visible=!0,this.render(),this.bind(),o(e.shown)&&y(t,"shown",e.shown,{once:!0}),x(t,"shown")},hidden:function(){var t=this.element,e=this.options;this.transitioning=!1,this.viewed=!1,this.fulled=!1,this.visible=!1,this.unbind(),this.close(),d(this.viewer,"viewer-hide"),this.resetList(),this.resetImage(),o(e.hidden)&&y(t,"hidden",e.hidden,{once:!0}),x(t,"hidden")},requestFullscreen:function(){if(this.fulled&&!tt.fullscreenElement&&!tt.mozFullScreenElement&&!tt.webkitFullscreenElement&&!tt.msFullscreenElement){var t=tt.documentElement;t.requestFullscreen?t.requestFullscreen():t.msRequestFullscreen?t.msRequestFullscreen():t.mozRequestFullScreen?t.mozRequestFullScreen():t.webkitRequestFullscreen&&t.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT)}},exitFullscreen:function(){this.fulled&&(tt.exitFullscreen?tt.exitFullscreen():tt.msExitFullscreen?tt.msExitFullscreen():tt.mozCancelFullScreen?tt.mozCancelFullScreen():tt.webkitExitFullscreen&&tt.webkitExitFullscreen())},change:function(t){var e=this.pointers,i=e[Object.keys(e)[0]],n=i.endX-i.startX,s=i.endY-i.startY;switch(this.action){case"move":this.move(n,s);break;case"zoom":this.zoom(L(e),!1,t);break;case"switch":this.action="switched",Math.abs(n)>Math.abs(s)&&(n>1?this.prev():n<-1&&this.next())}a(e,function(t){t.startX=t.endX,t.startY=t.endY})},isSwitchable:function(){var t=this.imageData,e=this.viewerData;return this.length>1&&t.left>=0&&t.top>=0&&t.width<=e.width&&t.height<=e.height}},it=function(){function t(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),e}}(),nt=void 0,st=function(){function t(e){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(M(this,t),!e||1!==e.nodeType)throw new Error("The first argument is required and must be an element.");this.element=e,this.options=r({},q,s(i)&&i),this.isImg=!1,this.ready=!1,this.visible=!1,this.viewed=!1,this.fulled=!1,this.played=!1,this.wheeling=!1,this.playing=!1,this.fading=!1,this.tooltiping=!1,this.transitioning=!1,this.action=!1,this.target=!1,this.timeout=!1,this.index=0,this.length=0,this.pointers={},this.init()}return it(t,[{key:"init",value:function(){var t=this,e=this.element,n=this.options;if(!w(e,"viewer")){g(e,"viewer",this);var s="img"===e.tagName.toLowerCase(),r=s?[e]:e.getElementsByTagName("img"),l=r.length;if(l)if(o(n.ready)&&y(e,"ready",n.ready,{once:!0}),i(document.createElement("viewer").style.transition)&&(n.transition=!1),this.isImg=s,this.length=l,this.count=0,this.images=r,this.body=document.body,this.scrollbarWidth=window.innerWidth-document.body.clientWidth,n.inline){var c=h(this.progress,this);y(e,"ready",function(){t.view()},{once:!0}),a(r,function(t){t.complete?c():y(t,"load",c,{once:!0})})}else y(e,"click",this.onStart=h(this.start,this))}}},{key:"progress",value:function(){this.count+=1,this.count===this.length&&this.build()}},{key:"build",value:function(){var t=this.options,e=this.element;if(!this.ready){var i=e.parentNode,n=document.createElement("div");n.innerHTML='<div class="viewer-container"><div class="viewer-canvas"></div><div class="viewer-footer"><div class="viewer-title"></div><ul class="viewer-toolbar"><li role="button" class="viewer-zoom-in" data-action="zoom-in"></li><li role="button" class="viewer-zoom-out" data-action="zoom-out"></li><li role="button" class="viewer-one-to-one" data-action="one-to-one"></li><li role="button" class="viewer-reset" data-action="reset"></li><li role="button" class="viewer-prev" data-action="prev"></li><li role="button" class="viewer-play" data-action="play"></li><li role="button" class="viewer-next" data-action="next"></li><li role="button" class="viewer-rotate-left" data-action="rotate-left"></li><li role="button" class="viewer-rotate-right" data-action="rotate-right"></li><li role="button" class="viewer-flip-horizontal" data-action="flip-horizontal"></li><li role="button" class="viewer-flip-vertical" data-action="flip-vertical"></li></ul><div class="viewer-navbar"><ul class="viewer-list"></ul></div></div><div class="viewer-tooltip"></div><div role="button" class="viewer-button" data-action="mix"></div><div class="viewer-player"></div></div>';var s=n.querySelector(".viewer-container"),o=s.querySelector(".viewer-title"),r=s.querySelector(".viewer-toolbar"),h=s.querySelector(".viewer-navbar"),u=s.querySelector(".viewer-button");if(this.parent=i,this.viewer=s,this.title=o,this.toolbar=r,this.navbar=h,this.button=u,this.canvas=s.querySelector(".viewer-canvas"),this.footer=s.querySelector(".viewer-footer"),this.tooltipBox=s.querySelector(".viewer-tooltip"),this.player=s.querySelector(".viewer-player"),this.list=s.querySelector(".viewer-list"),d(o,t.title?T(t.title):"viewer-hide"),d(r,t.toolbar?T(t.toolbar):"viewer-hide"),d(h,t.navbar?T(t.navbar):"viewer-hide"),f(u,"viewer-hide",!t.button),f(r.querySelector(".viewer-one-to-one"),"viewer-invisible",!t.zoomable),f(r.querySelectorAll('li[class*="zoom"]'),"viewer-invisible",!t.zoomable),f(r.querySelectorAll('li[class*="flip"]'),"viewer-invisible",!t.scalable),!t.rotatable){var v=r.querySelectorAll('li[class*="rotate"]');d(v,"viewer-invisible"),a(v,function(t){r.appendChild(t)})}t.inline?(d(u,"viewer-fullscreen"),l(s,{zIndex:t.zIndexInline}),"static"===c(i).position&&l(i,{position:"relative"}),i.insertBefore(s,e.nextSibling)):(d(u,"viewer-close"),d(s,"viewer-fixed"),d(s,"viewer-fade"),d(s,"viewer-hide"),l(s,{zIndex:t.zIndex}),document.body.appendChild(s)),t.inline&&(this.render(),this.bind(),this.visible=!0),this.ready=!0,x(e,"ready")}}},{key:"unbuild",value:function(){this.ready&&(this.ready=!1,this.viewer.parentNode.removeChild(this.viewer))}}],[{key:"noConflict",value:function(){return window.Viewer=nt,t}},{key:"setDefaults",value:function(t){r(q,s(t)&&t)}}]),t}();return r(st.prototype,_,G,J,Q,et),"undefined"!=typeof window&&(nt=window.Viewer,window.Viewer=st),st});