(function(r,C){typeof exports=="object"&&typeof module<"u"?C(require("jquery")):typeof define=="function"&&define.amd?define(["jquery"],C):(r=typeof globalThis<"u"?globalThis:r||self,C(r.jQuery))})(this,function(r){"use strict";function C(e,t,a){const i=t+"="+a;let o="?"+i;if(e){const n=new RegExp("([?&])"+t+"=[^&]*");n.exec(e)!==null?o=e.replace(n,"$1"+i):o=e+"&"+i}return o}function M(e){const t=new RegExp("[?&]"+e+"(=([^]*)|&|#|$)").exec(document.location.search);if((t==null?void 0:t[2])!==void 0)return decodeURIComponent(t[2].replace(/\+/g," "))}function D(e,t){let a=e;if(a){const i=new RegExp("\\?"+t+"=[^&]*"),o=new RegExp("&"+t+"=[^&]*");a=a.replace(i,"?"),a=a.replace(o,"")}return a}var y=(e=>(e[e.Right=-1]="Right",e[e.None=0]="None",e[e.Left=1]="Left",e))(y||{});function A(){let e=D(document.location.search,"imageLightboxIndex");e=D(e,"imageLightboxSet"),window.history.pushState({},"",document.location.pathname+e)}function Q(e,t,a){const i=a[e].dataset.ilb2Id??e.toString();let o=C(document.location.search,"imageLightboxIndex",i);const n={imageLightboxIndex:i,imageLightboxSet:""};t!==void 0&&(n.imageLightboxSet=t,o=C(o,"imageLightboxSet",t)),window.history.pushState(n,"",document.location.pathname+o)}function P(e,t,a){if(M("imageLightboxSet")!==e)return;const i=M("imageLightboxIndex");if(i===void 0)return;let o=t.index('[data-ilb2-id="'+i+'"]');o<0&&(o=parseInt(i)),a(o,!0)}function X(e,t,a,i,o,n,c){const u=e.originalEvent.state;if(u===null){n(!0);return}if(u.imageLightboxSet!==t)return;const g=u.imageLightboxIndex;if(g===void 0){n(!0);return}let b=a.get().findIndex(S=>S.dataset.ilb2Id===g);if(b<0&&(b=parseInt(g)),i===null){o(b,!0);return}c(b,b>i?y.Right:y.Left,!0)}const I=r("
",{id:"ilb-container"});function _(e,t){I.removeClass("ilb-overlay"),r("body").addClass("ilb-body"),r("body").append(I),e&&I.on("click.ilb7 touchend.ilb7",()=>(t(),!1))}function B(){I.addClass("ilb-overlay")}function W(){I.remove(),I.empty(),r("body").removeClass("ilb-body")}function q(e,t){I.trigger(e,t)}function E(){return I}const V=r("").attr("id","ilb-activity-indicator").append(r(""));function R(){E().append(V)}function H(){V.remove()}const z=r("",{class:"ilb-arrow",id:"ilb-arrow-left"}),U=r("",{class:"ilb-arrow",id:"ilb-arrow-right"});function G(e,t){E().append(z.on("click.ilb7 touchend.ilb7",()=>(e(),!1)),U.on("click.ilb7 touchend.ilb7",()=>(t(),!1)))}const N=r("",{id:"ilb-caption",html:" "});function J(){E().append(N)}function Y(e){e!==null?(N.css("display",""),N.text(e)):N.css("display","none")}const Z=r("",{id:"ilb-close-button"});function $(e){E().append(Z.on("click.ilb7",()=>(e(),!1)))}function ee(e,t,a){let i=0,o=0,n=r('
').attr("src",e.attr("href"));const c=r('').append(n);let u;const g=e.data("ilb2Video")!==void 0;g&&([n,u]=a.element(e.data("ilb2VideoId")));function b(d,f,h,L){if(t.quitOnImgClick)return L(),!1;const v=d.target;return(d.pageX-v.offsetLeft)/v.width<=1/3?f():h(),!1}function S(d,f,h,L){!g&&!("ontouchstart"in window)&&n.on("click.ilb7",v=>b(v,f,h,L)),n.on("touchstart.ilb7",v=>{i=v.originalEvent.touches[0].pageX,n.css("transition-property","opacity")}).on("touchmove.ilb7",v=>{o=v.originalEvent.touches[0].pageX-i,n.css("left",o.toString()+"px")}).on("touchend.ilb7 touchcancel.ilb7",()=>(n.css("transition-property","left, opacity"),o>50?(f(),!1):o<-50?(h(),!1):(n.css("left","0"),!0))),d()}function F(d,f){E().append(c);const h=Math.abs(100-t.gutter);n.css({"max-height":h.toString()+"%","max-width":h.toString()+"%",left:(-100*d).toString()+"px",transition:"all ease "+t.animationSpeed.toString()+"ms","transition-property":"left, opacity",opacity:"0"}),n.show(f)}function O(d,f){n.on("error.ilb7",f),u===!0?d():n.on("load.ilb7",d).on("loadedmetadata.ilb7",d)}function w(d,f,h,L){n.css({left:"0",opacity:"1"}),setTimeout(()=>{S(d,f,h,L)},t.animationSpeed)}function m(d,f){if(d!==y.None){const h=parseInt(n.css("left"),10)||0;n.css("left",(h+100*d).toString()+"px")}n.css("opacity","0"),setTimeout(()=>{f()},t.animationSpeed)}function x(){c.remove()}return{addToDOM:F,startLoading:O,transitionIn:w,transitionOut:m,removeFromDOM:x}}const te=document.fullscreenEnabled||(document.webkitFullscreenEnabled??!1);function ie(){const e=E().get(0),t=()=>{(e.requestFullscreen||e.webkitRequestFullScreen).call(e)},a=()=>{(document.exitFullscreen||document.webkitExitFullscreen).call(document)};!document.fullscreenElement&&!document.webkitFullscreenElement?t():a()}function ne(e,t,a,i){e.fullscreen&&te&&r(document).on("keyup.ilb7",o=>o.which===13?(ie(),!1):!0),e.enableKeyboard&&r(document).on("keyup.ilb7",o=>e.quitOnEscKey&&o.which===27?(t(),!1):o.which===37?(a(),!1):o.which===39?(i(),!1):!0)}function oe(){r(document).off("keyup.ilb7")}const ae=r("
",{href:"#"}),k=r("
",{class:"ilb-navigation"});function j(e){for(let t=0;t
!1).children().on("click.ilb7 touchend.ilb7",function(){const i=r(this);if(e().eq(i.index()).attr("href")===r("#ilb-image").attr("src"))return!1;const o=i.index()");let n=!1,c=!1,u,g;r.each(t,(O,w)=>{switch(O){case"autoplay":c=!0;break;case"height":u=w;break;case"width":g=w;break;case"controls":case"loop":case"muted":case"poster":case"preload":case"src":o.attr(O,w)}}),t.sources&&r.each(t.sources,(O,w)=>{let m=r("");r.each(w,(x,d)=>{m=m.attr(x,d)}),o.append(m)}),o.on("loadedmetadata.ilb7",()=>{n=!0});function b(){return i}function S(){return[g??o.width(),u??o.height()]}function F(){return c&&(n?o.get(0).play():o.attr("autoplay","autoplay")),[o,n]}return{id:b,dimensions:S,element:F}}function ce(){const e=[];function t(o){o.each((n,c)=>{const u=r(c).data("ilb2Video");u!==void 0&&e.push(le(r(c),u))})}function a(o){const n=e.find(c=>c.id()===o);if(n!==void 0)return n.dimensions()}function i(o){return e.find(c=>c.id()===o).element()}return{add:t,dimensions:a,element:i}}function de(e,t,a){let i=r();const o=ce();let n=null,c=null;function u(){return t}function g(){return i}function b(){return n}function S(l,s){const p=c;p.transitionOut(l,()=>{p.removeFromDOM(),s==null||s()})}function F(){c==null||c.transitionIn(H,d,f,m)}function O(l){c==null||c.addToDOM(l,()=>{const s=i.get(n);if(Y(s.dataset.ilb2Caption??r(s).find("img").attr("alt")??null),F(),e.preloadNext&&n+1").attr("src",p.attr("href"))}q("loaded.ilb2")})}function w(l,s){const p=ee(i.eq(l),e,o);p.startLoading(()=>{n=l,c=p,O(s)},()=>{H()})}function m(l=!1){n!==null&&(e.activity&&R(),oe(),e.history&&!l&&A(),q("quit.ilb2"),S(y.None,()=>{n=null,c=null,W()}))}function x(l,s,p=!1){n!==null&&(e.history&&!p&&Q(l,u(),g()),e.activity&&R(),K(l),S(s),w(l,s))}function d(){if(n===null)return;let l=n-1;if(n===0)if(e.quitOnEnd){m();return}else l=i.length-1;q("previous.ilb2",i.eq(l)),x(l,y.Left)}function f(){if(n===null)return;let l=n+1;if(n===i.length-1)if(e.quitOnEnd){m();return}else l=0;q("next.ilb2",i.eq(l)),x(l,y.Right)}function h(l,s=!1){_(e.quitOnDocClick,m),e.activity&&R(),ne(e,m,d,f),e.arrows&&G(d,f),e.caption&&J(),e.button&&$(m),e.navigation&&re(g,b,x),e.overlay&&B(),e.history&&!s&&Q(l,u(),g()),q("start.ilb2",i.eq(l)),w(l,y.None)}function L(l){const s=i.index(l);s<0||h(s)}function v(l){const s=l.not(i).filter((p,T)=>T.tagName.toLowerCase()==="a"&&(new RegExp(".("+e.allowedTypes+")$","i").test(T.href)||T.dataset.ilb2Video!==void 0));o.add(s),i=i.add(s),s.on("click.ilb7",p=>(L(r(p.delegateTarget)),!1)),j(s)}return v(a),e.history&&r(window).on("popstate.ilb7",l=>{X(l,u(),g(),b(),h,m,x)}),{set:u,images:g,currentIndex:b,addImages:v,openWithImage:L,open:h,close:m,previous:d,next:f,change:x}}r.fn.imageLightbox=function(e){const t=r.extend({allowedTypes:"png|jpg|jpeg|gif",animationSpeed:250,activity:!1,arrows:!1,button:!1,caption:!1,enableKeyboard:!0,history:!1,fullscreen:!1,gutter:10,navigation:!1,overlay:!1,preloadNext:!0,quitOnEnd:!1,quitOnImgClick:!1,quitOnDocClick:!0,quitOnEscKey:!0},e),a=de(t,r(this).data("imagelightbox"),r(this));return this.addToImageLightbox=i=>{a.addImages(i)},this.openHistory=()=>{t.history&&P(a.set(),a.images(),(i,o)=>{a.open(i,o)})},this.openHistory(),this.loadPreviousImage=()=>{a.previous()},this.loadNextImage=()=>{a.next()},this.quitImageLightbox=function(){return a.close(),this},this.startImageLightbox=i=>{i!==void 0?a.openWithImage(i):a.open(0)},this}});
//# sourceMappingURL=imagelightbox.umd.cjs.map