From de573afc8f5f1224a63e519a3aaa67cce9c6e926 Mon Sep 17 00:00:00 2001 From: LeeWannacott Date: Tue, 9 May 2023 23:16:45 +1200 Subject: [PATCH] Fix runtime-sort for github actions runtime not working with textContent. --- npm/package.json | 2 +- public/table-sort.js | 50 +++++++++++++++++++++++++------------------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/npm/package.json b/npm/package.json index 511a4e7..6bf0c34 100644 --- a/npm/package.json +++ b/npm/package.json @@ -1,6 +1,6 @@ { "name": "table-sort-js", - "version": "1.12.0", + "version": "1.12.1", "description": "A JavaScript client-side HTML table sorting library with no dependencies required.", "license": "MIT", "repository": "LeeWannacott/table-sort-js", diff --git a/public/table-sort.js b/public/table-sort.js index fecf815..4a707b4 100644 --- a/public/table-sort.js +++ b/public/table-sort.js @@ -177,30 +177,38 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) { } function sortByRuntime(tableRows, columnData) { - for (let [i, tr] of tableRows.entries()) { - const regexMinutesAndSeconds = /^(\d+h)?\s?(\d+m)?\s?(\d+s)?$/i; - let columnOfTd = tr - .querySelectorAll("td") - .item(columnIndex).textContent; - let match = columnOfTd.match(regexMinutesAndSeconds); - let [minutesInSeconds, hours, seconds, timeinSeconds] = [0, 0, 0, 0]; - if (match) { - const regexHours = match[1]; - if (regexHours) { - hours = Number(regexHours.replace("h", "")) * 60 * 60; - } - const regexMinutes = match[2]; - if (regexMinutes) { - minutesInSeconds = Number(regexMinutes.replace("m", "")) * 60; + try { + for (let [i, tr] of tableRows.entries()) { + const regexMinutesAndSeconds = /^(\d+h)?\s?(\d+m)?\s?(\d+s)?$/i; + let columnOfTd = ""; + // TODO: github actions runtime didn't like textContent, tests didn't like innerText? + if (testingTableSortJS) { + columnOfTd = tr.querySelectorAll("td").item(columnIndex).textContent; + } else { + columnOfTd = tr.querySelectorAll("td").item(columnIndex).innerText; } - const regexSeconds = match[3]; - if (regexSeconds) { - seconds = Number(regexSeconds.replace("s", "")); + let match = columnOfTd.match(regexMinutesAndSeconds); + let [minutesInSeconds, hours, seconds, timeinSeconds] = [0, 0, 0, 0]; + if (match) { + const regexHours = match[1]; + if (regexHours) { + hours = Number(regexHours.replace("h", "")) * 60 * 60; + } + const regexMinutes = match[2]; + if (regexMinutes) { + minutesInSeconds = Number(regexMinutes.replace("m", "")) * 60; + } + const regexSeconds = match[3]; + if (regexSeconds) { + seconds = Number(regexSeconds.replace("s", "")); + } + timeinSeconds = hours + minutesInSeconds + seconds; } - timeinSeconds = hours + minutesInSeconds + seconds; + columnData.push(`${timeinSeconds}#${i}`); + columnIndexAndTableRow[columnData[i]] = tr.innerHTML; } - columnData.push(`${timeinSeconds}#${i}`); - columnIndexAndTableRow[columnData[i]] = tr.innerHTML; + } catch (e) { + console.log(e); } }