lightgallery
Version:
lightGallery is a feature-rich, modular JavaScript gallery plugin for building beautiful image and video galleries for the web and the mobile
2 lines (1 loc) • 2.11 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).lgRelativeCaption=e()}(this,function(){"use strict";const t="lgContainerResize",e="lgSlideItemLoad",i="lgBeforeSlide",o="lgAfterSlide",s={relativeCaption:!1};var n=Object.defineProperty,l=Object.getOwnPropertySymbols,a=Object.prototype.hasOwnProperty,c=Object.prototype.propertyIsEnumerable,r=(t,e,i)=>e in t?n(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,d=(t,e)=>{for(var i in e||(e={}))a.call(e,i)&&r(t,i,e[i]);if(l)for(var i of l(e))c.call(e,i)&&r(t,i,e[i]);return t};return class{constructor(t){this.core=t;const e={addClass:this.core.settings.addClass+" lg-relative-caption"};return this.core.settings=d(d({},this.core.settings),e),this.settings=d(d(d({},s),this.core.settings),e),this}init(){this.settings.relativeCaption&&(this.core.LGel.on(`${e}.caption`,t=>{const{index:e,delay:i}=t.detail;setTimeout(()=>{e===this.core.index&&this.setRelativeCaption(e)},i)}),this.core.LGel.on(`${o}.caption`,t=>{const{index:e}=t.detail;setTimeout(()=>{this.core.getSlideItem(e).hasClass("lg-complete")&&this.setRelativeCaption(e)})}),this.core.LGel.on(`${i}.caption`,t=>{const{index:e}=t.detail;setTimeout(()=>{this.core.getSlideItem(e).removeClass("lg-show-caption")})}),this.core.LGel.on(`${t}.caption`,t=>{this.setRelativeCaption(this.core.index)}))}setCaptionStyle(t,e,i){const o=this.core.getSlideItem(t).find(".lg-relative-caption-item"),s=this.core.getSlideItem(t).find(".lg-sub-html");s.css("width",`${e.width}px`).css("left",`${e.left}px`);const n=o.get().getBoundingClientRect(),l=i.bottom-e.bottom-n.height;s.css("top","auto").css("bottom",`${Math.max(l,0)}px`)}setRelativeCaption(t){const e=this.core.getSlideItem(t);if(e.hasClass("lg-current")){const i=this.core.getSlideItem(t).find(".lg-object").get().getBoundingClientRect(),o=this.core.getSlideItem(t).get().getBoundingClientRect();this.setCaptionStyle(t,i,o),e.addClass("lg-show-caption")}}destroy(){this.core.LGel.off(".caption")}}});