{ "version": 3, "sources": ["../../javascript/themisable_element.js"], "sourcesContent": ["export default class ThemisableElement extends HTMLDivElement {\n static get observedAttributes() {\n return ['data-themis-id', 'data-themis-notifications-ids'];\n }\n\n constructor() {\n super();\n\n this.placement = this.hasAttribute('data-themis-notification-placement')\n ? this.dataset.themisNotificationPlacement\n : 'top-right';\n\n this.addNotificationBadge();\n\n this.showPanelBoundListener = this.showPanel.bind(this);\n }\n\n addNotificationBadge() {\n // console.log('constructor', this);\n this.style.position = 'relative';\n\n const span = document.createElement('span');\n span.classList.add('themis-notification-badge');\n span.classList.add(`themis-notification-badge--${this.placement}`);\n span.style.display = 'none';\n span.innerText = 'Th\u00E9mis';\n\n const spanCount = document.createElement('span');\n spanCount.classList.add('themis-notification-badge__count');\n span.appendChild(spanCount);\n\n this.notificationElement = span;\n this.notificationCountElement = spanCount;\n\n this.appendChild(span);\n }\n\n attributeChangedCallback(name, oldValue, newValue) {\n if (name === 'data-themis-notifications-ids') {\n const notificationIdsArray = newValue.length ? newValue.split(',') : [];\n this.notificationIds = notificationIdsArray;\n\n const notifsCount = notificationIdsArray.length;\n\n this.notificationCount = notifsCount;\n }\n }\n\n set notificationCount(val) {\n this.notificationCountElement.innerText = val;\n\n if (val > 0) {\n this.attachClickListener();\n this.showNotification();\n } else {\n this.hideNotification();\n }\n }\n\n attachClickListener() {\n this.notificationElement.addEventListener('click', this.showPanelBoundListener);\n }\n\n disconnectedCallback() {\n this.notificationElement.removeEventListener('click', this.showPanelBoundListener);\n }\n\n showPanel(event) {\n event.preventDefault();\n event.stopPropagation();\n\n window.Turbo.visit(`/themis/notifications/details_for_ids?notification_ids=${this.notificationIds.join(',')}`, { frame: 'themis-panel-index', action: 'update' });\n window.ThemisInstance.showPanel(this);\n\n this.reveal();\n }\n\n showNotification() {\n this.notificationElement.style.display = 'block';\n }\n\n hideNotification() {\n this.notificationElement.style.display = 'none';\n }\n\n reveal() {\n this.classList.add('themis-revealed');\n\n const yOffset = -300;\n const y = this.getBoundingClientRect().top + window.pageYOffset + yOffset;\n window.scroll({\n top: y,\n behavior: 'smooth',\n });\n\n setTimeout(() => {\n document.body.style.overflow = 'hidden';\n }, 500);\n }\n\n unreveal() {\n this.classList.remove('themis-revealed');\n document.body.style.overflow = 'unset';\n }\n}\n\ncustomElements.define('themisable-element', ThemisableElement, { extends: 'div' });\n"], "mappings": "MAAA,GAAqB,GAArB,aAA+C,eAAe,CAC5D,UAAW,qBAAqB,CAC9B,MAAO,CAAC,iBAAkB,+BAA+B,CAC3D,CAEA,aAAc,CACZ,MAAM,EAEN,KAAK,UAAY,KAAK,aAAa,oCAAoC,EACnE,KAAK,QAAQ,4BACb,YAEJ,KAAK,qBAAqB,EAE1B,KAAK,uBAAyB,KAAK,UAAU,KAAK,IAAI,CACxD,CAEA,sBAAuB,CAErB,KAAK,MAAM,SAAW,WAEtB,GAAM,GAAO,SAAS,cAAc,MAAM,EAC1C,EAAK,UAAU,IAAI,2BAA2B,EAC9C,EAAK,UAAU,IAAI,8BAA8B,KAAK,WAAW,EACjE,EAAK,MAAM,QAAU,OACrB,EAAK,UAAY,YAEjB,GAAM,GAAY,SAAS,cAAc,MAAM,EAC/C,EAAU,UAAU,IAAI,kCAAkC,EAC1D,EAAK,YAAY,CAAS,EAE1B,KAAK,oBAAsB,EAC3B,KAAK,yBAA2B,EAEhC,KAAK,YAAY,CAAI,CACvB,CAEA,yBAAyB,EAAM,EAAU,EAAU,CACjD,GAAI,IAAS,gCAAiC,CAC5C,GAAM,GAAuB,EAAS,OAAS,EAAS,MAAM,GAAG,EAAI,CAAC,EACtE,KAAK,gBAAkB,EAEvB,GAAM,GAAc,EAAqB,OAEzC,KAAK,kBAAoB,CAC3B,CACF,CAEA,GAAI,mBAAkB,EAAK,CACzB,KAAK,yBAAyB,UAAY,EAE1C,AAAI,EAAM,EACR,MAAK,oBAAoB,EACzB,KAAK,iBAAiB,GAEtB,KAAK,iBAAiB,CAE1B,CAEA,qBAAsB,CACpB,KAAK,oBAAoB,iBA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