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KAAKG,cAGhBH,KAAKE,SAASmD,GAAG,UAAU,KAEvBrD,KAAKqC,mBAAmBrC,KAAKE,SAASoD,UAAUnB,MAAM,IAG1DnC,KAAKE,SAASqD,MAClB,CAEAlB,kBAAAA,CAAmBF,GACfnC,KAAKO,MAAMP,KAAKG,aAAaJ,GAAGuC,UAAUkB,OAAO,UACjDxD,KAAKO,MAAM4B,GAAOpC,GAAGuC,UAAUC,IAAI,UACnCvC,KAAKM,QAAQmD,aAAa,MAAOzD,KAAKO,MAAM4B,GAAOV,IAAIT,QAAQI,KAC/DpB,KAAKM,QAAQmD,aAAa,SAAUzD,KAAKO,MAAM4B,GAAOV,IAAIT,QAAQ0C,QAClE1D,KAAKM,QAAQmD,aAAa,MAAOzD,KAAKO,MAAM4B,GAAOV,IAAIJ,aAAa,QACpErB,KAAKG,YAAcgC,CACvB,EAKG,SAASwB,EAAWC,GACvBA,EAAShD,SAASiD,IAEQ,IAAlBA,EAAKC,UACL,IAAIjE,EAAegE,EACvB,GAER,C","sources":["webpack://wildwoodtrust/./wwwroot/app/src/js/product-gallery.js"],"sourcesContent":["// *****************************************\r\n// ************* Image Gallery *************\r\n// *****************************************\r\n\r\nimport PhotoSwipe from 'photoswipe';\r\nimport 'photoswipe/style.css';\r\n\r\nclass ProductGallery {\r\n\r\n constructor(el) {\r\n this.el = el;\r\n this.imageSizesOkay = true;\r\n this.lightbox = null;\r\n this.activeIndex = 0;\r\n this.main = el.querySelector('.product-gallery--main-image');\r\n this.mainImg = el.querySelector('.product-gallery--main-image figure img');\r\n this.items = [];\r\n let findItems = el.querySelectorAll('ul li a');\r\n this.loop = findItems.length > 1;\r\n if(findItems != null) {\r\n [...findItems].forEach((itemElement, itemIndex) => {\r\n let dataWidth = itemElement.dataset.pswpWidth,\r\n dataHeight = itemElement.dataset.pswpHeight;\r\n this.items[itemIndex] = {\r\n el: itemElement,\r\n src: itemElement.getAttribute('href'),\r\n width: parseFloat(dataWidth) > 0 ? parseFloat(dataWidth) : 0,\r\n height: parseFloat(dataHeight) > 0 ? parseFloat(dataHeight) : 0,\r\n img: itemElement.querySelector('img'),\r\n alt: itemElement.querySelector('figcaption').innerText\r\n };\r\n this.imageSizesOkay = this.items[itemIndex].width > 0 && this.items[itemIndex].height > 0;\r\n });\r\n }\r\n // open gallery with 'main' button\r\n this.main.onclick = (e) => {\r\n e.stopPropagation();\r\n e.preventDefault();\r\n if(!this.imageSizesOkay) {\r\n this.getImageDimensions(this.activeIndex);\r\n } else {\r\n this.createLightbox(this.activeIndex);\r\n }\r\n };\r\n // thumbnail links load image into 'main' area and change the activeIndex\r\n for(var x=0; x < this.items.length; x++) {\r\n let index = x,\r\n _this = this;\r\n this.items[x].el.onclick = (e) => {\r\n e.stopPropagation();\r\n e.preventDefault();\r\n _this.setActiveThumbnail(index);\r\n };\r\n }\r\n this.items[this.activeIndex].el.classList.add('active');\r\n }\r\n\r\n getImageDimensions(priorityIndex) {\r\n // priority index\r\n if(this.items[priorityIndex].width == 0 || this.items[priorityIndex].height == 0) {\r\n let index = priorityIndex;\r\n this.items[priorityIndex].image = new Image();\r\n this.items[priorityIndex].image.onload = () => {\r\n this.imageLoaded(priorityIndex, true);\r\n }\r\n this.items[priorityIndex].image.src = this.items[priorityIndex].src;\r\n } else {\r\n this.createLightbox(priorityIndex);\r\n }\r\n // other images\r\n for(var x=0; x < this.items.length; x++) {\r\n if( x !== priorityIndex) {\r\n if(this.items[x].width == 0 || this.items[x].height == 0) {\r\n let index = x;\r\n this.items[x].image = new Image();\r\n this.items[x].image.onload = () => {\r\n this.imageLoaded(index, false);\r\n }\r\n this.items[x].image.src = this.items[x].src;\r\n }\r\n }\r\n };\r\n }\r\n\r\n imageLoaded(i, create) {\r\n let w = this.items[i].image.width,\r\n h = this.items[i].image.height;\r\n this.items[i].width = w;\r\n this.items[i].height = h;\r\n if(create) {\r\n this.createLightbox();\r\n } else {\r\n this.lightbox.options.dataSource[i].width = w;\r\n this.lightbox.options.dataSource[i].height = h;\r\n this.lightbox.refreshSlideContent(i);\r\n }\r\n }\r\n\r\n createLightbox() {\r\n this.lightbox = new PhotoSwipe({\r\n dataSource: this.items,\r\n loop: this.loop,\r\n index: this.activeIndex\r\n });\r\n // update thumbnails on slide change\r\n this.lightbox.on('change', () => {\r\n // triggers when slide is switched, and at initialization\r\n this.setActiveThumbnail(this.lightbox.currSlide.index);\r\n });\r\n // init\r\n this.lightbox.init();\r\n }\r\n\r\n setActiveThumbnail(index) {\r\n this.items[this.activeIndex].el.classList.remove('active');\r\n this.items[index].el.classList.add('active');\r\n this.mainImg.setAttribute('src', this.items[index].img.dataset.src);\r\n this.mainImg.setAttribute('srcset', this.items[index].img.dataset.srcset);\r\n this.mainImg.setAttribute('alt', this.items[index].img.getAttribute('alt'));\r\n this.activeIndex = index;\r\n }\r\n\r\n}\r\n\r\n// export the default function to create\r\nexport function createFrom(wrappers) {\r\n wrappers.forEach((node) => {\r\n // if node is an element\r\n if (node.nodeType === 1) {\r\n new ProductGallery(node);\r\n }\r\n });\r\n}"],"names":["ProductGallery","constructor","el","this","imageSizesOkay","lightbox","activeIndex","main","querySelector","mainImg","items","findItems","querySelectorAll","loop","length","forEach","itemElement","itemIndex","dataWidth","dataset","pswpWidth","dataHeight","pswpHeight","src","getAttribute","width","parseFloat","height","img","alt","innerText","onclick","e","stopPropagation","preventDefault","createLightbox","getImageDimensions","x","index","_this","setActiveThumbnail","classList","add","priorityIndex","image","Image","onload","imageLoaded","i","create","w","h","options","dataSource","refreshSlideContent","PhotoSwipe","on","currSlide","init","remove","setAttribute","srcset","createFrom","wrappers","node","nodeType"],"sourceRoot":""}