{"version":3,"sources":["webpack:///./LeLab.Web/src/js/load-more.entry.js"],"names":["PageComponent","constructor","node","this","id","increment","dataset","loadMore","parseInt","items","querySelectorAll","btn","querySelector","length","btnCollapse","counter","PageState","get","loadHandler","load","bind","updateHandler","update","addEventListener","window","updatePageState","btnCollapseMaxHeight","scrollHeight","itemsMaxHeight","i","style","setProperty","set","destroy","removeEventListener"],"mappings":"4FAAA,yBAuEA,IAAIA,IAAc,mBApElB,MACIC,aAAY,KAAEC,IACVC,KAAKD,KAAOA,EACZC,KAAKC,GAAKD,KAAKD,KAAKE,IAAM,KAC1BD,KAAKE,UAAYF,KAAKD,KAAKI,QAAQC,SAAWC,SAASL,KAAKD,KAAKI,QAAQC,UAAY,KACrFJ,KAAKM,MAAQN,KAAKD,KAAKQ,iBAAiB,yBACxCP,KAAKQ,IAAMR,KAAKD,KAAKU,cAAc,yBAE9BT,KAAKQ,KAAOR,KAAKM,MAAMI,QAAU,IAEtCV,KAAKW,YAAcX,KAAKD,KAAKU,cAAc,iCAC3CT,KAAKY,QAAUZ,KAAKC,IAAKY,IAAUC,IAAV,4BAAmCd,KAAKC,MAAa,EAE9ED,KAAKe,YAAcf,KAAKgB,KAAKC,KAAKjB,MAClCA,KAAKkB,cAAgBlB,KAAKmB,OAAOF,KAAKjB,MAEtCA,KAAKQ,IAAIY,iBAAiB,QAASpB,KAAKe,aACxCM,OAAOD,iBAAiB,SAAUpB,KAAKkB,eAEvClB,KAAKmB,UAGTH,OACIhB,KAAKY,QAAUZ,KAAKY,QAAUZ,KAAKE,UACnCF,KAAKmB,SACLnB,KAAKsB,kBAGTH,SAEI,IAAII,EAAuBvB,KAAKY,QAAUZ,KAAKM,MAAMI,OAASV,KAAKW,YAAYa,aAAe,EAC1FC,EAAiB,GACrB,IAAK,IAAIC,EAAI,EAAGA,EAAI1B,KAAKM,MAAMI,OAAQgB,IACnCD,EAAeC,GAAK,EAChBA,EAAI1B,KAAKY,UACTa,EAAeC,GAAK1B,KAAKM,MAAMoB,GAAGF,cAI1C,IAAK,IAAIE,EAAI,EAAGA,EAAI1B,KAAKM,MAAMI,OAAQgB,IACnC1B,KAAKM,MAAMoB,GAAGC,MAAMC,YAAY,yBAAhC,UAA6DH,EAAeC,KAAOA,EAAI1B,KAAKY,QAAU,KAAO,GAA7G,OAEJZ,KAAKW,YAAYgB,MAAMC,YAAY,yBAAnC,UAAgEL,EAAhE,OAGJD,kBACQtB,KAAKC,IACLY,IAAUgB,IAAV,4BAAmC7B,KAAKC,IAAMD,KAAKY,SAI3DkB,WACK9B,KAAKQ,KAAOR,KAAKQ,IAAIuB,oBAAoB,QAAS/B,KAAKe,aACxDM,OAAOU,oBAAoB,SAAU/B,KAAKkB,sBAEnClB,KAAKe,mBACLf,KAAKkB,qBAELlB,KAAKD,YACLC,KAAKC,UACLD,KAAKE,iBACLF,KAAKM,aACLN,KAAKQ,WACLR,KAAKW,mBACLX,KAAKY,Y","file":"load-more.js","sourcesContent":["import \"./load-more.scss\"\r\nimport { PageState, PageComponent } from \"barba\"\r\n\r\nclass LoadMore {\r\n constructor({ node }) {\r\n this.node = node\r\n this.id = this.node.id || null\r\n this.increment = this.node.dataset.loadMore ? parseInt(this.node.dataset.loadMore) : 9999\r\n this.items = this.node.querySelectorAll('[data-load-more-item]')\r\n this.btn = this.node.querySelector('[data-load-more-btn]')\r\n\r\n if (!this.btn || this.items.length <= 0) return\r\n\r\n this.btnCollapse = this.node.querySelector('[data-load-more-btn-collapse]')\r\n this.counter = this.id ? PageState.get(`load-more-counter-${this.id}`) || 0 : 0\r\n \r\n this.loadHandler = this.load.bind(this)\r\n this.updateHandler = this.update.bind(this)\r\n \r\n this.btn.addEventListener(\"click\", this.loadHandler)\r\n window.addEventListener(\"resize\", this.updateHandler)\r\n \r\n this.update()\r\n }\r\n\r\n load() {\r\n this.counter = this.counter + this.increment\r\n this.update()\r\n this.updatePageState()\r\n }\r\n\r\n update() {\r\n // Read scroll height in batch\r\n let btnCollapseMaxHeight = this.counter < this.items.length ? this.btnCollapse.scrollHeight : 0\r\n let itemsMaxHeight = []\r\n for (let i = 0; i < this.items.length; i++) {\r\n itemsMaxHeight[i] = 0\r\n if (i < this.counter) {\r\n itemsMaxHeight[i] = this.items[i].scrollHeight\r\n }\r\n }\r\n // Write in batch\r\n for (var i = 0; i < this.items.length; i++) {\r\n this.items[i].style.setProperty('--load-more-max-height', `${itemsMaxHeight[i] || (i < this.counter ? 9999 : 0)}px`)\r\n }\r\n this.btnCollapse.style.setProperty('--load-more-max-height', `${btnCollapseMaxHeight}px`)\r\n }\r\n\r\n updatePageState() {\r\n if (this.id) {\r\n PageState.set(`load-more-counter-${this.id}`, this.counter)\r\n }\r\n }\r\n\r\n destroy() {\r\n !this.btn || this.btn.removeEventListener(\"click\", this.loadHandler)\r\n window.removeEventListener(\"resize\", this.updateHandler)\r\n\r\n delete this.loadHandler\r\n delete this.updateHandler\r\n\r\n delete this.node\r\n delete this.id\r\n delete this.increment\r\n delete this.items\r\n delete this.btn\r\n delete this.btnCollapse\r\n delete this.counter\r\n }\r\n}\r\n\r\nnew PageComponent(\"[data-load-more]\", LoadMore)\r\n"],"sourceRoot":""}