Website Summary Files Commits Branches @commit @diff @stats
path: root / wp-content / themes / carmag / assets / src / scripts / scripts.js
diff options
context:
space:
mode:
Commit1c86fe831289eee3d3c2c963885fd553f40f81d2 (patch)
Author
 Victor Gorchilov <victor@gorchilov.com>
2020-07-15 20:43:05 +0300
Committer
 Victor Gorchilov <victor@gorchilov.com>
2020-07-15 20:43:05 +0300
Files1dc3d183affddf9c040eba8b9ec1e60c9e002d90 /wp-content/themes/carmag/assets/src/scripts/scripts.js
tues-interns-2020-feature/offers-grid.tar
tues-interns-2020-feature/offers-grid.tar.gz
tues-interns-2020-feature/offers-grid.zip
Parent333668c49e98cdfc84cf0702f289bd149fc5fd25 (diff)
[fix] bring changes from master feature/offers-grid
1 files changed, 106 insertions, 1 deletions
-rw-r--r--wp-content/themes/carmag/assets/src/scripts/scripts.js107
diff --git a/wp-content/themes/carmag/assets/src/scripts/scripts.js b/wp-content/themes/carmag/assets/src/scripts/scripts.js
index 93438c7..6d6347c 100644
--- a/wp-content/themes/carmag/assets/src/scripts/scripts.js
+++ b/wp-content/themes/carmag/assets/src/scripts/scripts.js
@@ -22,7 +22,7 @@ jQuery(document).ready(function ($) {
const toggleDrawer = () => {
const drawerClassList = event.target.classList;
- const navClassList = document.querySelectorAll(".menu-primary-container")[0]
+ const navClassList = document.querySelectorAll(".menu-container")[0]
.classList;
drawerClassList.toggle("opened");
navClassList.toggle("opened");
@@ -31,9 +31,13 @@ const toggleDrawer = () => {
const separator = document.createElement("span");
separator.className = "separator";
const loginLink = document.querySelectorAll(".login")[0];
+const profileDropdown = document.querySelectorAll(".profile")[0];
if (loginLink) {
loginLink.before(separator);
}
+if (profileDropdown) {
+ profileDropdown.before(separator);
+}
const faqFields = document.querySelectorAll(".faq-field");
faqFields.forEach((field) => {
@@ -42,3 +46,104 @@ faqFields.forEach((field) => {
field.querySelector(".field-content").classList.toggle("opened");
});
});
+
+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) {
+ confirm_password.setCustomValidity("Passwords don't match");
+ } else {
+ confirm_password.setCustomValidity("");
+ }
+}
+
+password.onchange = validatePassword;
+confirm_password.onkeyup = validatePassword;