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pack:///./resources/js/theme/products/_dropdowns.js","webpack:///webpack/bootstrap","webpack:///./resources/js/theme/products/_.js"],"sourcesContent":["document.addEventListener('DOMContentLoaded', function() {\n\n\tdocument.addEventListener('click', function (event) {\n\n\t\t//if the clicked element is a open/close accordion button\n\t\tif (event.target.matches('.custom-product-accordion')) {\n\n\t\t\t//toggle our active class\n\t\t\tevent.target.classList.toggle('custom-product-accordion-active');\n\t\t}\n\t});\n});","document.addEventListener(\"DOMContentLoaded\", function() {\n\n\t//if this is the products archive\n\tif(document.body.classList.contains('post-type-archive-products')) {\n\n\t\t//this will contain the last time a request was run (to prevent multiple firing at once)\n\t\tlet last_request = 0;\n\n\t\t//this will store our previous tax query so we can compare previous/new requests\n\t\tlet prev_tax_query = false;\n\n\t\t//fetch all product selects on this page\n\t\tlet product_selects = document.getElementsByClassName('custom-product-select');\n\n\t\t//loop over the product selects we've found\n\t\tfor(let i = 0; i < product_selects.length; i++) {\n\n\t\t\t//add our onchange event\n\t\t\tproduct_selects[i].onchange = function(event) {\n\n\t\t\t\t//trigger this lookup\n\t\t\t\tcustom_product_lookup(event.target, (i + 1));\n\t\t\t};\n\n\t\t\t//if the value for this dropdown isn't empty\n\t\t\tif(product_selects[i].value != '') {\n\n\t\t\t\t//trigger the event now\n\t\t\t\tcustom_product_lookup(event.target, (i + 1), true);\n\t\t\t}\n\t\t}\n\n\t\tfunction custom_product_lookup(target, pos, force) {\n\n\t\t\t//identify where we want our dropdown stylesheet to be\n\t\t\tlet stylesheet = document.getElementById('bt-sizes-dropdown-logic');\n\n\t\t\t//if we don't have a stylesheet\n\t\t\tif(!stylesheet) {\n\n\t\t\t\t//create one\n\t\t\t\tdocument.head.insertAdjacentHTML(\"beforeend\", ``);\n\t\t\t\tstylesheet = document.getElementById('bt-sizes-dropdown-logic');\n\t\t\t}\n\n\t\t\t//calculate the current time\n\t\t\tlet current_time = Math.floor(Date.now() / 1000);\n\n\t\t\t//if it's not been 1s since the last request\n\t\t\tif(force || !force && last_request < (current_time - 1)) {\n\n\t\t\t\t//set the timestamp of the last request\n\t\t\t\tlast_request = (current_time - 1);\n\n\t\t\t\t//create a new xhr\n\t\t\t\tconst xhr = new XMLHttpRequest();\n\n\t\t\t\t//the following code will run on state change\n\t\t\t\txhr.addEventListener(\"readystatechange\", function () {\n\t\t\t\t\tif (this.readyState === this.DONE) {\n\n\t\t\t\t\t\t//this will be the response from the backend\n\t\t\t\t\t\tlet response = JSON.parse(this.responseText);\n\n\t\t\t\t\t\t//this will contain an array of options that haven't changed based on the new selections\n\t\t\t\t\t\tlet whitelisted_values = [];\n\n\t\t\t\t\t\t//start our styles list\n\t\t\t\t\t\tlet styles = '';\n\n\t\t\t\t\t\t//loop over the responding dropdowns\n\t\t\t\t\t\tObject.entries(response).forEach(([name, values]) => {\n\n\t\t\t\t\t\t\t//write our styles that will disable each option by default\n\t\t\t\t\t\t\tstyles = styles + '.custom-product-select[name=\"' + name + '\"] option { display: none }';\n\t\t\t\t\t\t\tstyles = styles + 'li[id^=\"select2-' + name + '-\"] { display: none }';\n\n\t\t\t\t\t\t\tvalues.forEach((value) => {\n\n\t\t\t\t\t\t\t\t//push to our whitelist\n\t\t\t\t\t\t\t\twhitelisted_values.push(value);\n\n\t\t\t\t\t\t\t\t//write styles that will make our valid options available for use\n\t\t\t\t\t\t\t\tstyles = styles + '.custom-product-select[name=\"' + name + '\"] option[value=\"' + value + '\"] { display: block !important }';\n\t\t\t\t\t\t\t\tstyles = styles + 'li[id^=\"select2-' + name + '-\"][id$=\"-' + value + '\"] { display: block !important }';\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\t//creates a change event we can use to kick select2\n\t\t\t\t\t\tlet change_event = new Event('change');\n\n\t\t\t\t\t\t//start our loop at the current position\n\t\t\t\t\t\tfor(let i = pos; i < product_selects.length; i++) {\n\n\t\t\t\t\t\t\t//if this value hasn't also been returned by the API\n\t\t\t\t\t\t\tif(!whitelisted_values.includes(product_selects[i].value)) {\n\n\t\t\t\t\t\t\t\t//reset the dropdown\n\t\t\t\t\t\t\t\tproduct_selects[i].value = '';\n\t\t\t\t\t\t\t\tproduct_selects[i].dispatchEvent(change_event);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t//append our styles\n\t\t\t\t\t\tstylesheet.innerHTML = styles;\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\t//prep our XHR request\n\t\t\t\txhr.open(\"POST\", '/wp-json/laserred/products/dropdowns');\n\t\t\t\txhr.setRequestHeader(\"Accept\", \"*/*\");\n\t\t\t\txhr.setRequestHeader(\"Content-Type\", \"application/json\");\n\n\t\t\t\t//start building a new tax query for all our dropdowns\n\t\t\t\tlet tax_query = {};\n\n\t\t\t\t//create empty variables for our master and active taxonomies\n\t\t\t\tlet master_tax = false;\n\t\t\t\tlet active_tax = false;\n\n\t\t\t\t//loop over the select dropdowns\n\t\t\t\tfor(let i = 0; i < product_selects.length; i++) {\n\n\t\t\t\t\t//add a key value pair for this dropdown\n\t\t\t\t\ttax_query[product_selects[i].name] = product_selects[i].value;\n\t\t\t\t}\n\n\t\t\t\t//if we don't have a previous tax query\n\t\t\t\tif(!prev_tax_query) {\n\n\t\t\t\t\t//use the current one\n\t\t\t\t\tprev_tax_query = tax_query;\n\t\t\t\t}\n\n\t\t\t\t//loop over the current tax query\n\t\t\t\tfor (const [name, value] of Object.entries(tax_query)) {\n\n\t\t\t\t\t//if we don't have a master tax\n\t\t\t\t\tif(!master_tax) {\n\n\t\t\t\t\t\t//set it to the first element in the loop\n\t\t\t\t\t\tmaster_tax = name;\n\t\t\t\t\t}\n\n\t\t\t\t\t//if the new value is different from the previous value\n\t\t\t\t\tif(value != '' && (value != prev_tax_query[name] || master_tax && tax_query[master_tax] == '')) {\n\n\t\t\t\t\t\t//this is our active tax\n\t\t\t\t\t\tactive_tax = name;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t//save our tax query\n\t\t\t\tprev_tax_query = tax_query;\n\n\t\t\t\t//make our request with the current tax query\n\t\t\t\txhr.send(JSON.stringify({\n\t\t\t\t\t'master': master_tax,\n\t\t\t\t\t'active': active_tax ? active_tax : master_tax,\n\t\t\t\t\t'dropdowns': tax_query\n\t\t\t\t}));\n\t\t\t} else {\n\t\t\t\tconsole.warn('Too many dropdown requests, please wait.');\n\t\t\t}\n\t\t}\n\t}\n});","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","//Require products JS\nrequire('./_accordion');\nrequire('./_dropdowns');"],"names":["document","addEventListener","event","target","matches","classList","toggle","body","contains","custom_product_lookup","pos","force","stylesheet","getElementById","head","insertAdjacentHTML","current_time","Math","floor","Date","now","last_request","xhr","XMLHttpRequest","this","readyState","DONE","response","JSON","parse","responseText","whitelisted_values","styles","Object","entries","forEach","name","values","value","push","change_event","Event","i","product_selects","length","includes","dispatchEvent","innerHTML","open","setRequestHeader","tax_query","master_tax","active_tax","prev_tax_query","send","stringify","console","warn","getElementsByClassName","onchange","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","exports","module","__webpack_modules__","require"],"sourceRoot":""}