Skip to content

Commit

Permalink
Refactor each check for a date sort into an object.
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeWannacott committed May 18, 2023
1 parent 4e0e104 commit 227e899
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions public/table-sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,7 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
column,
isFileSize,
isTimeSort,
isSortDateDayMonthYear,
isSortDateMonthDayYear,
isSortDateYearMonthDay,
isSortDates,
isDataAttribute,
} = tableProperties;
for (let [i, tr] of tableRows.entries()) {
Expand All @@ -313,9 +311,9 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
!isFileSize &&
!isDataAttribute &&
!isTimeSort &&
!isSortDateDayMonthYear &&
!isSortDateYearMonthDay &&
!isSortDateMonthDayYear
!isSortDates.dayMonthYear &&
!isSortDates.yearMonthDay &&
!isSortDates.monthDayYear
) {
column.toBeSorted.push(`${tdTextContent}#${i}`);
columnIndexAndTableRow[`${tdTextContent}#${i}`] = tr.outerHTML;
Expand Down Expand Up @@ -465,15 +463,17 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
sortByRuntime(visibleTableRows, column);
}

const isSortDateDayMonthYear = th.classList.contains("dates-dmy-sort");
const isSortDateMonthDayYear = th.classList.contains("dates-mdy-sort");
const isSortDateYearMonthDay = th.classList.contains("dates-ymd-sort");
const isSortDates = {
dayMonthYear: th.classList.contains("dates-dmy-sort"),
monthDayYear: th.classList.contains("dates-mdy-sort"),
yearMonthDay: th.classList.contains("dates-ymd-sort"),
};
// pick mdy first to override the inferred default class which is dmy.
if (isSortDateMonthDayYear) {
if (isSortDates.monthDayYear) {
sortDates("mdy", visibleTableRows, column);
} else if (isSortDateYearMonthDay) {
} else if (isSortDates.yearMonthDay) {
sortDates("ymd", visibleTableRows, column);
} else if (isSortDateDayMonthYear) {
} else if (isSortDates.dayMonthYear) {
sortDates("dmy", visibleTableRows, column);
}

Expand All @@ -486,9 +486,7 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
tableRows: visibleTableRows,
column,
isFileSize,
isSortDateDayMonthYear,
isSortDateMonthDayYear,
isSortDateYearMonthDay,
isSortDates,
isDataAttribute,
isTimeSort,
};
Expand Down

0 comments on commit 227e899

Please sign in to comment.