Website Summary Files Commits Branches @commit @diff @stats
path: root / wp-content / themes / carmag / assets / src / scripts / scripts.js
diff options
context:
space:
mode:
Commite962470e9fc7da812aed4188c897a96a1a480772 (patch)
Author
 Ivan Dimitrov <ivan.dimitrov293@gmail.com>
2020-07-14 23:27:39 +0300
Committer
 Ivan Dimitrov <ivan.dimitrov293@gmail.com>
2020-07-14 23:27:39 +0300
Files929f3d72a149311592e3d36e410203a6055b00a5 /wp-content/themes/carmag/assets/src/scripts/scripts.js
tues-interns-2020-feature/simple-search.tar
tues-interns-2020-feature/simple-search.tar.gz
tues-interns-2020-feature/simple-search.zip
Parentcc63885688f80a597a69fcae6819e079079f0921 (diff)
[Update] Refactored the whole search. Fixed responsive design and category select feature/simple-search
1 files changed, 35 insertions, 22 deletions
-rwxr-xr-xwp-content/themes/carmag/assets/src/scripts/scripts.js57
diff --git a/wp-content/themes/carmag/assets/src/scripts/scripts.js b/wp-content/themes/carmag/assets/src/scripts/scripts.js
index f58c82e..93e8823 100755
--- a/wp-content/themes/carmag/assets/src/scripts/scripts.js
+++ b/wp-content/themes/carmag/assets/src/scripts/scripts.js
@@ -46,10 +46,10 @@ faqFields.forEach((field) => {
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);
+ let option = document.createElement("option");
+ option.value = model;
+ option.innerHTML = model;
+ selectedBrand.appendChild(option);
});
const handleModels = () => {
const brand = event.target.value;
@@ -58,18 +58,18 @@ const handleModels = () => {
modelsSelect.innerHTML = "";
modelsSelect.append(defaultOption);
let models;
- if(selectedType.value === "car") {
+ if (selectedType.value === "car") {
models = carModels;
- } else if(selectedType.value === "truck") {
+ } else if (selectedType.value === "truck") {
models = truckModels;
- } else if(selectedType.value === "motorcycle") {
+ } else if (selectedType.value === "motorcycle") {
models = motorcycleModels;
- } else if(selectedType.value === "tractor") {
+ } else if (selectedType.value === "tractor") {
models = agriculturalBrands;
- } else if(selectedType.value === "bus") {
+ } else if (selectedType.value === "bus") {
models = busModels;
}
- if(brand) {
+ if (brand) {
models[brand].forEach((model) => {
let option = document.createElement("option");
option.value = model;
@@ -82,27 +82,27 @@ const handleModels = () => {
option.innerHTML = "Model";
modelsSelect.appendChild(option);
}
-}
+};
let selectedType = document.getElementById("category");
let types = document.querySelectorAll(".type");
-types.forEach(type => {
- type.addEventListener("click", () => {
+types.forEach((type) => {
+ type.addEventListener("click", () => {
event.stopPropagation();
- types.forEach(type => {
+ types.forEach((type) => {
type.classList.remove("selected");
- })
+ });
event.target.classList.add("selected");
selectedType.value = event.target.id;
let models;
- if(selectedType.value === "car") {
+ if (selectedType.value === "car") {
models = carModels;
- } else if(selectedType.value === "truck") {
+ } else if (selectedType.value === "truck") {
models = truckModels;
- } else if(selectedType.value === "motorcycle") {
+ } else if (selectedType.value === "motorcycle") {
models = motorcycleModels;
- } else if(selectedType.value === "tractor") {
+ } else if (selectedType.value === "tractor") {
models = agriculturalBrands;
- } else if(selectedType.value === "bus") {
+ } else if (selectedType.value === "bus") {
models = busModels;
}
modelsNames = Object.keys(models);
@@ -115,5 +115,18 @@ types.forEach(type => {
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,
+ ];
+ });
+}