Website Summary Files Commits Branches @commit @diff @stats
path: root / wp-content / themes / carmag / assets / src / scripts / scripts.js
diff options
context:
space:
mode:
Commita50693feaa8cf7a923b14c36df9eddce4af16078 (patch)
Author
 Ivan Dimitrov <ivan.dimitrov293@gmail.com>
2020-07-15 16:45:36 +0300
Committer
 GitHub <noreply@github.com>
2020-07-15 16:45:36 +0300
Filesc14196ea287e28117088685344b26404e57a94a8 /wp-content/themes/carmag/assets/src/scripts/scripts.js
tues-interns-2020-a50693feaa8cf7a923b14c36df9eddce4af16078.tar
tues-interns-2020-a50693feaa8cf7a923b14c36df9eddce4af16078.tar.gz
tues-interns-2020-a50693feaa8cf7a923b14c36df9eddce4af16078.zip
Parent2094746a9b50fb25c0abdb2c70dee45cec8b919f (diff)
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 <victor@gorchilov.com> Co-authored-by: Chris <kristiyan.kkirilov@gmail.com> Co-authored-by: metodiew <stanko@metodiew.com> Co-authored-by: root <root@dxdemos.online>
1 files changed, 92 insertions, 5 deletions
-rw-r--r--wp-content/themes/carmag/assets/src/scripts/scripts.js97
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;