Skip to content

Commit 08c2239

Browse files
NPM 1.17.1
1 parent 94cf1a8 commit 08c2239

File tree

10 files changed

+283
-277
lines changed

10 files changed

+283
-277
lines changed

browser-extensions/chrome/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifest_version": 3,
33
"author": "Lee Wannacott",
44
"name": "table-sort-js",
5-
"version": "1.17.0",
5+
"version": "1.17.1",
66
"description": "Makes tables sortable using table-sort-js: https://github.com/LeeWannacott/table-sort-js",
77
"icons": { "48": "icons/t.png" },
88
"browser_action": {
16 Bytes
Binary file not shown.

browser-extensions/chrome/table-sort.js

+18-33
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@ Instructions:
1717

1818
function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
1919
function getHTMLTables() {
20-
if (testingTableSortJS === true) {
21-
const getTagTable = domDocumentWindow.getElementsByTagName("table");
22-
return [getTagTable];
23-
} else {
24-
const getTagTable = document.getElementsByTagName("table");
25-
return [getTagTable];
26-
}
20+
const getTagTable = !testingTableSortJS
21+
? document.getElementsByTagName("table")
22+
: domDocumentWindow.getElementsByTagName("table");
23+
return [getTagTable];
2724
}
2825

2926
const [getTagTable] = getHTMLTables();
@@ -35,12 +32,9 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
3532
}
3633

3734
function createMissingTableHead(sortableTable) {
38-
let createTableHead;
39-
if (testingTableSortJS === true) {
40-
createTableHead = domDocumentWindow.createElement("thead");
41-
} else {
42-
createTableHead = document.createElement("thead");
43-
}
35+
let createTableHead = !testingTableSortJS
36+
? document.createElement("thead")
37+
: domDocumentWindow.createElement("thead");
4438
createTableHead.appendChild(sortableTable.rows[0]);
4539
sortableTable.insertBefore(createTableHead, sortableTable.firstChild);
4640
}
@@ -49,8 +43,8 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
4943
if (sortableTable.getElementsByTagName("thead").length === 0) {
5044
createMissingTableHead(sortableTable);
5145
if (sortableTable.querySelectorAll("tbody").length > 1) {
52-
// Why index 1?; I don't remember
53-
return sortableTable.querySelectorAll("tbody")[1];
46+
// don't select empty tbody that the browser creates
47+
return sortableTable.querySelectorAll("tbody:not(:nth-child(2))");
5448
} else {
5549
return sortableTable.querySelectorAll("tbody");
5650
}
@@ -85,8 +79,8 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
8579
let foundMatch = false;
8680
for (let key of Object.keys(inferableClasses)) {
8781
let classRegexp = inferableClasses[key].regexp;
88-
if (tableColumn.innerText) {
89-
if (tableColumn.innerText.match(classRegexp) !== null) {
82+
if (tableColumn?.innerText !== undefined) {
83+
if (tableColumn.innerText.match(classRegexp)) {
9084
foundMatch = true;
9185
inferableClasses[key].count++;
9286
}
@@ -114,21 +108,21 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
114108
rows: [],
115109
headers: [],
116110
};
111+
for (let index of table.theads.keys()) {
112+
table.headers.push(table.theads.item(index).querySelectorAll("th"));
113+
}
117114
for (let index of table.bodies.keys()) {
118115
if (table.bodies.item(index) == null) {
119116
return;
120117
}
121-
table.headers.push(table.theads.item(index).querySelectorAll("th"));
122118
table.rows.push(table.bodies.item(index).querySelectorAll("tr"));
123119
}
124-
125120
table.hasClass = {
126121
noClassInfer: sortableTable.classList.contains("no-class-infer"),
127122
cellsSort: sortableTable.classList.contains("cells-sort"),
128123
tableArrows: sortableTable.classList.contains("table-arrows"),
129124
rememberSort: sortableTable.classList.contains("remember-sort"),
130125
};
131-
132126
for (
133127
let headerIndex = 0;
134128
headerIndex < table.theads.length;
@@ -244,19 +238,10 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
244238
const regexMinutesAndSeconds = /^(\d+h)?\s?(\d+m)?\s?(\d+s)?$/i;
245239
let columnOfTd = "";
246240
// TODO: github actions runtime didn't like textContent, tests didn't like innerText?
247-
if (testingTableSortJS) {
248-
columnOfTd = column.getColumn(
249-
tr,
250-
column.spanSum,
251-
column.span
252-
).textContent;
253-
} else {
254-
columnOfTd = column.getColumn(
255-
tr,
256-
column.spanSum,
257-
column.span
258-
).innerText;
259-
}
241+
columnOfTd = column.getColumn(tr, column.spanSum, column.span);
242+
columnOfTd = testingTableSortJS
243+
? columnOfTd.textContent
244+
: columnOfTd.innerText;
260245
let match = columnOfTd.match(regexMinutesAndSeconds);
261246
let [minutesInSeconds, hours, seconds] = [0, 0, 0];
262247
let timeinSeconds = columnOfTd;

browser-extensions/firefox/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifest_version": 2,
33
"author": "Lee Wannacott",
44
"name": "table-sort-js",
5-
"version": "1.17.0",
5+
"version": "1.17.1",
66
"description": "Makes tables sortable using table-sort-js: https://github.com/LeeWannacott/table-sort-js",
77
"icons": { "48": "icons/t.png" },
88
"browser_action": {
16 Bytes
Binary file not shown.

browser-extensions/firefox/table-sort.js

+18-33
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@ Instructions:
1717

1818
function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
1919
function getHTMLTables() {
20-
if (testingTableSortJS === true) {
21-
const getTagTable = domDocumentWindow.getElementsByTagName("table");
22-
return [getTagTable];
23-
} else {
24-
const getTagTable = document.getElementsByTagName("table");
25-
return [getTagTable];
26-
}
20+
const getTagTable = !testingTableSortJS
21+
? document.getElementsByTagName("table")
22+
: domDocumentWindow.getElementsByTagName("table");
23+
return [getTagTable];
2724
}
2825

2926
const [getTagTable] = getHTMLTables();
@@ -35,12 +32,9 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
3532
}
3633

3734
function createMissingTableHead(sortableTable) {
38-
let createTableHead;
39-
if (testingTableSortJS === true) {
40-
createTableHead = domDocumentWindow.createElement("thead");
41-
} else {
42-
createTableHead = document.createElement("thead");
43-
}
35+
let createTableHead = !testingTableSortJS
36+
? document.createElement("thead")
37+
: domDocumentWindow.createElement("thead");
4438
createTableHead.appendChild(sortableTable.rows[0]);
4539
sortableTable.insertBefore(createTableHead, sortableTable.firstChild);
4640
}
@@ -49,8 +43,8 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
4943
if (sortableTable.getElementsByTagName("thead").length === 0) {
5044
createMissingTableHead(sortableTable);
5145
if (sortableTable.querySelectorAll("tbody").length > 1) {
52-
// Why index 1?; I don't remember
53-
return sortableTable.querySelectorAll("tbody")[1];
46+
// don't select empty tbody that the browser creates
47+
return sortableTable.querySelectorAll("tbody:not(:nth-child(2))");
5448
} else {
5549
return sortableTable.querySelectorAll("tbody");
5650
}
@@ -85,8 +79,8 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
8579
let foundMatch = false;
8680
for (let key of Object.keys(inferableClasses)) {
8781
let classRegexp = inferableClasses[key].regexp;
88-
if (tableColumn.innerText) {
89-
if (tableColumn.innerText.match(classRegexp) !== null) {
82+
if (tableColumn?.innerText !== undefined) {
83+
if (tableColumn.innerText.match(classRegexp)) {
9084
foundMatch = true;
9185
inferableClasses[key].count++;
9286
}
@@ -114,21 +108,21 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
114108
rows: [],
115109
headers: [],
116110
};
111+
for (let index of table.theads.keys()) {
112+
table.headers.push(table.theads.item(index).querySelectorAll("th"));
113+
}
117114
for (let index of table.bodies.keys()) {
118115
if (table.bodies.item(index) == null) {
119116
return;
120117
}
121-
table.headers.push(table.theads.item(index).querySelectorAll("th"));
122118
table.rows.push(table.bodies.item(index).querySelectorAll("tr"));
123119
}
124-
125120
table.hasClass = {
126121
noClassInfer: sortableTable.classList.contains("no-class-infer"),
127122
cellsSort: sortableTable.classList.contains("cells-sort"),
128123
tableArrows: sortableTable.classList.contains("table-arrows"),
129124
rememberSort: sortableTable.classList.contains("remember-sort"),
130125
};
131-
132126
for (
133127
let headerIndex = 0;
134128
headerIndex < table.theads.length;
@@ -244,19 +238,10 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
244238
const regexMinutesAndSeconds = /^(\d+h)?\s?(\d+m)?\s?(\d+s)?$/i;
245239
let columnOfTd = "";
246240
// TODO: github actions runtime didn't like textContent, tests didn't like innerText?
247-
if (testingTableSortJS) {
248-
columnOfTd = column.getColumn(
249-
tr,
250-
column.spanSum,
251-
column.span
252-
).textContent;
253-
} else {
254-
columnOfTd = column.getColumn(
255-
tr,
256-
column.spanSum,
257-
column.span
258-
).innerText;
259-
}
241+
columnOfTd = column.getColumn(tr, column.spanSum, column.span);
242+
columnOfTd = testingTableSortJS
243+
? columnOfTd.textContent
244+
: columnOfTd.innerText;
260245
let match = columnOfTd.match(regexMinutesAndSeconds);
261246
let [minutesInSeconds, hours, seconds] = [0, 0, 0];
262247
let timeinSeconds = columnOfTd;

npm/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "table-sort-js",
3-
"version": "1.17.0",
3+
"version": "1.17.1",
44
"description": "A JavaScript client-side HTML table sorting library with no dependencies required.",
55
"license": "MIT",
66
"repository": "LeeWannacott/table-sort-js",

npm/table-sort.js

+18-33
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@ Instructions:
1717

1818
function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
1919
function getHTMLTables() {
20-
if (testingTableSortJS === true) {
21-
const getTagTable = domDocumentWindow.getElementsByTagName("table");
22-
return [getTagTable];
23-
} else {
24-
const getTagTable = document.getElementsByTagName("table");
25-
return [getTagTable];
26-
}
20+
const getTagTable = !testingTableSortJS
21+
? document.getElementsByTagName("table")
22+
: domDocumentWindow.getElementsByTagName("table");
23+
return [getTagTable];
2724
}
2825

2926
const [getTagTable] = getHTMLTables();
@@ -35,12 +32,9 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
3532
}
3633

3734
function createMissingTableHead(sortableTable) {
38-
let createTableHead;
39-
if (testingTableSortJS === true) {
40-
createTableHead = domDocumentWindow.createElement("thead");
41-
} else {
42-
createTableHead = document.createElement("thead");
43-
}
35+
let createTableHead = !testingTableSortJS
36+
? document.createElement("thead")
37+
: domDocumentWindow.createElement("thead");
4438
createTableHead.appendChild(sortableTable.rows[0]);
4539
sortableTable.insertBefore(createTableHead, sortableTable.firstChild);
4640
}
@@ -49,8 +43,8 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
4943
if (sortableTable.getElementsByTagName("thead").length === 0) {
5044
createMissingTableHead(sortableTable);
5145
if (sortableTable.querySelectorAll("tbody").length > 1) {
52-
// Why index 1?; I don't remember
53-
return sortableTable.querySelectorAll("tbody")[1];
46+
// don't select empty tbody that the browser creates
47+
return sortableTable.querySelectorAll("tbody:not(:nth-child(2))");
5448
} else {
5549
return sortableTable.querySelectorAll("tbody");
5650
}
@@ -85,8 +79,8 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
8579
let foundMatch = false;
8680
for (let key of Object.keys(inferableClasses)) {
8781
let classRegexp = inferableClasses[key].regexp;
88-
if (tableColumn.innerText) {
89-
if (tableColumn.innerText.match(classRegexp) !== null) {
82+
if (tableColumn?.innerText !== undefined) {
83+
if (tableColumn.innerText.match(classRegexp)) {
9084
foundMatch = true;
9185
inferableClasses[key].count++;
9286
}
@@ -114,21 +108,21 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
114108
rows: [],
115109
headers: [],
116110
};
111+
for (let index of table.theads.keys()) {
112+
table.headers.push(table.theads.item(index).querySelectorAll("th"));
113+
}
117114
for (let index of table.bodies.keys()) {
118115
if (table.bodies.item(index) == null) {
119116
return;
120117
}
121-
table.headers.push(table.theads.item(index).querySelectorAll("th"));
122118
table.rows.push(table.bodies.item(index).querySelectorAll("tr"));
123119
}
124-
125120
table.hasClass = {
126121
noClassInfer: sortableTable.classList.contains("no-class-infer"),
127122
cellsSort: sortableTable.classList.contains("cells-sort"),
128123
tableArrows: sortableTable.classList.contains("table-arrows"),
129124
rememberSort: sortableTable.classList.contains("remember-sort"),
130125
};
131-
132126
for (
133127
let headerIndex = 0;
134128
headerIndex < table.theads.length;
@@ -244,19 +238,10 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
244238
const regexMinutesAndSeconds = /^(\d+h)?\s?(\d+m)?\s?(\d+s)?$/i;
245239
let columnOfTd = "";
246240
// TODO: github actions runtime didn't like textContent, tests didn't like innerText?
247-
if (testingTableSortJS) {
248-
columnOfTd = column.getColumn(
249-
tr,
250-
column.spanSum,
251-
column.span
252-
).textContent;
253-
} else {
254-
columnOfTd = column.getColumn(
255-
tr,
256-
column.spanSum,
257-
column.span
258-
).innerText;
259-
}
241+
columnOfTd = column.getColumn(tr, column.spanSum, column.span);
242+
columnOfTd = testingTableSortJS
243+
? columnOfTd.textContent
244+
: columnOfTd.innerText;
260245
let match = columnOfTd.match(regexMinutesAndSeconds);
261246
let [minutesInSeconds, hours, seconds] = [0, 0, 0];
262247
let timeinSeconds = columnOfTd;

0 commit comments

Comments
 (0)