{"version":3,"sources":["webpack:///./LeLab.Web/src/js/comparator.entry.js","webpack:///./node_modules/js-event-bus/src/index.js"],"names":["eventBus","EventBus","ComparatorState","constructor","on","obj","state","getState","some","x","id","this","setState","emit","filter","window","addEventListener","e","localStorage","setItem","JSON","stringify","storageItem","getItem","parse","PageComponent","node","dataset","compareId","title","compareTitle","image","compareImage","disableUpdate","clickHandler","click","bind","updateHandler","update","classList","contains","remove","add","setTimeout","destroy","removeEventListener","detach","count","animationendHandler","animationend","length","innerText","empty","querySelector","enum","list","template","items","querySelectorAll","stateIds","map","itemsIds","forEach","item","includes","parentNode","removeChild","newItem","document","importNode","content","src","onClickComparatorRemove","append","style","setProperty","href","getAttribute","split","ids","setAttribute","join","body","target","closest","navigator","userAgent","search","location","trigger","createElement","barbaHistory","currentIds","URLSearchParams","substring","get","barba","go","history","module","exports","listeners","registerListener","event","callback","number","type","name","validateNumber","Error","that","push","n","toLowerCase","toBeRemoved","info","execution","eventName","once","exactly","die","off","undefined","k","hasOwnProperty","splice","detachAll","context","Array","prototype","apply","indexOf","newName","replace","match","parentArgs","arguments","index","args","Object","keys","i"],"mappings":"2FAAA,0BAQA,MAyBMA,EAAW,IAjCjB,OAiCqBC,GAOrB,MAAMC,EACFC,cACIH,EAASI,GAZM,MAYaC,IACxB,IAAIC,EAAQJ,EAAgBK,WACxBD,EAAME,KAAKC,GAAKA,EAAEC,KAAOL,EAAIK,MACjCJ,EAAQ,IAAIA,EAAOD,GACnBM,KAAKC,SAASN,GACdN,EAASa,KAfK,SAemB,KAAMP,MAG3CN,EAASI,GAnBS,SAmBaC,IAC3B,IAAIC,EAAQJ,EAAgBK,WAAWO,OAAOL,GAAKA,EAAEC,KAAOL,EAAIK,IAChEC,KAAKC,SAASN,GACdN,EAASa,KArBK,SAqBmB,KAAMP,KAG3CS,OAAOC,iBAAiB,UAAWC,IAC/BjB,EAASa,KAzBK,SAyBmB,KAAMX,EAAgBK,cAI/DK,SAASN,GACLY,aAAaC,QAtDQ,mB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T,KAAaP,EAAKT,UACrBS,EAAKT,UAAUuB,eAAeP,IAChC1G,KAAKmC,OAAOuE,IASlBxG,KAAM,SAASwG,EAAWU,GACxB,IAAI1B,EAAY,GAChB,IAAKM,QAAQG,EAAKT,UAChB,GAAIS,EAAKT,UAAUuB,eAAejB,QAC5BA,OAASU,GAEXW,MAAMC,UAAUlB,KAAKmB,MAAM7B,EAAWS,EAAKT,UAAUM,OAGnDA,KAAKwB,QAAQ,MAAQ,GAAG,CAC1B,IAAIC,EAAUzB,KAAK0B,QAAQ,OAAQ,cACnCD,EAAUA,EAAQC,QAAQ,MAAO,SAEjC,IAAIC,EAAQjB,EAAUiB,MAAMF,GACxBE,GAASjB,IAAciB,EAAM,IAC/BN,MAAMC,UAAUlB,KAAKmB,MAAM7B,EAAWS,EAAKT,UAAUM,OAM7D,IAAI4B,EAAaC,UAEjBT,EAAUA,GAAWpH,KACrB0F,EAAUvC,SAAQ,SAASqD,EAAMsB,GAC/B,IAAIjC,EAAWW,EAAKX,SACPW,EAAKV,OAEdsB,IACFvB,EAAWA,EAASpE,KAAK2F,IAG3B,IAAIW,EAAO,GACXC,OAAOC,KAAKL,GAAY3E,KAAI,SAASiF,GAC/BA,EAAI,GACNH,EAAK3B,KAAKwB,EAAWM,OAKrB/B,EAAKI,YAAYC,IACnBL,EAAKT,UAAUgB,GAAWQ,OAAOY,EAAO,GAG1CjC,EAAS0B,MAAM,KAAMQ,W","file":"comparator.js","sourcesContent":["import { barba, PageComponent } from \"barba\"\r\nimport EventBus from \"js-event-bus\"\r\n\r\n\r\n\r\n/**\r\n * Local storage key into which store state\r\n */\r\nconst COMPARATOR_STATE_KEY = 'comparator-state'\r\n\r\n\r\n\r\n/**\r\n * Event Bus\r\n *\r\n * DO NOT USE 'add' AND 'remove' EVENT TO\r\n * UPDATE DOM STATE! THIS COULD CAUSE\r\n * PROBLEM ACROSS MULTIPLE TABS OR WINDOW.\r\n * USE 'update' EVENT TO UPDATE DISPLAY.\r\n * \r\n * event: 'add'\r\n * args: { id, title, image }\r\n * \r\n * event: 'remove'\r\n * args: { id }\r\n * \r\n * event: 'update'\r\n * args: [{ id, title, image }...]\r\n * \r\n */\r\nconst EVENT_NAME_ADD = 'add'\r\nconst EVENT_NAME_REMOVE = 'remove'\r\nconst EVENT_NAME_UPDATE = 'update'\r\nconst eventBus = new EventBus();\r\n\r\n\r\n\r\n/**\r\n * Central management of comparator state into local storage\r\n */\r\nclass ComparatorState {\r\n constructor() {\r\n eventBus.on(EVENT_NAME_ADD, obj => {\r\n let state = ComparatorState.getState()\r\n if (state.some(x => x.id === obj.id)) return\r\n state = [...state, obj]\r\n this.setState(state)\r\n eventBus.emit(EVENT_NAME_UPDATE, null, state)\r\n })\r\n\r\n eventBus.on(EVENT_NAME_REMOVE, obj => {\r\n let state = ComparatorState.getState().filter(x => x.id !== obj.id)\r\n this.setState(state)\r\n eventBus.emit(EVENT_NAME_UPDATE, null, state)\r\n })\r\n\r\n window.addEventListener('storage', e => {\r\n eventBus.emit(EVENT_NAME_UPDATE, null, ComparatorState.getState())\r\n })\r\n }\r\n\r\n setState(state) {\r\n localStorage.setItem(COMPARATOR_STATE_KEY, JSON.stringify(state))\r\n }\r\n\r\n static getState() {\r\n const storageItem = localStorage.getItem(COMPARATOR_STATE_KEY);\r\n return storageItem ? JSON.parse(storageItem) : []\r\n }\r\n}\r\nnew ComparatorState()\r\n\r\n\r\n\r\n/**\r\n * Compare partial component\r\n * Views/Partials/Components/Compare.cshtml\r\n */\r\nconst COMPARE_CLASS_ADD = 'compare--add'\r\nconst COMPARE_CLASS_ADDED = 'compare--added'\r\nconst COMPARE_CLASS_REMOVE = 'compare--delete'\r\n\r\nclass Compare {\r\n constructor({ node }) {\r\n this.node = node\r\n this.id = node.dataset.compareId\r\n this.title = node.dataset.compareTitle\r\n this.image = node.dataset.compareImage\r\n this.disableUpdate = false\r\n\r\n this.clickHandler = this.click.bind(this)\r\n this.updateHandler = this.update.bind(this)\r\n\r\n this.update(ComparatorState.getState())\r\n\r\n this.node.addEventListener(\"click\", this.clickHandler)\r\n eventBus.on(EVENT_NAME_UPDATE, this.updateHandler)\r\n }\r\n\r\n click() {\r\n const obj = {\r\n id: this.id,\r\n title: this.title,\r\n image: this.image\r\n }\r\n\r\n // Add\r\n if (this.node.classList.contains(COMPARE_CLASS_ADD)) {\r\n this.disableUpdate = true\r\n\r\n eventBus.emit(EVENT_NAME_ADD, null, obj)\r\n\r\n this.node.classList.remove(COMPARE_CLASS_ADD)\r\n this.node.classList.add(COMPARE_CLASS_ADDED)\r\n\r\n setTimeout(() => {\r\n this.disableUpdate = false\r\n this.update(ComparatorState.getState())\r\n }, 2000)\r\n\r\n return\r\n }\r\n \r\n // Remove\r\n if (this.node.classList.contains(COMPARE_CLASS_REMOVE)) {\r\n this.disableUpdate = false\r\n eventBus.emit(EVENT_NAME_REMOVE, null, obj)\r\n return\r\n }\r\n }\r\n\r\n update(state) {\r\n if (this.disableUpdate) {\r\n return\r\n }\r\n\r\n this.node.classList.remove(COMPARE_CLASS_ADD, COMPARE_CLASS_ADDED, COMPARE_CLASS_REMOVE)\r\n\r\n if (state.some(x => x.id === this.id)) {\r\n this.node.classList.add(COMPARE_CLASS_REMOVE)\r\n return\r\n }\r\n\r\n this.node.classList.add(COMPARE_CLASS_ADD)\r\n }\r\n\r\n destroy() {\r\n this.node.removeEventListener(\"click\", this.clickHandler)\r\n\r\n eventBus.detach(EVENT_NAME_UPDATE, this.updateHandler)\r\n\r\n delete this.node\r\n delete this.id\r\n delete this.title\r\n delete this.image\r\n delete this.disableUpdate\r\n\r\n delete this.clickHandler\r\n delete this.updateHandler\r\n }\r\n}\r\nnew PageComponent(\".compare\", Compare)\r\n\r\n\r\n\r\n/**\r\n * Update header comparator counter\r\n */\r\nconst HEADER_COMARATOR_COUNT_CLASS_BLINK = 'header-comparator__count--blink'\r\nconst HEADER_COMARATOR_COUNT_CLASS_HIDDEN = 'hidden'\r\n\r\nclass HeaderComparatorCount {\r\n constructor({ node }) {\r\n this.node = node\r\n this.count = null\r\n this.updateHandler = this.update.bind(this)\r\n this.animationendHandler = this.animationend.bind(this)\r\n\r\n this.update(ComparatorState.getState())\r\n\r\n this.node.addEventListener('animationend', this.animationendHandler)\r\n eventBus.on(EVENT_NAME_UPDATE, this.updateHandler)\r\n }\r\n\r\n update(state) {\r\n const count = state.length\r\n\r\n // Update text\r\n this.node.innerText = count\r\n\r\n // Visibility\r\n if (count <= 0) {\r\n this.node.classList.add(HEADER_COMARATOR_COUNT_CLASS_HIDDEN)\r\n } else {\r\n this.node.classList.remove(HEADER_COMARATOR_COUNT_CLASS_HIDDEN)\r\n }\r\n\r\n // Quit if initial (null), same or lower\r\n if (this.count === null || this.count >= count) {\r\n this.count = count\r\n return\r\n }\r\n\r\n // Blink animation not playing, do it\r\n if (!this.node.classList.contains(HEADER_COMARATOR_COUNT_CLASS_BLINK)) {\r\n this.node.classList.add(HEADER_COMARATOR_COUNT_CLASS_BLINK)\r\n }\r\n\r\n // Save count\r\n this.count = count\r\n }\r\n\r\n animationend() {\r\n this.node.classList.remove(HEADER_COMARATOR_COUNT_CLASS_BLINK)\r\n }\r\n\r\n destroy() {\r\n this.node.removeEventListener('animationend', this.animationendHandler)\r\n\r\n eventBus.detach(EVENT_NAME_UPDATE, this.updateHandler)\r\n\r\n delete this.node\r\n delete this.count\r\n delete this.updateHandler\r\n delete this.animationendHandler\r\n }\r\n}\r\nnew PageComponent(\".header-comparator__count\", HeaderComparatorCount)\r\n\r\n\r\n\r\n/**\r\n * Update header comparator dropdown\r\n */\r\nclass HeaderComparatorDropdown {\r\n constructor({ node }) {\r\n this.node = node\r\n this.empty = this.node.querySelector('.header-comparator__empty')\r\n this.enum = this.node.querySelector('.header-comparator__enum')\r\n this.list = this.node.querySelector('.header-comparator__list')\r\n this.template = this.list.querySelector('template')\r\n\r\n this.updateHandler = this.update.bind(this)\r\n this.update(ComparatorState.getState())\r\n eventBus.on(EVENT_NAME_UPDATE, this.updateHandler)\r\n }\r\n\r\n update(state) {\r\n // Is empty\r\n if (state.length <= 0) {\r\n this.empty.classList.remove('hidden')\r\n this.enum.classList.add('hidden')\r\n return\r\n }\r\n\r\n // Existing items element\r\n const items = [...this.list.querySelectorAll('.header-comparator__item')]\r\n\r\n // Array of ids in state and items\r\n const stateIds = state.map(x => x.id)\r\n const itemsIds = items.map(x => x.dataset.id)\r\n \r\n // Remove items not in state\r\n items.forEach(item => {\r\n if (stateIds.includes(item.dataset.id)) {\r\n return\r\n }\r\n item.parentNode.removeChild(item)\r\n })\r\n\r\n // Add new items\r\n state.forEach(obj => {\r\n if (itemsIds.includes(obj.id)) {\r\n return\r\n }\r\n \r\n let newItem = document.importNode(this.template.content, true)\r\n newItem.querySelectorAll('.header-comparator__item').forEach(x => x.dataset.id = obj.id)\r\n newItem.querySelectorAll('.header-comparator__item-img').forEach(x => { x.src = `${obj.image}?mode=max&bgcolor=FFFFFF&format=jpeg&width=160&height=128` })\r\n newItem.querySelectorAll('.header-comparator__item-title').forEach(x => x.innerText = obj.title)\r\n newItem.querySelectorAll('.header-comparator__item-delete').forEach(x => x.dataset.onClickComparatorRemove = obj.id)\r\n\r\n this.list.append(newItem)\r\n newItem = null\r\n })\r\n\r\n // Hide empty, show list\r\n this.empty.classList.add('hidden')\r\n this.enum.classList.remove('hidden')\r\n }\r\n\r\n destroy() {\r\n eventBus.detach(EVENT_NAME_UPDATE, this.updateHandler)\r\n\r\n delete this.node\r\n delete this.empty \r\n delete this.enum\r\n delete this.list\r\n delete this.template\r\n\r\n delete this.updateHandler\r\n }\r\n}\r\nnew PageComponent(\".header-comparator__dropdown\", HeaderComparatorDropdown)\r\n\r\n\r\n\r\n/**\r\n * Mobile header visibility when item added to caparator\r\n */\r\nclass HeaderMobileVisibility {\r\n constructor({ node }) {\r\n this.node = node\r\n this.count = null\r\n this.updateHandler = this.update.bind(this)\r\n\r\n this.update(ComparatorState.getState())\r\n\r\n eventBus.on(EVENT_NAME_UPDATE, this.updateHandler)\r\n }\r\n\r\n update(state) {\r\n const count = state.length\r\n\r\n // Quit if initial (null), same or lower\r\n if (this.count === null || this.count >= count) {\r\n this.count = count\r\n return\r\n }\r\n\r\n // Update offset css custom properties to force reveal\r\n this.node.style.setProperty('--header-offset-y', '0px')\r\n\r\n // Save count\r\n this.count = count\r\n }\r\n\r\n destroy() {\r\n eventBus.detach(EVENT_NAME_UPDATE, this.updateHandler)\r\n\r\n delete this.node\r\n delete this.count\r\n delete this.updateHandler\r\n }\r\n}\r\nnew PageComponent(\".header\", HeaderMobileVisibility)\r\n\r\n\r\n\r\n/**\r\n * Update HREF of link\r\n */\r\nclass ComparatorHref {\r\n constructor({ node }) {\r\n this.node = node\r\n this.href = node.getAttribute('href').split('?')[0]\r\n this.updateHandler = this.update.bind(this)\r\n\r\n this.update(ComparatorState.getState())\r\n eventBus.on(EVENT_NAME_UPDATE, this.updateHandler)\r\n }\r\n\r\n update(state) {\r\n const ids = state.map(x => x.id)\r\n\r\n if (ids && ids.length > 0) {\r\n this.node.setAttribute('href', `${this.href}?id=${ids.join(',')}`)\r\n return\r\n }\r\n \r\n this.node.setAttribute('href', this.href)\r\n }\r\n\r\n destroy() {\r\n eventBus.detach(EVENT_NAME_UPDATE, this.updateHandler)\r\n\r\n delete this.node\r\n delete this.href\r\n delete this.updateHandler\r\n }\r\n}\r\nnew PageComponent(\"a[href][data-comparator-href]\", ComparatorHref)\r\n\r\n\r\n\r\n/**\r\n * Data attribue applied to element, when clicked,\r\n * remove the ID from the state.\r\n * \r\n * data-on-click-comparator-remove=\"ID\"\r\n */\r\nclass OnClickComparatorRemove {\r\n constructor() {\r\n document.body.addEventListener(\r\n 'click',\r\n e => {\r\n const node = e.target.closest('[data-on-click-comparator-remove]')\r\n if (!node) return\r\n // Hotfix, timeout solve problem with \"is-within\" (class IsWithinClass)\r\n setTimeout(() => {\r\n eventBus.emit(EVENT_NAME_REMOVE, null, { id: node.dataset.onClickComparatorRemove })\r\n }, 0)\r\n }\r\n )\r\n }\r\n}\r\nnew OnClickComparatorRemove()\r\n\r\n\r\n\r\n/**\r\n * Add scroll-snap to compatible browsers\r\n */\r\nclass ComparatorScrollSnap {\r\n constructor({ node }) {\r\n if (navigator.userAgent.search(\"Firefox\") === -1) {\r\n node.classList.add('comparator--snap')\r\n }\r\n }\r\n destroy() {}\r\n}\r\nnew PageComponent(\".comparator\", ComparatorScrollSnap)\r\n\r\n\r\n\r\n/**\r\n * Update HREF of link\r\n */\r\nclass ComparatorReload {\r\n constructor({ node }) {\r\n this.node = node\r\n this.href = location.href.split('?')[0]\r\n\r\n // This will be used with barba.go(url, trigger)\r\n // has the trigger argument (which will replace the history)\r\n this.trigger = document.createElement('a')\r\n this.trigger.dataset.barbaHistory = 'replace'\r\n\r\n this.updateHandler = this.update.bind(this)\r\n\r\n this.update(ComparatorState.getState())\r\n eventBus.on(EVENT_NAME_UPDATE, this.updateHandler)\r\n }\r\n\r\n update(state) {\r\n const currentParams = new URLSearchParams(document.location.search.substring(1))\r\n const currentIds = currentParams.get(\"id\")\r\n const stateIds = state.map(x => x.id).join(',')\r\n\r\n if (currentIds === stateIds) {\r\n return\r\n }\r\n\r\n if (stateIds) {\r\n barba.go(`${this.href}?id=${stateIds}`, this.trigger)\r\n return\r\n }\r\n\r\n barba.history.add(this.href, this.trigger)\r\n }\r\n\r\n destroy() {\r\n eventBus.detach(EVENT_NAME_UPDATE, this.updateHandler)\r\n\r\n delete this.node\r\n delete this.href\r\n delete this.updateHandler\r\n }\r\n}\r\nnew PageComponent(\".comparator\", ComparatorReload)\r\n","(function(caller, bus) {\n if (typeof exports === 'object' && typeof module === 'object') {\n module.exports = bus();\n } else if (typeof exports === 'object') {\n exports.EventBus = bus();\n } else {\n caller.EventBus = bus();\n }\n})(this, function() {\n var EventBus = function() {\n this.listeners = {};\n\n this.registerListener = function(event, callback, number) {\n var type = event.constructor.name;\n number = this.validateNumber(number || 'any');\n\n if (type !== 'Array') {\n event = [event];\n }\n\n event.forEach(function(e) {\n if (e.constructor.name !== 'String') {\n throw new Error(\n 'Only `String` and array of `String` are accepted for the event names!'\n );\n }\n\n that.listeners[e] = that.listeners[e] || [];\n that.listeners[e].push({\n callback: callback,\n number: number,\n });\n });\n };\n\n // valiodate that the number is a vild number for the number of executions\n this.validateNumber = function(n) {\n var type = n.constructor.name;\n\n if (type === 'Number') {\n return n;\n } else if (type === 'String' && n.toLowerCase() === 'any') {\n return 'any';\n }\n\n throw new Error(\n 'Only `Number` and `any` are accepted in the number of possible executions!'\n );\n };\n\n // return wether or not this event needs to be removed\n this.toBeRemoved = function(info) {\n var number = info.number;\n info.execution = info.execution || 0;\n info.execution++;\n\n if (number === 'any' || info.execution < number) {\n return false;\n }\n\n return true;\n };\n\n var that = this;\n return {\n /**\n * Attach a callback to an event\n * @param {string} eventName - name of the event.\n * @param {function} callback - callback executed when this event is triggered\n */\n on: function(eventName, callback) {\n that.registerListener.bind(that)(eventName, callback, 'any');\n },\n\n /**\n * Attach a callback to an event. This callback will not be executed more than once if the event is trigger mutiple times\n * @param {string} eventName - name of the event.\n * @param {function} callback - callback executed when this event is triggered\n */\n once: function(eventName, callback) {\n that.registerListener.bind(that)(eventName, callback, 1);\n },\n\n /**\n * Attach a callback to an event. This callback will be executed will not be executed more than the number if the event is trigger mutiple times\n * @param {number} number - max number of executions\n * @param {string} eventName - name of the event.\n * @param {function} callback - callback executed when this event is triggered\n */\n exactly: function(number, eventName, callback) {\n that.registerListener.bind(that)(eventName, callback, number);\n },\n\n /**\n * Kill an event with all it's callbacks\n * @param {string} eventName - name of the event.\n */\n die: function(eventName) {\n delete that.listeners[eventName];\n },\n\n /**\n * Kill an event with all it's callbacks\n * @param {string} eventName - name of the event.\n */\n off: function(eventName) {\n this.die(eventName);\n },\n\n /**\n * Remove the callback for the given event\n * @param {string} eventName - name of the event.\n * @param {callback} callback - the callback to remove (undefined to remove all of them).\n */\n detach: function(eventName, callback) {\n if (callback === undefined) {\n that.listeners[eventName] = [];\n return true;\n }\n\n for (var k in that.listeners[eventName]) {\n if (\n that.listeners[eventName].hasOwnProperty(k) &&\n that.listeners[eventName][k].callback === callback\n ) {\n that.listeners[eventName].splice(k, 1);\n return this.detach(eventName, callback);\n }\n }\n\n return true;\n },\n\n /**\n * Remove all the events\n */\n detachAll: function() {\n for (var eventName in that.listeners) {\n if (that.listeners.hasOwnProperty(eventName)) {\n this.detach(eventName);\n }\n }\n },\n\n /**\n * Emit the event\n * @param {string} eventName - name of the event.\n */\n emit: function(eventName, context) {\n var listeners = [];\n for (name in that.listeners) {\n if (that.listeners.hasOwnProperty(name)) {\n if (name === eventName) {\n //TODO: this lib should definitely use > ES5\n Array.prototype.push.apply(listeners, that.listeners[name]);\n }\n\n if (name.indexOf('*') >= 0) {\n var newName = name.replace(/\\*\\*/, '([^.]+.?)+');\n newName = newName.replace(/\\*/g, '[^.]+');\n\n var match = eventName.match(newName);\n if (match && eventName === match[0]) {\n Array.prototype.push.apply(listeners, that.listeners[name]);\n }\n }\n }\n }\n\n var parentArgs = arguments;\n\n context = context || this;\n listeners.forEach(function(info, index) {\n var callback = info.callback;\n var number = info.number;\n\n if (context) {\n callback = callback.bind(context);\n }\n\n var args = [];\n Object.keys(parentArgs).map(function(i) {\n if (i > 1) {\n args.push(parentArgs[i]);\n }\n });\n\n // this event cannot be fired again, remove from the stack\n if (that.toBeRemoved(info)) {\n that.listeners[eventName].splice(index, 1);\n }\n\n callback.apply(null, args);\n });\n },\n };\n };\n\n return EventBus;\n});\n"],"sourceRoot":""}