{"version":3,"sources":["webpack:///./LeLab.Web/src/js/bike-geometry.entry.js"],"names":["PageComponent","constructor","node","this","heightSelect","querySelector","adjustementCheckbox","frame","table","tableRows","querySelectorAll","userHeight","getDefaultUserHeight","smallest","getSmallestSize","largest","getLargestSize","updateHeightHandler","updateHeight","bind","updateAdjustmentHandler","updateAdjustment","updateMaxHeightHandler","updateMaxHeight","mouseEnterRowHandler","mouseEnterRow","mouseLeaveRowHandler","mouseLeaveRow","addEventListener","forEach","x","window","PageState","get","checked","value","updateTable","style","setProperty","localStorage","setItem","set","requestAnimationFrame","scrollHeight","adjustementSelector","classList","add","remove","sizeMatchesUserHeight","parseInt","dataset","min","max","offsetWidth","innerWidth","rowTitleWidth","cellLeftPos","getBoundingClientRect","left","leftScrollPos","parentNode","scrollLeft","scrollTo","top","behavior","e","id","target","pictureId","element","getItem","selectOptions","options","i","length","destroy","removeEventListener"],"mappings":"2FAAA,kBAwNA,IAAIA,IAAc,iBAnNlB,MAEIC,aAAY,KAAEC,IACVC,KAAKD,KAAOA,EACZC,KAAKC,aAAeD,KAAKD,KAAKG,cAAc,gBAC5CF,KAAKG,oBAAsBH,KAAKD,KAAKG,cAAc,+BACnDF,KAAKI,MAAQJ,KAAKD,KAAKG,cAAc,yBACrCF,KAAKK,MAAQL,KAAKD,KAAKG,cAAc,yBACrCF,KAAKM,UAAYN,KAAKD,KAAKQ,iBAAiB,4BAC5CP,KAAKQ,WAAaR,KAAKS,uBACvBT,KAAKU,SAAWV,KAAKW,kBACrBX,KAAKY,QAAUZ,KAAKa,iBAEpBb,KAAKc,oBAAsBd,KAAKe,aAAaC,KAAKhB,MAClDA,KAAKiB,wBAA0BjB,KAAKkB,iBAAiBF,KAAKhB,MAC1DA,KAAKmB,uBAAyBnB,KAAKoB,gBAAgBJ,KAAKhB,MACxDA,KAAKqB,qBAAuBrB,KAAKsB,cAAcN,KAAKhB,MACpDA,KAAKuB,qBAAuBvB,KAAKwB,cAAcR,KAAKhB,MAEpDA,KAAKC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AUE,OAAO,UAIjCpB,cAAcsC,GACV,MAAMC,EAAKD,EAAEE,OAAOjB,QAAQkB,UAC5B,IAAKF,EACD,OAEJ,MAAMG,EAAUlE,KAAKD,KAAKG,cAAV,WAA4B6D,IACxCG,GACAA,EAAQxB,UAAUC,IAAI,UAI9BlC,uBACI,MAAMD,EAAa4B,aAAa+B,QA5KpB,eA6KNC,EAAgBpE,KAAKC,aAAaoE,QACxC,GAAmB,OAAf7D,EACA,OAAO,KAEX,IAAK,IAAI8D,EAAI,EAAGA,EAAIF,EAAcG,OAAQD,IACtC,GAAIF,EAAcE,GAAGtC,QAAUxB,EAC3B,OAAOA,EAGf,OAAO,KAGXgE,UACIxE,KAAKC,aAAawE,oBAAoB,SAAUzE,KAAKc,qBACrDd,KAAKM,UAAUoB,QAAQC,GAAKA,EAAE8C,oBAAoB,aAAczE,KAAKqB,uBACrErB,KAAKM,UAAUoB,QAAQC,GAAKA,EAAE8C,oBAAoB,aAAczE,KAAKuB,uBACrEK,OAAO6C,oBAAoB,SAAUzE,KAAKmB,wBAEtCnB,KAAKG,qBACLH,KAAKG,oBAAoBsE,oBAAoB,SAAUzE,KAAKiB,gCAGzDjB,KAAKc,2BACLd,KAAKiB,+BACLjB,KAAKmB,8BACLnB,KAAKqB,4BACLrB,KAAKuB,4BAELvB,KAAKD,YACLC,KAAKC,oBACLD,KAAKG,2BACLH,KAAKI,aACLJ,KAAKK,aACLL,KAAKM,iBACLN,KAAKQ,kBACLR,KAAKU,gBACLV,KAAKY,a","file":"bike-geometry.js","sourcesContent":["import { PageComponent, PageState } from \"barba\"\r\n\r\nconst USER_HEIGHT = 'user-height'\r\nconst ADJUSTMENT_CHECKED = 'bike-geometry-adjustment-checked'\r\n\r\nclass BikeGeometryClass {\r\n\r\n constructor({ node }) {\r\n this.node = node\r\n this.heightSelect = this.node.querySelector('.form-select')\r\n this.adjustementCheckbox = this.node.querySelector('.bike-geometry__check-input')\r\n this.frame = this.node.querySelector('.bike-geometry__frame')\r\n this.table = this.node.querySelector('.bike-geometry__table')\r\n this.tableRows = this.node.querySelectorAll('.bike-geometry__table-tr')\r\n this.userHeight = this.getDefaultUserHeight()\r\n this.smallest = this.getSmallestSize()\r\n this.largest = this.getLargestSize()\r\n\r\n this.updateHeightHandler = this.updateHeight.bind(this)\r\n this.updateAdjustmentHandler = this.updateAdjustment.bind(this)\r\n this.updateMaxHeightHandler = this.updateMaxHeight.bind(this)\r\n this.mouseEnterRowHandler = this.mouseEnterRow.bind(this)\r\n this.mouseLeaveRowHandler = this.mouseLeaveRow.bind(this)\r\n\r\n this.heightSelect.addEventListener('change', this.updateHeightHandler)\r\n this.tableRows.forEach(x => x.addEventListener('mouseenter', this.mouseEnterRowHandler))\r\n this.tableRows.forEach(x => x.addEventListener('mouseleave', this.mouseLeaveRowHandler))\r\n window.addEventListener(\"resize\", this.updateMaxHeightHandler)\r\n\r\n if (this.adjustementCheckbox) {\r\n if (PageState.get(ADJUSTMENT_CHECKED) !== null) {\r\n this.adjustementCheckbox.checked = PageState.get(ADJUSTMENT_CHECKED)\r\n }\r\n this.adjustementCheckbox.addEventListener('change', this.updateAdjustmentHandler)\r\n }\r\n \r\n if (this.userHeight !== null) {\r\n this.heightSelect.value = this.userHeight\r\n }\r\n \r\n this.updateTable()\r\n this.updateMaxHeight()\r\n \r\n this.frame.style.setProperty('--bike-geometry-frame-height', 'auto')\r\n }\r\n\r\n updateHeight() {\r\n localStorage.setItem(USER_HEIGHT, this.heightSelect.value)\r\n this.userHeight = this.heightSelect.value\r\n this.updateTable()\r\n this.updateMaxHeight()\r\n }\r\n\r\n updateAdjustment() {\r\n if (!this.adjustementCheckbox) {\r\n return\r\n }\r\n PageState.set(ADJUSTMENT_CHECKED, this.adjustementCheckbox.checked)\r\n\r\n this.updateTable()\r\n }\r\n\r\n updateMaxHeight() {\r\n window.requestAnimationFrame(() => !this.frame || this.frame.style.setProperty('--bike-geometry-frame-max-height', `${this.frame.scrollHeight}px`))\r\n }\r\n\r\n updateTable() {\r\n let adjustementSelector = `[data-adjustment]`\r\n\r\n // Hide all\r\n this.table.querySelectorAll(adjustementSelector).forEach(x => x.classList.add('hidden'))\r\n this.table.querySelectorAll(adjustementSelector).forEach(x => x.classList.remove('bike-geometry__cell-selected'))\r\n\r\n // Show matching adjustement within min / max\r\n if (this.adjustementCheckbox) {\r\n adjustementSelector = `[data-adjustment=\"${this.adjustementCheckbox.value}\"]`\r\n if (!this.adjustementCheckbox.checked) {\r\n adjustementSelector = `:not(${adjustementSelector})`\r\n }\r\n }\r\n\r\n \r\n this.table.querySelectorAll(adjustementSelector).forEach(x => {\r\n x.classList.remove('hidden')\r\n if (this.sizeMatchesUserHeight(\r\n parseInt(x.dataset.min), \r\n parseInt(x.dataset.max)\r\n )) {\r\n x.classList.add('bike-geometry__cell-selected')\r\n }\r\n })\r\n\r\n /* Scroll to selected element on mobile */\r\n if (this.userHeight !== null) {\r\n if (this.table.offsetWidth > window.innerWidth) {\r\n const rowTitleWidth = this.table.querySelector('.bike-geometry__table-td--row-title').offsetWidth;\r\n const cellLeftPos = this.table.querySelector('.bike-geometry__cell-selected').getBoundingClientRect().left;\r\n const leftScrollPos = this.table.parentNode.scrollLeft\r\n\r\n this.table.parentNode.scrollTo({\r\n top: 0,\r\n left: (cellLeftPos + leftScrollPos) - rowTitleWidth,\r\n behavior: 'smooth'\r\n }); \r\n }\r\n }\r\n \r\n }\r\n \r\n sizeMatchesUserHeight(min, max) {\r\n if (this.userHeight === null) return false;\r\n \r\n const userHeight = parseInt(this.userHeight);\r\n \r\n if (min === this.smallest && userHeight <= this.smallest) return true;\r\n if (max === this.largest && userHeight >= this.largest) return true;\r\n \r\n // Note: modifié de 2 à 0 dans la tâche DV-8\r\n // Le nouvel affichage fait en sorte qu'il n'est plus nécessaire \r\n // de sélectionner les tailles \"proches\" de la taille sélectionnée\r\n const fuzzyFactor = 0;\r\n min -= fuzzyFactor;\r\n max += fuzzyFactor;\r\n \r\n return userHeight >= min && userHeight <= max;\r\n }\r\n\r\n getSmallestSize() {\r\n let smallest = 9999;\r\n\r\n this.table.querySelectorAll(\"[data-adjustment]\").forEach(x => {\r\n const min = parseInt(x.dataset.min);\r\n if (min < smallest)\r\n smallest = min;\r\n })\r\n\r\n return smallest;\r\n }\r\n\r\n getLargestSize() {\r\n let largest = 0;\r\n\r\n this.table.querySelectorAll(\"[data-adjustment]\").forEach(x => {\r\n const max = parseInt(x.dataset.max);\r\n if (max > largest)\r\n largest = max;\r\n })\r\n\r\n return largest;\r\n }\r\n\r\n mouseEnterRow(e) {\r\n const id = e.target.dataset.pictureId\r\n if (!id) {\r\n return\r\n }\r\n const element = this.node.querySelector(`#${id}`);\r\n if (element) {\r\n element.classList.remove('hidden')\r\n }\r\n }\r\n\r\n mouseLeaveRow(e) {\r\n const id = e.target.dataset.pictureId\r\n if (!id) {\r\n return\r\n }\r\n const element = this.node.querySelector(`#${id}`);\r\n if (element) {\r\n element.classList.add('hidden')\r\n }\r\n }\r\n\r\n getDefaultUserHeight() {\r\n const userHeight = localStorage.getItem(USER_HEIGHT)\r\n const selectOptions = this.heightSelect.options\r\n if (userHeight === null) {\r\n return null\r\n }\r\n for (let i = 0; i < selectOptions.length; i++) {\r\n if (selectOptions[i].value === userHeight) {\r\n return userHeight\r\n }\r\n }\r\n return null\r\n }\r\n\r\n destroy() {\r\n this.heightSelect.removeEventListener('change', this.updateHeightHandler)\r\n this.tableRows.forEach(x => x.removeEventListener('mouseenter', this.mouseEnterRowHandler))\r\n this.tableRows.forEach(x => x.removeEventListener('mouseleave', this.mouseLeaveRowHandler))\r\n window.removeEventListener(\"resize\", this.updateMaxHeightHandler)\r\n\r\n if (this.adjustementCheckbox) {\r\n this.adjustementCheckbox.removeEventListener('change', this.updateAdjustmentHandler)\r\n }\r\n\r\n delete this.updateHeightHandler\r\n delete this.updateAdjustmentHandler\r\n delete this.updateMaxHeightHandler\r\n delete this.mouseEnterRowHandler\r\n delete this.mouseLeaveRowHandler\r\n\r\n delete this.node\r\n delete this.heightSelect\r\n delete this.adjustementCheckbox\r\n delete this.frame\r\n delete this.table\r\n delete this.tableRows\r\n delete this.userHeight\r\n delete this.smallest\r\n delete this.largest\r\n }\r\n\r\n}\r\n\r\nnew PageComponent(\".bike-geometry\", BikeGeometryClass)"],"sourceRoot":""}