{"version":3,"sources":["webpack:///./LeLab.Web/src/js/is-within.entry.js"],"names":["PageComponent","constructor","node","this","html","document","querySelector","classes","dataset","isWithin","trim","replace","split","updateHandler","update","bind","addEventListener","e","target","closest","toggleNode","open","classList","add","close","remove","type","contains","c","destroy","removeEventListener"],"mappings":"4FAAA,kBA2DA,IAAIA,IAAc,mBAzDlB,MAEIC,aAAY,KAAEC,IACVC,KAAKD,KAAOA,EACZC,KAAKC,KAAOC,SAASC,cAAc,QAEnCH,KAAKI,QAAUJ,KAAKD,KAAKM,QAAQC,SACL,KAAxBN,KAAKI,QAAQG,OACbP,KAAKI,QAAUJ,KAAKI,QAAQI,QAAQ,OAAQ,KAE5CR,KAAKI,QAAU,YAEnBJ,KAAKI,QAAUJ,KAAKI,QAAQK,MAAM,KAGlCT,KAAKU,cAAgBV,KAAKW,OAAOC,KAAKZ,MAEtCA,KAAKC,KAAKY,iBAAiB,QAASb,KAAKU,eACzCV,KAAKC,KAAKY,iBAAiB,UAAWb,KAAKU,eAG/CC,OAAOG,GACH,MAAMf,EAAOe,EAAEC,OAAOC,QAAQ,oBACxBC,EAAaH,EAAEC,OAAOC,QAAQ,2BAC9BE,EAAO,IAAMlB,KAAKD,KAAKoB,UAAUC,OAAOpB,KAAKI,SAC7CiB,EAAQ,IAAMrB,KAAKD,KAAKoB,UAAUG,UAAUtB,KAAKI,SAGxC,UAAXU,EAAES,MAAoBxB,IAASC,KAAKD,MAAQkB,GAAcjB,KAAKD,KAAKyB,SAASP,GAC7EjB,KAAKM,WAAae,IAAUH,IAKhClB,KAAKD,KAAKyB,SAASV,EAAEC,QAAUG,IAASG,IAG5Cf,WACI,IAAK,MAAMmB,KAAKzB,KAAKI,QACjB,IAAKJ,KAAKD,KAAKoB,UAAUK,SAASC,GAAI,OAAO,EAEjD,OAAO,EAGXC,UACI1B,KAAKC,KAAK0B,oBAAoB,QAAS3B,KAAKU,eAC5CV,KAAKC,KAAK0B,oBAAoB,UAAW3B,KAAKU,sBAEvCV,KAAKD,YACLC,KAAKC,YACLD,KAAKI,eAELJ,KAAKU,mB","file":"is-within.js","sourcesContent":["import { PageComponent } from \"barba\"\r\n\r\nclass IsWithinClass {\r\n\r\n constructor({ node }) {\r\n this.node = node\r\n this.html = document.querySelector('html')\r\n\r\n this.classes = this.node.dataset.isWithin\r\n if (this.classes.trim() !== '') {\r\n this.classes = this.classes.replace(/\\s+/g, \" \")\r\n } else {\r\n this.classes = 'is-within'\r\n }\r\n this.classes = this.classes.split(' ')\r\n \r\n\r\n this.updateHandler = this.update.bind(this)\r\n\r\n this.html.addEventListener('click', this.updateHandler)\r\n this.html.addEventListener('focusin', this.updateHandler)\r\n }\r\n\r\n update(e) {\r\n const node = e.target.closest('[data-is-within]')\r\n const toggleNode = e.target.closest('[data-is-within-toggle]')\r\n const open = () => this.node.classList.add(...this.classes)\r\n const close = () => this.node.classList.remove(...this.classes)\r\n\r\n // Toggle on click\r\n if (e.type === 'click' && node === this.node && toggleNode && this.node.contains(toggleNode)) {\r\n this.isWithin() ? close() : open()\r\n return\r\n }\r\n\r\n // If target is inside\r\n this.node.contains(e.target) ? open() : close()\r\n }\r\n\r\n isWithin() {\r\n for (const c of this.classes) {\r\n if (!this.node.classList.contains(c)) return false\r\n }\r\n return true\r\n }\r\n\r\n destroy() {\r\n this.html.removeEventListener('click', this.updateHandler)\r\n this.html.removeEventListener('focusin', this.updateHandler)\r\n\r\n delete this.node\r\n delete this.html\r\n delete this.classes\r\n\r\n delete this.updateHandler\r\n }\r\n\r\n}\r\n\r\nnew PageComponent(\"[data-is-within]\", IsWithinClass)"],"sourceRoot":""}