{ "version": 3, "sources": ["../../javascript/entrypoints/stitch-your-photo-dropdown.js"], "sourcesContent": ["import Rails from \"@rails/ujs\"\n\ndocument.addEventListener(\"DOMContentLoaded\", () => {\n const drawers = document.getElementsByClassName(\"dropdown__drawer\")\n\n for (let drawer of drawers) {\n const drawerContents = drawer.querySelector(\".dropdown__drawer__contents\")\n const dropdownArrow = drawer.querySelector(\".dropdown__drawer__arrow\")\n const dropdown = drawer.querySelector(\".dropdown__content\")\n\n // If there is a default dropdown open, we should open it.\n if (dropdown.classList.contains(\"active\")) {\n dropdownArrow.classList.add(\"selected\")\n drawer.classList.add(\"selected\")\n dropdown.classList.add(\"active\")\n }\n\n drawerContents.addEventListener(\"click\", function () {\n if (dropdown.classList.contains(\"active\")) {\n dropdownArrow.classList.remove(\"selected\")\n drawer.classList.remove(\"selected\")\n dropdown.classList.remove(\"active\")\n } else {\n closeAllDropdowns()\n dropdownArrow.classList.add(\"selected\")\n drawer.classList.add(\"selected\")\n dropdown.classList.add(\"active\")\n }\n\n const selectedOption = drawer.querySelector(\n \".dropdown__drawer__selected-option\"\n )\n\n if (selectedOption) {\n for (let j = 0; j < dropdown.children.length; j++) {\n const dropdownItems = dropdown.children[j].children\n for (let y = 0; y < dropdownItems.length; y++) {\n // We need to handle the photo upload differently than other options.\n if (drawer.querySelector(\"#stitch-your-photo-upload\")) {\n imageInput.addEventListener(\"change\", function () {\n // We can confidently grab the first file as we will only have one selected.\n selectedOption.textContent = imageInput.files[0].name\n selectedOption.classList.add(\n \"dropdown__drawer__selected-option--selected\"\n )\n })\n } else {\n dropdownItems[y].addEventListener(\"change\", function (event) {\n addSelectedTextContentToDropdown(selectedOption, drawer)\n // We don't want to submit the form if we're adjusting the buying options\n // or accessories.\n const inputType = dropdownItems[y]?.type\n if (inputType != \"radio\" && inputType != \"checkbox\") {\n submitPhotoUploadForm()\n }\n })\n }\n }\n }\n }\n })\n }\n})\n\nconst imageInput = document.getElementById(\n \"quilt_custom_pattern_original_attachment\"\n)\n\nconst closeAllDropdowns = () => {\n const drawers = document.getElementsByClassName(\"dropdown__drawer\")\n\n for (let drawer of drawers) {\n const dropdown = drawer.querySelector(\".dropdown__content\")\n const dropdownArrow = drawer.querySelector(\".dropdown__drawer__arrow\")\n\n drawer.classList.remove(\"selected\")\n dropdown.classList.remove(\"active\")\n dropdownArrow.classList.remove(\"selected\")\n }\n}\n\nconst submitPhotoUploadForm = () => {\n if (imageInput.files.length == 1) {\n Rails.fire(document.getElementById(\"photo-upload-form\"), \"submit\")\n }\n}\n\nconst addSelectedTextContentToDropdown = (selectedOption, drawer) => {\n const selectedOptions = drawer.querySelectorAll(\"option:checked\")\n const selectedRadio = drawer.querySelector(\n \".upload-form__radio input:checked\"\n )\n let selectedOptionText = []\n\n if (selectedOptions.length > 0) {\n selectedOptions.forEach((option) => {\n selectedOptionText.push(option.text)\n })\n } else if (selectedRadio) {\n const radioLabel = selectedRadio.parentElement\n .querySelector(\"label\")\n .innerText.split(\"\\n\")[0]\n selectedOptionText.push(radioLabel)\n }\n\n selectedOption.classList.add(\"dropdown__drawer__selected-option--selected\")\n selectedOption.textContent = selectedOptionText.join(\", \")\n}\n"], "mappings": "kHAAA,IAAAA,EAAkB,SAElB,SAAS,iBAAiB,mBAAoB,IAAM,CAClD,IAAMC,EAAU,SAAS,uBAAuB,kBAAkB,EAElE,QAASC,KAAUD,EAAS,CAC1B,IAAME,EAAiBD,EAAO,cAAc,6BAA6B,EACnEE,EAAgBF,EAAO,cAAc,0BAA0B,EAC/DG,EAAWH,EAAO,cAAc,oBAAoB,EAGtDG,EAAS,UAAU,SAAS,QAAQ,IACtCD,EAAc,UAAU,IAAI,UAAU,EACtCF,EAAO,UAAU,IAAI,UAAU,EAC/BG,EAAS,UAAU,IAAI,QAAQ,GAGjCF,EAAe,iBAAiB,QAAS,UAAY,CAC/CE,EAAS,UAAU,SAAS,QAAQ,GACtCD,EAAc,UAAU,OAAO,UAAU,EACzCF,EAAO,UAAU,OAAO,UAAU,EAClCG,E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B,EAAgBjB,EAAO,cAC3B,mCACF,EACIkB,EAAqB,CAAC,EAE1B,GAAIF,EAAgB,OAAS,EAC3BA,EAAgB,QAASG,GAAW,CAClCD,EAAmB,KAAKC,EAAO,IAAI,CACrC,CAAC,UACQF,EAAe,CACxB,IAAMG,EAAaH,EAAc,cAC9B,cAAc,OAAO,EACrB,UAAU,MAAM;AAAA,CAAI,EAAE,GACzBC,EAAmB,KAAKE,CAAU,CACpC,CAEAf,EAAe,UAAU,IAAI,6CAA6C,EAC1EA,EAAe,YAAca,EAAmB,KAAK,IAAI,CAC3D", "names": ["import_ujs", "drawers", "drawer", "drawerContents", "dropdownArrow", "dropdown", "closeAllDropdowns", "selectedOption", "j", "dropdownItems", "y", "imageInput", "event", "_a", "addSelectedTextContentToDropdown", "inputType", "submitPhotoUploadForm", "Rails", "selectedOptions", "selectedRadio", "selectedOptionText", "option", "radioLabel"] }