{ "version": 3, "sources": ["../../src/scripts/inspiration-gallery.js"], "sourcesContent": ["class InspirationGallery {\n\tconstructor(el) {\n\t\t// store references to our dom elements\n\t\tthis.dom = {\n\t\t\tel,\n\t\t\titems: el.querySelectorAll(\".inspiration-gallery__element\"),\n\t\t\tmodal: el.querySelector(\".inspiration-gallery__modal\"),\n\t\t\tmodalImage: el.querySelector(\".inspiration-gallery__modal-image\"),\n\t\t\tmodalContent: el.querySelector(\".inspiration-gallery__modal-content\"),\n\t\t\tmodalControls: el.querySelector(\".inspiration-gallery__modal-controls\"),\n\t\t};\n\n\t\tthis.currentItem = 0;\n\n\t\t// console.log(\"InspirationGallery\", this.dom);\n\n\t\tif (!this.dom.el || !this.dom.items) return;\n\n\t\tconst foundModal = this.dom.modalImage && this.dom.modalContent && this.dom.modalControls;\n\n\t\tlet enlarge, share, prev, next;\n\n\t\t[...this.dom.items].forEach((item, idx) => {\n\t\t\tenlarge = item.querySelector(\".inspiration-gallery__enlarge\");\n\t\t\tif (foundModal && enlarge) {\n\t\t\t\tenlarge.addEventListener(\"click\", () => this.enlargeClick(idx));\n\t\t\t}\n\n\t\t\tshare = item.querySelector(\".global-share-button .icon--share\");\n\t\t\tif (share) {\n\t\t\t\tif (navigator.share) {\n\t\t\t\t\tshare.classList.remove(\"hidden\");\n\t\t\t\t\tshare.addEventListener(\"click\", this.shareClick);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tjQuery(document).keydown(function (e) {\n\t\t\tif (e.which == 37) {\n\t\t\t\t// console.log(\"prev arrow\");\n\t\t\t\tprev = this.dom.modalControls.querySelector(\".inspiration-gallery__modal-prev\");\n\t\t\t\tprev.addEventListener(\"click\", () => this.prevClick());\n\t\t\t} else if (e.which == 39) {\n\t\t\t\t// console.log(\"next arrow\");\n\t\t\t\tnext = this.dom.modalControls.querySelector(\".inspiration-gallery__modal-next\");\n\t\t\t\tnext.addEventListener(\"click\", () => this.nextClick());\n\t\t\t}\n\t\t});\n\n\t\tprev = this.dom.modalControls.querySelector(\".inspiration-gallery__modal-prev\");\n\t\tif (prev) {\n\t\t\t// console.log(\"prev\");\n\t\t\tprev.addEventListener(\"click\", () => this.prevClick());\n\t\t}\n\t\tnext = this.dom.modalControls.querySelector(\".inspiration-gallery__modal-next\");\n\t\tif (next) {\n\t\t\tnext.addEventListener(\"click\", () => this.nextClick());\n\t\t}\n\n\t\tjQuery(\".inspiration-gallery__content-inner > p\").each(function () {\n\t\t\tjQuery(this).html(\n\t\t\t\tjQuery(this)\n\t\t\t\t\t.html()\n\t\t\t\t\t.replace(/ /gi, \"\"),\n\t\t\t);\n\t\t});\n\t}\n\n\t/**\n\t * open gallery item in modal\n\t */\n\tenlargeClick(idx) {\n\t\t// console.log(idx + \" enlarge click\");\n\n\t\tconst item = this.dom.items.item(idx);\n\t\tconst bg = item.querySelector(\".inspiration-gallery__background\");\n\t\tconst content = item.querySelector(\".inspiration-gallery__content\");\n\t\tconst bgSrc = bg.dataset.enlarged;\n\n\t\t// create new img tag to add to modal\n\t\tconst img = document.createElement(\"img\");\n\n\t\timg.src = bgSrc;\n\n\t\t// add it to the modal\n\t\tthis.currentItem = idx;\n\t\tthis.dom.modalImage.innerHTML = \"\";\n\t\tthis.dom.modalImage.appendChild(img);\n\n\t\t// add item's content to the modal\n\t\tthis.dom.modalContent.innerHTML = content.innerHTML;\n\n\t\t// show modal\n\t\tthis.dom.modal.classList.add(\"is-visible\");\n\t\tdocument.body.setAttribute(\"style\", \"overflow:hidden;\");\n\t\tdocument.getElementById(\"global-header\").setAttribute(\"style\", \"display:none;\");\n\t\tdocument.getElementById(\"top-bar\").setAttribute(\"style\", \"display:none;\");\n\t\tdocument.getElementsByTagName(\"main\")[0].setAttribute(\"style\", \"z-index:9997;\");\n\t\t// set focus on close button when\n\t\tthis.dom.modal.getElementsByClassName(\"modal__close\")[0].focus();\n\t}\n\n\t/**\n\t * activate share icons (by adding class to element)\n\t */\n\tshareClick(event) {\n\t\tconst share_title = event.currentTarget.dataset.title;\n\t\tconst share_url = event.currentTarget.dataset.url;\n\t\tconst share = {\n\t\t\ttitle: share_title,\n\t\t\turl: share_url,\n\t\t};\n\t\tnavigator\n\t\t\t.share(share)\n\t\t\t.then(function () {})\n\t\t\t.catch();\n\t}\n\n\topenAnchor(anchor) {\n\t\tthis.dom.items.forEach((item, idx) => {\n\t\t\tif (anchor == item.id) {\n\t\t\t\t// console.log(\"Inspiration Anchor Found\", anchor);\n\t\t\t\tthis.enlargeClick(idx);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t});\n\t\treturn false;\n\t}\n\n\tprevClick() {\n\t\tlet prevIDX = this.currentItem - 1;\n\n\t\tif (prevIDX < 0) {\n\t\t\tprevIDX = this.dom.items.length - 1;\n\t\t}\n\t\t// console.log(\"Previous Modal\", prevIDX);\n\t\tthis.enlargeClick(prevIDX);\n\t}\n\n\tnextClick() {\n\t\tlet nextIDX = this.currentItem + 1;\n\n\t\tif (nextIDX > this.dom.items.length - 1) {\n\t\t\tnextIDX = 0;\n\t\t}\n\t\t// console.log(\"Next Modal\", nextIDX);\n\t\tthis.enlargeClick(nextIDX);\n\t}\n}\nfunction getAnchor() {\n\treturn document.URL.split(\"#\").length > 1 ? document.URL.split(\"#\")[1] : null;\n}\njQuery(document).ready(function () {\n\tlet i;\n\n\tlet gallerySections = document.querySelectorAll(\".inspiration-gallery-section\");\n\n\tlet galleries = [];\n\n\tlet anchor = getAnchor();\n\n\tfor (i = 0; i < gallerySections.length; i++) {\n\t\tgalleries.push(new InspirationGallery(gallerySections[i]));\n\t}\n\n\tif (anchor !== null) {\n\t\t// console.log(anchor);\n\t\tfor (i = 0; i < galleries.length; i++) {\n\t\t\tif (galleries[i].openAnchor(anchor)) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n});\n"], "mappings": "MAAA,IAAMA,EAAN,KAAyB,CACxB,YAAYC,EAAI,CAef,GAbA,KAAK,IAAM,CACV,GAAAA,EACA,MAAOA,EAAG,iBAAiB,+BAA+B,E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AAc,EAE7BA,EAAU,KAAK,IAAI,MAAM,OAAS,IACrCA,EAAU,GAGX,KAAK,aAAaA,CAAO,CAC1B,CACD,EACA,SAASC,GAAY,CACpB,OAAO,SAAS,IAAI,MAAM,GAAG,EAAE,OAAS,EAAI,SAAS,IAAI,MAAM,GAAG,EAAE,CAAC,EAAI,IAC1E,CACA,OAAO,QAAQ,EAAE,MAAM,UAAY,CAClC,IAAIC,EAEAC,EAAkB,SAAS,iBAAiB,8BAA8B,EAE1EC,EAAY,CAAC,EAEbN,EAASG,EAAU,EAEvB,IAAKC,EAAI,EAAGA,EAAIC,EAAgB,OAAQD,IACvCE,EAAU,KAAK,IAAIvB,EAAmBsB,EAAgBD,CAAC,CAAC,CAAC,EAG1D,GAAIJ,IAAW,KAEd,IAAKI,EAAI,EAAGA,EAAIE,EAAU,QACrB,CAAAA,EAAUF,CAAC,EAAE,WAAWJ,CAAM,EADDI,IACjC,CAKH,CAAC", "names": ["InspirationGallery", "el", "foundModal", "enlarge", "share", "prev", "next", "item", "idx", "e", "bg", "content", "bgSrc", "img", "event", "share_title", "share_url", "anchor", "prevIDX", "nextIDX", "getAnchor", "i", "gallerySections", "galleries"] }