From a50693feaa8cf7a923b14c36df9eddce4af16078 Mon Sep 17 00:00:00 2001 From: Ivan Dimitrov Date: Wed, 15 Jul 2020 16:45:36 +0300 Subject: Feature/homepage (#110) * [Update] Created vehicle card * [Update] add grid layout * [Fix] stylize cards and use custom class for flow * [Update] Added 'Read more' to the vehicle card * [Update] Added 'Read more' to the vehicle card * [Update] Added the grid layout in homepage with recent offers. * [Update] Removed the leftover font-awesome plugin * Added simple search front-end scss and php * Fixed Brand and Model fields, connect them to script.js and models.js correctly * [Update] Refactored the whole search. Fixed responsive design and category select * [Update] Merged feature/simple-search * [Update] Changed the search url * [Update] Connected the backend with latest offers in the hompage. No more dummy content :)) * Change the files and folder permissions and hope for the best Co-authored-by: Victor Gorchilov Co-authored-by: Chris Co-authored-by: metodiew Co-authored-by: root --- .../themes/carmag/assets/src/scripts/scripts.js | 97 ++++++++++++++++++++-- 1 file changed, 92 insertions(+), 5 deletions(-) (limited to 'wp-content/themes/carmag/assets/src/scripts/scripts.js') diff --git a/wp-content/themes/carmag/assets/src/scripts/scripts.js b/wp-content/themes/carmag/assets/src/scripts/scripts.js index 1e5febd..6d6347c 100644 --- a/wp-content/themes/carmag/assets/src/scripts/scripts.js +++ b/wp-content/themes/carmag/assets/src/scripts/scripts.js @@ -47,16 +47,103 @@ faqFields.forEach((field) => { }); }); -var password = document.getElementById("password") - , confirm_password = document.getElementById("confirm_password"); +let selectedBrand = document.getElementById("brands"); +let modelsNames = Object.keys(carModels); +modelsNames.forEach((model) => { + let option = document.createElement("option"); + option.value = model; + option.innerHTML = model; + selectedBrand.appendChild(option); +}); +const handleModels = () => { + const brand = event.target.value; + const modelsSelect = document.getElementById("models"); + const defaultOption = modelsSelect.firstElementChild; + modelsSelect.innerHTML = ""; + modelsSelect.append(defaultOption); + let models; + if (selectedType.value === "car") { + models = carModels; + } else if (selectedType.value === "truck") { + models = truckModels; + } else if (selectedType.value === "motorcycle") { + models = motorcycleModels; + } else if (selectedType.value === "tractor") { + models = agriculturalBrands; + } else if (selectedType.value === "bus") { + models = busModels; + } + if (brand) { + models[brand].forEach((model) => { + let option = document.createElement("option"); + option.value = model; + option.innerHTML = model; + modelsSelect.appendChild(option); + }); + } else { + let option = document.createElement("option"); + option.value = ""; + option.innerHTML = "Model"; + modelsSelect.appendChild(option); + } +}; +let selectedType = document.getElementById("category"); +let types = document.querySelectorAll(".type"); +types.forEach((type) => { + type.addEventListener("click", () => { + event.stopPropagation(); + types.forEach((type) => { + type.classList.remove("selected"); + }); + event.target.classList.add("selected"); + selectedType.value = event.target.id; + let models; + if (selectedType.value === "car") { + models = carModels; + } else if (selectedType.value === "truck") { + models = truckModels; + } else if (selectedType.value === "motorcycle") { + models = motorcycleModels; + } else if (selectedType.value === "tractor") { + models = agriculturalBrands; + } else if (selectedType.value === "bus") { + models = busModels; + } + modelsNames = Object.keys(models); + const defaultOption = selectedBrand.firstElementChild; + selectedBrand.innerHTML = ""; + selectedBrand.append(defaultOption); + modelsNames.forEach((model) => { + let option = document.createElement("option"); + option.value = model; + option.innerHTML = model; + selectedBrand.appendChild(option); + }); + }); +}); + +const switcher = document.querySelectorAll(".switcher")[0]; +if (switcher) { + switcher.addEventListener("click", () => { + event.stopPropagation(); + const firstPrice = document.querySelectorAll(".price-first")[0]; + const secondPrice = document.querySelectorAll(".price-second")[0]; + [firstPrice.value, secondPrice.value] = [ + secondPrice.value, + firstPrice.value, + ]; + }); +} +var password = document.getElementById("password"), + confirm_password = document.getElementById("confirm_password"); function validatePassword() { - if(password.value != confirm_password.value) { + if (password.value != confirm_password.value) { confirm_password.setCustomValidity("Passwords don't match"); } else { - confirm_password.setCustomValidity(''); + confirm_password.setCustomValidity(""); } } password.onchange = validatePassword; -confirm_password.onkeyup = validatePassword; \ No newline at end of file +confirm_password.onkeyup = validatePassword; -- cgit v1.3.1-26-gb76a