From 8736e678f65376842c05b3e1631744bca5ddb369 Mon Sep 17 00:00:00 2001 From: Yury Uvarov Date: Sat, 30 Sep 2023 19:40:29 +0300 Subject: [PATCH] refactoring --- .../src/scripts/helpers/{getColumn.ts => getColumnID.ts} | 4 ++-- package/src/scripts/methods/clickCalendar.ts | 6 +++--- package/src/scripts/methods/createDOM.ts | 8 ++++---- package/src/scripts/methods/createMonths.ts | 2 +- package/src/scripts/methods/createYears.ts | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) rename package/src/scripts/helpers/{getColumn.ts => getColumnID.ts} (83%) diff --git a/package/src/scripts/helpers/getColumn.ts b/package/src/scripts/helpers/getColumnID.ts similarity index 83% rename from package/src/scripts/helpers/getColumn.ts rename to package/src/scripts/helpers/getColumnID.ts index eb4ed91d..dc799743 100644 --- a/package/src/scripts/helpers/getColumn.ts +++ b/package/src/scripts/helpers/getColumnID.ts @@ -1,6 +1,6 @@ import { IVanillaCalendar } from '../../types'; -const getColumn = (self: IVanillaCalendar, columnClass: string, personalClass: string, id: number, dataAttr: string) => { +const getColumnID = (self: IVanillaCalendar, columnClass: string, personalClass: string, id: number, dataAttr: string) => { const columnEls = (self.HTMLElement as HTMLElement).querySelectorAll(`.${self.CSSClasses.column}`) as NodeListOf; const firstColumnID = Number((columnEls[0].querySelector(`.${personalClass}`) as HTMLElement).getAttribute(dataAttr)); const lastColumnID = Number((columnEls[columnEls.length - 1].querySelector(`.${personalClass}`) as HTMLElement).getAttribute(dataAttr)); @@ -17,4 +17,4 @@ const getColumn = (self: IVanillaCalendar, columnClass: string, personalClass: s return id; }; -export default getColumn; +export default getColumnID; diff --git a/package/src/scripts/methods/clickCalendar.ts b/package/src/scripts/methods/clickCalendar.ts index 5d6344fd..59ad66e8 100644 --- a/package/src/scripts/methods/clickCalendar.ts +++ b/package/src/scripts/methods/clickCalendar.ts @@ -6,7 +6,7 @@ import createYears from './createYears'; import generateDate from '../helpers/generateDate'; import mainMethod from './mainMethod'; import handlerMultipleRanged from './handlerMultipleRanged'; -import getColumn from '../helpers/getColumn'; +import getColumnID from '../helpers/getColumnID'; const clickCalendar = (self: IVanillaCalendar) => { (self.HTMLElement as HTMLElement).addEventListener('click', (e) => { @@ -161,7 +161,7 @@ const clickCalendar = (self: IVanillaCalendar) => { } else if (yearItemEl) { if (self.selectedMonth === undefined || !self.dateMin || !self.dateMax) return; self.selectedYear = self.type === 'multiple' - ? getColumn(self, self.CSSClasses.columnYear, self.CSSClasses.year, Number(yearItemEl.dataset.calendarYear), 'data-calendar-selected-year') + ? getColumnID(self, self.CSSClasses.columnYear, self.CSSClasses.year, Number(yearItemEl.dataset.calendarYear), 'data-calendar-selected-year') : Number(yearItemEl.dataset.calendarYear); self.currentType = self.type; if (self.selectedMonth < self.dateMin.getMonth() && self.selectedYear === self.dateMin.getFullYear()) { @@ -187,7 +187,7 @@ const clickCalendar = (self: IVanillaCalendar) => { mainMethod(self); } else if (monthItemEl) { self.selectedMonth = self.type === 'multiple' - ? getColumn(self, self.CSSClasses.columnMonth, self.CSSClasses.month, Number(monthItemEl.dataset.calendarMonth), 'data-calendar-selected-month') + ? getColumnID(self, self.CSSClasses.columnMonth, self.CSSClasses.month, Number(monthItemEl.dataset.calendarMonth), 'data-calendar-selected-month') : Number(monthItemEl.dataset.calendarMonth); if (self.type === 'multiple') { const column = monthItemEl.closest(`.${self.CSSClasses.columnMonth}`) as HTMLElement; diff --git a/package/src/scripts/methods/createDOM.ts b/package/src/scripts/methods/createDOM.ts index 8d47777b..a94d88ae 100644 --- a/package/src/scripts/methods/createDOM.ts +++ b/package/src/scripts/methods/createDOM.ts @@ -1,7 +1,7 @@ -import { IVanillaCalendar, TypesCalendar } from '../../types'; +import { IVanillaCalendar } from '../../types'; import { DOMParser, MultipleParser } from '../helpers/parserComponent'; -const createDOM = (self: IVanillaCalendar, initType?: TypesCalendar, target?: HTMLElement) => { +const createDOM = (self: IVanillaCalendar, target?: HTMLElement) => { const calendarElement = (self.HTMLElement as HTMLElement); calendarElement.classList.add(self.CSSClasses.calendar); @@ -31,7 +31,7 @@ const createDOM = (self: IVanillaCalendar, initType?: TypesCalendar, target?: HT calendarElement.innerHTML = MultipleParser(self, DOMParser(self, self.DOMTemplates.multiple)); break; case 'month': - if (initType === 'multiple') { + if (self.type === 'multiple') { switcherTypeMultiple(self.CSSClasses.columnMonth, self.DOMTemplates.month); break; } @@ -41,7 +41,7 @@ const createDOM = (self: IVanillaCalendar, initType?: TypesCalendar, target?: HT calendarElement.innerHTML = DOMParser(self, self.DOMTemplates.month); break; case 'year': - if (initType === 'multiple') { + if (self.type === 'multiple') { switcherTypeMultiple(self.CSSClasses.columnYear, self.DOMTemplates.year); break; } diff --git a/package/src/scripts/methods/createMonths.ts b/package/src/scripts/methods/createMonths.ts index 7b4856af..f94b53cc 100644 --- a/package/src/scripts/methods/createMonths.ts +++ b/package/src/scripts/methods/createMonths.ts @@ -6,7 +6,7 @@ import showYear from './showYear'; const createMonths = (self: IVanillaCalendar, target?: HTMLElement) => { const selectedMonth = target?.dataset.calendarSelectedMonth ? Number(target?.dataset.calendarSelectedMonth) : self.selectedMonth; self.currentType = 'month'; - createDOM(self, self.type, target); + createDOM(self, target); showMonth(self); showYear(self); diff --git a/package/src/scripts/methods/createYears.ts b/package/src/scripts/methods/createYears.ts index 28e88eba..58e765ca 100644 --- a/package/src/scripts/methods/createYears.ts +++ b/package/src/scripts/methods/createYears.ts @@ -8,7 +8,7 @@ const createYears = (self: IVanillaCalendar, target?: HTMLElement) => { if (self.viewYear === undefined || !self.dateMin || !self.dateMax) return; const selectedYear = target?.dataset.calendarSelectedYear ? Number(target?.dataset.calendarSelectedYear) : self.selectedYear; self.currentType = 'year'; - createDOM(self, self.type, target); + createDOM(self, target); showMonth(self); showYear(self); controlArrows(self);