{"version":3,"sources":["webpack:///./src/js/modules/favorite-button.js"],"names":["Module","Component","setupDefaults","this","dom","span","el","querySelector","notificationBar","document","body","notificationBarHeading","notificationBarCopy","notificationBarDismissBtn","loginModal","favorited","dataset","favoriteLabel","favoritedLabel","innerText","updateNotificationBar","addListeners","addEventListener","handleFavoriteSubmit","bind","handleDismiss","checkForClick","queries","URLSearchParams","window","location","search","get","click","delete","history","pushState","title","href","split","removed","added","classList","contains","id","head","content","loggedIn","add","headers","fetch","postEndpoint","method","JSON","stringify","then","r","json","data","Success","setAttribute","timeout","setTimeout","remove","parseInt","catch","console","error","finally","clearTimeout"],"mappings":"2FAAA,mBAEA,MAAMA,UAAeC,YACnBC,gBAAgB,UACdC,KAAKC,IAAM,CACTC,KAAMF,KAAKG,GAAGC,cAAc,SAE9BJ,KAAKK,gBAAkBC,SAASC,KAAKH,cAAc,+BACnDJ,KAAKQ,uBAAL,UAA8BR,KAAKK,uBAAnC,aAA8B,EAAsBD,cAClD,8BAEFJ,KAAKS,oBAAL,UAA2BT,KAAKK,uBAAhC,aAA2B,EAAsBD,cAC/C,2BAEFJ,KAAKU,0BAAL,UAAiCV,KAAKK,uBAAtC,aAAiC,EAAsBD,cACrD,mCAGFJ,KAAKW,WAAaL,SAASC,KAAKH,cAAc,gBAC9CJ,KAAKY,UAA0C,UAA9BZ,KAAKG,GAAGU,QAAQD,UACjCZ,KAAKc,cAAgBd,KAAKG,GAAGU,QAAQC,cACrCd,KAAKe,eAAiBf,KAAKG,GAAGU,QAAQE,eACtCf,KAAKC,IAAIC,KAAKc,UAAYhB,KAAKY,UAC3BZ,KAAKe,eACLf,KAAKc,cAETd,KAAKiB,wBAGPC,eACElB,KAAKG,GAAGgB,iBAAiB,QAASnB,KAAKoB,qBAAqBC,KAAKrB,OACjEA,KAAKU,0BAA0BS,iBAAiB,QAASnB,KAAKsB,cAAcD,KAAKrB,OAEjFA,KAAKuB,gBAGPA,gBACE,MAAMC,EAAU,IAAIC,gBAAgBC,OAAO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C5D,KAAKiB,yBACJ4C,SAAS7D,KAAKK,gBAAgBQ,QAAQ6C,WAEzC1D,KAAKW,WAAW8C,aAAa,eAAe,KAG/CK,MAAMC,QAAQC,OACdC,QAAQ,KACPjE,KAAKG,GAAGoC,UAAUqB,OAAO,6CAG7B5D,KAAKW,WAAW8C,aAAa,eAAe,GAIhDnC,gBACE4C,aAAalE,KAAK0D,SAClB1D,KAAKK,gBAAgBkC,UAAUqB,OAAO,0BAEtC5D,KAAKiB,yBAIMpB","file":"71.c35a95.js","sourcesContent":["import { Component } from '@verndale/core';\n\nclass Module extends Component {\n setupDefaults() {\n this.dom = {\n span: this.el.querySelector('span')\n };\n this.notificationBar = document.body.querySelector('.notification-bar--favorite');\n this.notificationBarHeading = this.notificationBar?.querySelector(\n '.notification-bar__heading'\n );\n this.notificationBarCopy = this.notificationBar?.querySelector(\n '.notification-bar__copy'\n );\n this.notificationBarDismissBtn = this.notificationBar?.querySelector(\n '.notification-bar__close-button'\n )\n\n this.loginModal = document.body.querySelector('.login-modal');\n this.favorited = this.el.dataset.favorited === 'false' ? false : true;\n this.favoriteLabel = this.el.dataset.favoriteLabel;\n this.favoritedLabel = this.el.dataset.favoritedLabel;\n this.dom.span.innerText = this.favorited\n ? this.favoritedLabel\n : this.favoriteLabel;\n\n this.updateNotificationBar();\n }\n\n addListeners() {\n this.el.addEventListener('click', this.handleFavoriteSubmit.bind(this));\n this.notificationBarDismissBtn.addEventListener('click', this.handleDismiss.bind(this));\n\n this.checkForClick();\n }\n\n checkForClick() {\n const queries = new URLSearchParams(window.location.search);\n if (queries.get('favorite')) {\n this.el.click();\n queries.delete('favorite');\n window.history.pushState({}, document.title, location.href.split('?')[0]);\n }\n }\n\n updateNotificationBar() {\n if (this.favorited) {\n this.notificationBarHeading.innerText = this.notificationBarHeading.dataset.removed;\n this.notificationBarCopy.innerText = this.notificationBarCopy.dataset.removed;\n } else {\n this.notificationBarHeading.innerText = this.notificationBarHeading.dataset.added;\n this.notificationBarCopy.innerText = this.notificationBarCopy.dataset.added;\n }\n }\n\n handleFavoriteSubmit() {\n if (this.notificationBar.classList.contains('notification-bar--show')) {\n this.handleDismiss();\n }\n const id = this.el.dataset.id\n ? this.el.dataset.id\n : document.head.querySelector('meta[property=\"page_id\"').content;\n\n if (this.el.dataset.loggedIn === 'true') {\n this.el.classList.add('masthead__favorite-button--loading');\n const headers = {\n 'content-type': 'application/json'\n };\n fetch(this.el.dataset.postEndpoint, {\n method: 'POST',\n headers,\n body: JSON.stringify({ id, add: !this.favorited })\n })\n .then(r => r.json())\n .then(data => {\n if (data.Success) {\n this.notificationBar.classList.add('notification-bar--show');\n\n this.favorited = !this.favorited;\n this.dom.span.innerText = this.favorited\n ? this.favoritedLabel\n : this.favoriteLabel;\n this.el.setAttribute('data-favorited', this.favorited);\n this.el.dataset.favorited = this.favorited;\n this.timeout = setTimeout(() => {\n this.notificationBar.classList.remove('notification-bar--show');\n\n this.updateNotificationBar();\n }, parseInt(this.notificationBar.dataset.timeout));\n } else {\n this.loginModal.setAttribute('aria-hidden', false);\n }\n })\n .catch(console.error)\n .finally(() => {\n this.el.classList.remove('masthead__favorite-button--loading');\n });\n } else {\n this.loginModal.setAttribute('aria-hidden', false);\n }\n }\n\n handleDismiss() {\n clearTimeout(this.timeout);\n this.notificationBar.classList.remove('notification-bar--show');\n\n this.updateNotificationBar();\n }\n}\n\nexport default Module;\n"],"sourceRoot":""}