Skip to content

Commit

Permalink
Merge pull request #28 from koseckaya/burger-fix
Browse files Browse the repository at this point in the history
Burger fix
  • Loading branch information
SiverianSerpent authored Jan 11, 2023
2 parents b279780 + 5943a11 commit 4ba1210
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 36 deletions.
19 changes: 7 additions & 12 deletions src/modules/checkout.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//@ts-nocheck
import { CheckoutInterface, storageItem } from '../pages/types';
import { isValidCreditCard, isExpireValid, phoneNumberFormat, dataFormat } from '../helpers/validation'
import { setUrlParams } from '../helpers/url';
Expand Down Expand Up @@ -125,12 +124,12 @@ class Checkout implements CheckoutInterface {
if (x) (e.target as HTMLInputElement).value = phoneNumberFormat(x)
}
}
handleCvv = (e: Event): void => {
let x = e.target.value[e.target.value.length - 1]
if (/^\d*\.?\d*$/.test(x) && e.target.value.length < 4) {
handleCvv = (e: Event): string => {
let x: string = (e.target as HTMLInputElement).value[(e.target as HTMLInputElement).value.length - 1]
if (/^\d*\.?\d*$/.test(x) && (e.target as HTMLInputElement).value.length < 4) {
return x
} else {
return e.target.value = e.target.value.slice(0, -1)
return (e.target as HTMLInputElement).value = (e.target as HTMLInputElement).value.slice(0, -1)
}
}
handleData = (e: Event): void => {
Expand Down Expand Up @@ -200,13 +199,9 @@ class Checkout implements CheckoutInterface {
cardNumber?.addEventListener('input', this.handleCardNumber)
const cardCvv = form?.querySelector('#card-cvv')
cardCvv?.addEventListener('input', this.handleCvv)
// cardCvv?.addEventListener('paste', (e) => {
// console.log('paste');
// if (!(/^\d*\.?\d*$/.test(e.target.value))) {
// console.log('paste2');
// return e.target.value = ''
// }
// })
cardCvv?.addEventListener('paste', (e: Event) => {
e.preventDefault();
})

}
render = () => {
Expand Down
17 changes: 3 additions & 14 deletions src/modules/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,6 @@ class Header implements HeaderInterface {
this.handleSearch(e);
}
}
// burgerLogic: EventListener = (e: Event): void => {

// console.log(e)
// const burgerIcon = document.getElementById('nav-icon4') as HTMLDivElement;
// const nav = document.querySelector('.nav');
// if (burgerIcon.classList.contains('open')) {
// burgerIcon.removeAttribute('class');
// nav?.classList.remove('openMenu');
// } else {
// burgerIcon.classList.add('open');
// nav?.classList.add('openMenu');
// }
// }
bind = (): void => {
const search = document.querySelector('.settings__search .settings__btn')
if (search) search.addEventListener('click', this.handleSearch)
Expand Down Expand Up @@ -95,7 +82,9 @@ class Header implements HeaderInterface {
newLi.classList.add('list-item');
clone.setAttribute('style', 'display: block; order: 1; position: unset;');
newLi.appendChild(clone);
menuList.insertAdjacentElement('afterbegin', newLi);
if (!menuList.querySelector('.dope-h1')) {
menuList.insertAdjacentElement('afterbegin', newLi);
}
}
}

Expand Down
19 changes: 10 additions & 9 deletions src/pages/cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ class Cart implements ModuleInterface {
if (!Array.from(arrayOfProductCart).some(el => el.getAttribute('style') === '')) {
this.pageNow -= 1;
let output = document.getElementById('output')
if (output) output.innerText = `${this.pageNow + 1}`;
if (output) output.innerText = `${this.pageNow}`;
this.visibleItems()
};
this.visibleItems()
Expand All @@ -393,34 +393,35 @@ class Cart implements ModuleInterface {
}
)
}
let previousPage = document.querySelector("#subtract") as HTMLButtonElement;
let nextPage = document.querySelector("#add") as HTMLButtonElement;
if (nextPage) nextPage.addEventListener("click", () => {
let productsInLocalStorage = JSON.parse(localStorage.getItem('fullCart') || '');
let pages = Math.ceil(productsInLocalStorage.length / this.itemsPerPage);
if (this.pageNow == pages) nextPage.disabled = true;
if (this.pageNow < pages) {
if (this.pageNow == pages) {
nextPage.style.pointerEvents = 'none';
} else if (this.pageNow < pages) {
this.pageNow += 1
//setUrlParams(this.getCartParams(this.pageNow))
this.changeUrl(this.getCartParams(this.pageNow))
if (nextPage) nextPage.disabled = false;
if (nextPage) nextPage.removeAttribute('style');
let output = document.querySelector("#output") as HTMLSpanElement;
if (output) output.innerText = `${this.pageNow}`;
previousPage.removeAttribute('style');
}
this.visibleItems()
});

let previousPage = document.querySelector("#subtract") as HTMLButtonElement;
if (previousPage) previousPage.addEventListener("click", () => {
console.log(this.pageNow);
if (this.pageNow > 1) {
this.pageNow -= 1;
this.changeUrl(this.getCartParams(this.pageNow))
if (previousPage) previousPage.disabled = false;
if (previousPage) previousPage.removeAttribute('style');
let output = document.querySelector("#output") as HTMLSpanElement;
if (output) output.innerText = `${this.pageNow}`;
this.visibleItems()
nextPage.removeAttribute('style');
} else {
previousPage.disabled = true;
previousPage.style.pointerEvents = 'none';
}
});
if (promoField && promoLabel) {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ class Category implements ModuleInterface {
productViewBtn.addEventListener('change', this.handleProductView)

const searchInput = <HTMLInputElement>document.querySelector('.search-input')
searchInput.value = this.filters.search
searchInput.value = this.filters.search || ''

this.initRangePrice()
this.initRangeRating()
Expand Down

0 comments on commit 4ba1210

Please sign in to comment.