tidy-table 4.0.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,107 @@
1
+ /**
2
+ * tidy-table
3
+ * Create a HTML table that can be sorted, selected and
4
+ * post-processed using a simple callback.
5
+ *
6
+ * Copyright 2012-2023, Marc S. Brooks (https://mbrooks.info)
7
+ * Licensed under the MIT license:
8
+ * http://www.opensource.org/licenses/mit-license.php
9
+ */
10
+ .tidy-table table {
11
+ background-color: #fff;
12
+ border-collapse: collapse;
13
+ border: 1px solid #ccc;
14
+ cursor: pointer;
15
+ white-space: nowrap;
16
+ }
17
+ .tidy-table table thead input[type=checkbox], .tidy-table table tbody input[type=checkbox] {
18
+ display: block;
19
+ margin: 0px auto;
20
+ }
21
+ .tidy-table table thead td, .tidy-table table thead th, .tidy-table table tbody td, .tidy-table table tbody th {
22
+ padding: 6px 20px;
23
+ }
24
+ .tidy-table table thead td:nth-child(1), .tidy-table table thead th:nth-child(1), .tidy-table table tbody td:nth-child(1), .tidy-table table tbody th:nth-child(1) {
25
+ width: 10px;
26
+ }
27
+ .tidy-table table thead {
28
+ border: none;
29
+ }
30
+ .tidy-table table thead th {
31
+ background-color: #ddd;
32
+ }
33
+ .tidy-table table thead th.arrow-down {
34
+ background: #eee url("../images/arrow-down.svg") no-repeat right center;
35
+ }
36
+ .tidy-table table thead th.arrow-up {
37
+ background: #eee url("../images/arrow-up.svg") no-repeat right center;
38
+ }
39
+ .tidy-table table tbody tr.check-on {
40
+ background-color: #f5f5f5;
41
+ }
42
+ .tidy-table table tbody tr.check-off {
43
+ background-color: #fff;
44
+ }
45
+ .tidy-table table tbody tr td {
46
+ border-right: 1px solid #eee;
47
+ border-top: 1px solid #ccc;
48
+ padding: 7px 20px;
49
+ }
50
+ .tidy-table table tbody tr td .label {
51
+ display: none;
52
+ }
53
+ .tidy-table table tbody tr td:nth-child(1) {
54
+ border-right: 1px solid #eee;
55
+ }
56
+ .tidy-table table tbody tr td:nth-last-child(1) {
57
+ border-right: none;
58
+ }
59
+ @media only screen and (min-device-width: 0px) and (max-device-width: 800px) {
60
+ .tidy-table.responsive {
61
+ margin: 0px !important;
62
+ overflow: auto;
63
+ width: auto !important;
64
+ }
65
+ .tidy-table.responsive table {
66
+ border: 0px;
67
+ border-top: 1px solid #ddd;
68
+ width: 100%;
69
+ }
70
+ .tidy-table.responsive table thead td, .tidy-table.responsive table thead th, .tidy-table.responsive table tbody td, .tidy-table.responsive table tbody th {
71
+ border: 0px;
72
+ box-sizing: border-box;
73
+ clear: both;
74
+ float: left;
75
+ padding-left: 10px;
76
+ }
77
+ .tidy-table.responsive table thead td:first-child, .tidy-table.responsive table thead th:first-child, .tidy-table.responsive table tbody td:first-child, .tidy-table.responsive table tbody th:first-child {
78
+ background-color: transparent;
79
+ padding: 10px;
80
+ position: absolute;
81
+ right: 0px;
82
+ top: 2px;
83
+ width: auto;
84
+ }
85
+ .tidy-table.responsive table thead th {
86
+ text-align: left;
87
+ width: 100%;
88
+ }
89
+ .tidy-table.responsive table thead th:first-child {
90
+ top: -40px;
91
+ }
92
+ .tidy-table.responsive table tbody tr {
93
+ border-bottom: 1px solid #ccc;
94
+ position: relative;
95
+ }
96
+ .tidy-table.responsive table tbody tr:last-child {
97
+ border: none;
98
+ }
99
+ .tidy-table.responsive table tbody td {
100
+ background-color: transparent;
101
+ }
102
+ .tidy-table.responsive table tbody td:first-child {
103
+ border: none;
104
+ }
105
+ }
106
+
107
+ /*# sourceMappingURL=tidy-table.css.map */
@@ -0,0 +1 @@
1
+ {"version":3,"sourceRoot":"","sources":["../src/tidy-table.scss"],"names":[],"mappings":"AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWE;EACE;EACA;EACA;EACA;EACA;;AAGE;EACE;EACA;;AAGF;EACE;;AAEA;EACE;;AAKN;EACE;;AAEA;EACE;;AAEA;EACE;;AAGF;EACE;;AAOF;EACE;;AAGF;EACE;;AAGF;EACE;EACA;EACA;;AAEA;EACE;;AAGF;EACE;;AAGF;EACE;;AAOV;EACE;IACE;IACA;IACA;;EAEA;IACE;IACA;IACA;;EAGE;IACE;IACA;IACA;IACA;IACA;;EAEA;IACE;IACA;IACA;IACA;IACA;IACA;;EAMJ;IACE;IACA;;EAEA;IACE;;EAMJ;IACE;IACA;;EAEA;IACE;;EAIJ;IACE;;EAEA;IACE","file":"tidy-table.css"}
@@ -0,0 +1,358 @@
1
+ /**
2
+ * tidy-table
3
+ * Create a HTML table that can be sorted, selected and
4
+ * post-processed using a simple callback.
5
+ *
6
+ * Copyright 2012-2023, Marc S. Brooks (https://mbrooks.info)
7
+ * Licensed under the MIT license:
8
+ * http://www.opensource.org/licenses/mit-license.php
9
+ */
10
+
11
+ 'use strict';
12
+
13
+ /**
14
+ * @param {Element} container
15
+ * Containing HTML element.
16
+ *
17
+ * @param {Object} settings
18
+ * Table settings.
19
+ *
20
+ * @param {Object} options
21
+ * Configuration overrides (optional).
22
+ */
23
+ function TidyTable(container, settings, options) {
24
+ if (options === void 0) {
25
+ options = {};
26
+ }
27
+ var self = this;
28
+ var defaults = {
29
+ enableCheckbox: false,
30
+ enableMenu: false,
31
+ reverseSortDir: false,
32
+ responsive: false
33
+ };
34
+ (function () {
35
+ self.options = Object.assign(defaults, options);
36
+ var columnTitles = settings.columnTitles,
37
+ columnValues = settings.columnValues;
38
+ if (columnTitles.length && columnValues.length) {
39
+ renderTable();
40
+ } else {
41
+ throw new Error('Failed to initialize (missing settings)');
42
+ }
43
+ })();
44
+
45
+ /**
46
+ * Render a new table instance.
47
+ */
48
+ function renderTable() {
49
+ var _settings$postProcess;
50
+ var table = createTableElm();
51
+
52
+ // Post-process table results HTML object.
53
+ if (typeof ((_settings$postProcess = settings.postProcess) == null ? void 0 : _settings$postProcess.table) === 'function') {
54
+ settings.postProcess.table(table);
55
+ }
56
+
57
+ // Replace the element, if already exists.
58
+ var block = container.querySelector('.tidy-table table');
59
+ if (block) {
60
+ block.parentNode.replaceChild(table, block);
61
+ } else {
62
+ // Generate select menu elements.
63
+ if (self.options.enableMenu) {
64
+ container.appendChild(createMenuElm('options'));
65
+ }
66
+ container.classList.add('tidy-table');
67
+ container.appendChild(table);
68
+ }
69
+
70
+ // Enable/disable responsive layout support.
71
+ if (defaults.responsive) {
72
+ container.classList.add('responsive');
73
+ }
74
+ }
75
+
76
+ /**
77
+ * Create table elements.
78
+ *
79
+ * @return {Element}
80
+ */
81
+ function createTableElm() {
82
+ var table = document.createElement('table');
83
+ table.appendChild(createTableHeaderElm());
84
+ table.appendChild(createTableBodyElm());
85
+
86
+ // Append check boxes to beginning each row.
87
+ if (self.options.enableCheckbox) {
88
+ var rows = table.querySelectorAll('tr');
89
+ for (var i = 0; i < rows.length; i++) {
90
+ var input = createCheckboxElm();
91
+ var col = void 0;
92
+
93
+ // First row is always the header.
94
+ if (i === 0) {
95
+ col = document.createElement('th');
96
+
97
+ // Attach event to check all boxes.
98
+ input.addEventListener('click', function () {
99
+ toggleSelRows(rows);
100
+ });
101
+ } else {
102
+ col = document.createElement('td');
103
+
104
+ // Attach events to each checkbox.
105
+ input.addEventListener('click', function (index) {
106
+ toggleSelRows(rows, index);
107
+ }.bind(null, i), false);
108
+ }
109
+ col.appendChild(input);
110
+
111
+ // Insert before first cell.
112
+ rows[i].insertBefore(col, rows[i].firstChild);
113
+ }
114
+ }
115
+ return table;
116
+ }
117
+
118
+ /**
119
+ * Create table body elements.
120
+ *
121
+ * @return {Element}
122
+ */
123
+ function createTableBodyElm() {
124
+ var tbody = document.createElement('tbody');
125
+ var vals = settings.columnValues;
126
+ for (var i = 0; i < vals.length; i++) {
127
+ var row = document.createElement('tr');
128
+ for (var j = 0; j < vals[i].length; j++) {
129
+ var _settings$postProcess2;
130
+ var val = vals[i][j];
131
+ var col = document.createElement('td');
132
+ col.appendChild(document.createTextNode(val));
133
+ col.setAttribute('title', val);
134
+ row.appendChild(col);
135
+
136
+ // Post-process table column HTML object.
137
+ if (typeof ((_settings$postProcess2 = settings.postProcess) == null ? void 0 : _settings$postProcess2.column) === 'function') {
138
+ settings.postProcess.column(col);
139
+ }
140
+ }
141
+ tbody.appendChild(row);
142
+ }
143
+ return tbody;
144
+ }
145
+
146
+ /**
147
+ * Create table header elements.
148
+ *
149
+ * @return {Element}
150
+ */
151
+ function createTableHeaderElm() {
152
+ var thead = document.createElement('thead');
153
+ var row = document.createElement('tr');
154
+ var titles = settings.columnTitles;
155
+ var sortOrder = self.sortOrder;
156
+ var _loop = function _loop(i) {
157
+ var title = titles[i];
158
+ var col = document.createElement('th');
159
+ col.appendChild(document.createTextNode(title));
160
+ col.setAttribute('title', title);
161
+ row.appendChild(col);
162
+ if (self.selected === i) {
163
+ var className;
164
+
165
+ // Determine column result order.
166
+ if (!self.options.reverseSortDir) {
167
+ if (sortOrder === 'asc' || !sortOrder) {
168
+ className = 'arrow-up';
169
+ sortOrder = 'desc';
170
+ } else {
171
+ className = 'arrow-up';
172
+ sortOrder = 'asc';
173
+ }
174
+ } else {
175
+ if (sortOrder === 'desc' || !sortOrder) {
176
+ className = 'arrow-down';
177
+ sortOrder = 'asc';
178
+ } else {
179
+ className = 'arrow-up';
180
+ sortOrder = 'desc';
181
+ }
182
+ }
183
+
184
+ // Highlight selected column.
185
+ col.classList.add(className);
186
+ }
187
+
188
+ // Attach column sorting events.
189
+ col.addEventListener('click', function (index) {
190
+ self.sortOrder = self.selected === i ? sortOrder : 'asc';
191
+ sortByColumn(index, sortOrder);
192
+ self.selected = index;
193
+ renderTable();
194
+ }.bind(null, i), false);
195
+ };
196
+ for (var i = 0; i < titles.length; i++) {
197
+ _loop(i);
198
+ }
199
+ thead.appendChild(row);
200
+ return thead;
201
+ }
202
+
203
+ /**
204
+ * Create checkbox element.
205
+ *
206
+ * @returns {Element}
207
+ */
208
+ function createCheckboxElm() {
209
+ var input = document.createElement('input');
210
+ input.setAttribute('type', 'checkbox');
211
+ return input;
212
+ }
213
+
214
+ /**
215
+ * Create select menu element.
216
+ *
217
+ * @returns {Element}
218
+ */
219
+ function createMenuElm(name) {
220
+ var _settings$postProcess3;
221
+ // Create reusable elements.
222
+ var select = document.createElement('select');
223
+ select.classList.add(name);
224
+
225
+ // Listen for select menu events.
226
+ select.addEventListener('change', function () {
227
+ // Execute callback.
228
+ var callback = settings.menuOptions[this.value][1].callback;
229
+ if (typeof callback === 'function') {
230
+ callback(getCheckedAsObj());
231
+ }
232
+ this.value = 0;
233
+ });
234
+
235
+ // .. Options
236
+ for (var i = 0; i < settings.menuOptions.length; i++) {
237
+ var option = document.createElement('option');
238
+ option.text = settings.menuOptions[i][0];
239
+ option.value = i;
240
+ select.appendChild(option);
241
+ }
242
+
243
+ // Post-process select menu HTML object.
244
+ if (typeof ((_settings$postProcess3 = settings.postProcess) == null ? void 0 : _settings$postProcess3.menu) === 'function') {
245
+ settings.postProcess.menu(select);
246
+ }
247
+ return select;
248
+ }
249
+
250
+ /**
251
+ * Return selected row values as array of objects.
252
+ *
253
+ * @returns {Array<Object>}
254
+ */
255
+ function getCheckedAsObj() {
256
+ var rows = container.querySelectorAll('tbody > tr');
257
+ var objs = [];
258
+ for (var i = 0; i < rows.length; i++) {
259
+ var cols = rows[i].childNodes;
260
+
261
+ // If the row checkbox is selected.
262
+ if (cols[0].firstChild.checked) {
263
+ var row = [];
264
+
265
+ // Simulate an associative array.
266
+ for (var j = 1; j < cols.length; j++) {
267
+ row[j - 1] = cols[j].textContent;
268
+ }
269
+ objs.push(row);
270
+ }
271
+ }
272
+ return objs;
273
+ }
274
+
275
+ /**
276
+ * Select/Deselect (input checkbox and row highlight).
277
+ */
278
+ function toggleSelRows(rows, num) {
279
+ var checked;
280
+ for (var i = 0; i < rows.length; i++) {
281
+ var row = rows[i];
282
+ var input = row.querySelector('input[type=checkbox]');
283
+
284
+ // Update all rows.
285
+ if (!num) {
286
+ if (i === 0) {
287
+ checked = input.checked;
288
+ continue;
289
+ }
290
+ if (checked) {
291
+ row.classList.replace('check-off', 'check-on') || row.classList.add('check-on');
292
+ input.checked = true;
293
+ } else {
294
+ row.classList.replace('check-on', 'check-off');
295
+ input.checked = false;
296
+ }
297
+ }
298
+
299
+ // Update selected row.
300
+ else {
301
+ if (i === 0) {
302
+ continue;
303
+ }
304
+ if (input.checked === true) {
305
+ row.classList.replace('check-off', 'check-on') || row.classList.add('check-on');
306
+ input.checked = true;
307
+ } else {
308
+ row.classList.replace('check-on', 'check-off');
309
+ input.checked = false;
310
+ }
311
+ }
312
+ }
313
+ }
314
+
315
+ /**
316
+ * Display results ordered by selected column.
317
+ */
318
+ function sortByColumn(num, order) {
319
+ var sortByPattern = settings.sortByPattern;
320
+ if (typeof sortByPattern !== 'function') {
321
+ sortByPattern = function sortByPattern(val) {
322
+ return val == null ? void 0 : val.replace(/\$|%|#/g, '');
323
+ };
324
+ }
325
+ var reverse = order === 'desc' ? -1 : 1;
326
+
327
+ // Sort object by array index.
328
+ settings.columnValues.sort(function (a, b) {
329
+ var str1 = sortByPattern(a[num]);
330
+ var str2 = sortByPattern(b[num]);
331
+ if (isNaN(str1)) {
332
+ return [reverse * cmpAny(str1, str2)] > [reverse * cmpAny(str2, str1)] ? -1 : 1;
333
+ }
334
+ return [reverse * cmpInt(str1, str2)];
335
+ });
336
+ }
337
+
338
+ /**
339
+ * Generic string comparison functions.
340
+ */
341
+ function cmpAny(a, b) {
342
+ return a > b ? 1 : a < b ? -1 : 0;
343
+ }
344
+ function cmpInt(a, b) {
345
+ return b - a;
346
+ }
347
+ }
348
+
349
+ /**
350
+ * Set global/exportable instance, where supported.
351
+ */
352
+ window.tidyTable = function (container, settings, options) {
353
+ return new TidyTable(container, settings, options);
354
+ };
355
+ if (typeof module !== 'undefined' && module.exports) {
356
+ module.exports = TidyTable;
357
+ }
358
+ //# sourceMappingURL=tidy-table.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tidy-table.js","names":["TidyTable","container","settings","options","self","defaults","enableCheckbox","enableMenu","reverseSortDir","responsive","Object","assign","columnTitles","columnValues","length","renderTable","Error","_settings$postProcess","table","createTableElm","postProcess","block","querySelector","parentNode","replaceChild","appendChild","createMenuElm","classList","add","document","createElement","createTableHeaderElm","createTableBodyElm","rows","querySelectorAll","i","input","createCheckboxElm","col","addEventListener","toggleSelRows","index","bind","insertBefore","firstChild","tbody","vals","row","j","_settings$postProcess2","val","createTextNode","setAttribute","column","thead","titles","sortOrder","_loop","title","selected","className","sortByColumn","name","_settings$postProcess3","select","callback","menuOptions","value","getCheckedAsObj","option","text","menu","objs","cols","childNodes","checked","textContent","push","num","replace","order","sortByPattern","reverse","sort","a","b","str1","str2","isNaN","cmpAny","cmpInt","window","tidyTable","module","exports"],"sources":["../src/tidy-table.js"],"sourcesContent":["/**\n * tidy-table\n * Create a HTML table that can be sorted, selected and\n * post-processed using a simple callback.\n *\n * Copyright 2012-2023, Marc S. Brooks (https://mbrooks.info)\n * Licensed under the MIT license:\n * http://www.opensource.org/licenses/mit-license.php\n */\n\n'use strict';\n\n/**\n * @param {Element} container\n * Containing HTML element.\n *\n * @param {Object} settings\n * Table settings.\n *\n * @param {Object} options\n * Configuration overrides (optional).\n */\nfunction TidyTable(container, settings, options = {}) {\n const self = this;\n\n const defaults = {\n enableCheckbox: false,\n enableMenu: false,\n reverseSortDir: false,\n responsive: false\n };\n\n (function() {\n self.options = Object.assign(defaults, options);\n\n const {columnTitles, columnValues} = settings;\n\n if (columnTitles.length && columnValues.length) {\n renderTable();\n } else {\n throw new Error('Failed to initialize (missing settings)');\n }\n })();\n\n /**\n * Render a new table instance.\n */\n function renderTable() {\n const table = createTableElm();\n\n // Post-process table results HTML object.\n if (typeof settings.postProcess?.table === 'function') {\n settings.postProcess.table(table);\n }\n\n // Replace the element, if already exists.\n const block = container.querySelector('.tidy-table table');\n\n if (block) {\n block.parentNode.replaceChild(table, block);\n } else {\n\n // Generate select menu elements.\n if (self.options.enableMenu) {\n container.appendChild(createMenuElm('options'));\n }\n\n container.classList.add('tidy-table');\n container.appendChild(table);\n }\n\n // Enable/disable responsive layout support.\n if (defaults.responsive) {\n container.classList.add('responsive');\n }\n }\n\n /**\n * Create table elements.\n *\n * @return {Element}\n */\n function createTableElm() {\n const table = document.createElement('table');\n table.appendChild(createTableHeaderElm());\n table.appendChild(createTableBodyElm());\n\n // Append check boxes to beginning each row.\n if (self.options.enableCheckbox) {\n const rows = table.querySelectorAll('tr');\n\n for (let i = 0; i < rows.length; i++) {\n const input = createCheckboxElm();\n\n let col;\n\n // First row is always the header.\n if (i === 0) {\n col = document.createElement('th');\n\n // Attach event to check all boxes.\n input.addEventListener('click', function() {\n toggleSelRows(rows);\n });\n }\n else {\n col = document.createElement('td');\n\n // Attach events to each checkbox.\n input.addEventListener('click', function(index) {\n toggleSelRows(rows, index);\n }.bind(null, i), false);\n }\n\n col.appendChild(input);\n\n // Insert before first cell.\n rows[i].insertBefore(col, rows[i].firstChild);\n }\n }\n\n return table;\n }\n\n /**\n * Create table body elements.\n *\n * @return {Element}\n */\n function createTableBodyElm() {\n const tbody = document.createElement('tbody');\n\n const vals = settings.columnValues;\n\n for (let i = 0; i < vals.length; i++) {\n const row = document.createElement('tr');\n\n for (let j = 0; j < vals[i].length; j++) {\n const val = vals[i][j];\n\n const col = document.createElement('td');\n col.appendChild(document.createTextNode(val));\n col.setAttribute('title', val);\n row.appendChild(col);\n\n // Post-process table column HTML object.\n if (typeof settings.postProcess?.column === 'function') {\n settings.postProcess.column(col);\n }\n }\n\n tbody.appendChild(row);\n }\n\n return tbody;\n }\n\n /**\n * Create table header elements.\n *\n * @return {Element}\n */\n function createTableHeaderElm() {\n const thead = document.createElement('thead');\n const row = document.createElement('tr');\n\n const titles = settings.columnTitles;\n\n let sortOrder = self.sortOrder;\n\n for (let i = 0; i < titles.length; i++) {\n const title = titles[i];\n\n const col = document.createElement('th');\n col.appendChild(document.createTextNode(title));\n col.setAttribute('title', title);\n\n row.appendChild(col);\n\n if (self.selected === i) {\n let className;\n\n // Determine column result order.\n if (!self.options.reverseSortDir) {\n if (sortOrder === 'asc' || !sortOrder) {\n className = 'arrow-up';\n sortOrder = 'desc';\n }\n else {\n className = 'arrow-up';\n sortOrder = 'asc';\n }\n }\n else {\n if (sortOrder === 'desc' || !sortOrder) {\n className = 'arrow-down';\n sortOrder = 'asc';\n }\n else {\n className = 'arrow-up';\n sortOrder = 'desc';\n }\n }\n\n // Highlight selected column.\n col.classList.add(className);\n }\n\n // Attach column sorting events.\n col.addEventListener('click', function(index) {\n self.sortOrder = (self.selected === i) ? sortOrder : 'asc';\n\n sortByColumn(index, sortOrder);\n\n self.selected = index;\n\n renderTable();\n }.bind(null, i), false);\n }\n\n thead.appendChild(row);\n\n return thead;\n }\n\n /**\n * Create checkbox element.\n *\n * @returns {Element}\n */\n function createCheckboxElm() {\n const input = document.createElement('input');\n input.setAttribute('type', 'checkbox');\n\n return input;\n }\n\n /**\n * Create select menu element.\n *\n * @returns {Element}\n */\n function createMenuElm(name) {\n\n // Create reusable elements.\n const select = document.createElement('select');\n select.classList.add(name);\n\n // Listen for select menu events.\n select.addEventListener('change', function() {\n\n // Execute callback.\n const callback = settings.menuOptions[this.value][1].callback;\n\n if (typeof callback === 'function') {\n callback(getCheckedAsObj());\n }\n\n this.value = 0;\n });\n\n // .. Options\n for (let i = 0; i < settings.menuOptions.length; i++) {\n const option = document.createElement('option');\n option.text = settings.menuOptions[i][0];\n option.value = i;\n\n select.appendChild(option);\n }\n\n // Post-process select menu HTML object.\n if (typeof settings.postProcess?.menu === 'function') {\n settings.postProcess.menu(select);\n }\n\n return select;\n }\n\n /**\n * Return selected row values as array of objects.\n *\n * @returns {Array<Object>}\n */\n function getCheckedAsObj() {\n const rows = container.querySelectorAll('tbody > tr');\n const objs = [];\n\n for (let i = 0; i < rows.length; i++) {\n const cols = rows[i].childNodes;\n\n // If the row checkbox is selected.\n if (cols[0].firstChild.checked) {\n const row = [];\n\n // Simulate an associative array.\n for (let j = 1; j < cols.length; j++) {\n row[j - 1] = cols[j].textContent;\n }\n\n objs.push(row);\n }\n }\n\n return objs;\n }\n\n /**\n * Select/Deselect (input checkbox and row highlight).\n */\n function toggleSelRows(rows, num) {\n let checked;\n\n for (let i = 0; i < rows.length; i++) {\n const row = rows[i];\n\n const input = row.querySelector('input[type=checkbox]');\n\n // Update all rows.\n if (!num) {\n if (i === 0) {\n checked = input.checked;\n continue;\n }\n\n if (checked) {\n row.classList.replace('check-off', 'check-on') || row.classList.add('check-on');\n input.checked = true;\n }\n else {\n row.classList.replace('check-on', 'check-off');\n input.checked = false;\n }\n }\n\n // Update selected row.\n else {\n if (i === 0) {\n continue;\n }\n\n if (input.checked === true) {\n row.classList.replace('check-off', 'check-on') || row.classList.add('check-on');\n input.checked = true;\n }\n else {\n row.classList.replace('check-on', 'check-off');\n input.checked = false;\n }\n }\n }\n }\n\n /**\n * Display results ordered by selected column.\n */\n function sortByColumn(num, order) {\n let sortByPattern = settings.sortByPattern;\n\n if (typeof sortByPattern !== 'function') {\n sortByPattern = function(val) {\n return val?.replace(/\\$|%|#/g, '');\n };\n }\n\n const reverse = (order === 'desc') ? -1 : 1;\n\n // Sort object by array index.\n settings.columnValues.sort(function(a, b) {\n const str1 = sortByPattern(a[num]);\n const str2 = sortByPattern(b[num]);\n\n if (isNaN(str1)) {\n return [reverse * cmpAny(str1, str2)] >\n [reverse * cmpAny(str2, str1)] ? -1 : 1;\n }\n\n return [reverse * cmpInt(str1, str2)];\n });\n }\n\n /**\n * Generic string comparison functions.\n */\n function cmpAny(a, b) {\n return (a > b) ? 1 : (a < b) ? -1 : 0;\n }\n\n function cmpInt(a, b) {\n return b - a;\n }\n}\n\n/**\n * Set global/exportable instance, where supported.\n */\nwindow.tidyTable = function(container, settings, options) {\n return new TidyTable(container, settings, options);\n};\n\nif (typeof module !== 'undefined' && module.exports) {\n module.exports = TidyTable;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,YAAY;;AAEZ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,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C,CAAC,GAAG,CAAC;EACvC;EAEA,SAASK,MAAMA,CAACN,CAAC,EAAEC,CAAC,EAAE;IACpB,OAAOA,CAAC,GAAGD,CAAC;EACd;AACF;;AAEA;AACA;AACA;AACAO,MAAM,CAACC,SAAS,GAAG,UAAS3F,SAAS,EAAEC,QAAQ,EAAEC,OAAO,EAAE;EACxD,OAAO,IAAIH,SAAS,CAACC,SAAS,EAAEC,QAAQ,EAAEC,OAAO,CAAC;AACpD,CAAC;AAED,IAAI,OAAO0F,MAAM,KAAK,WAAW,IAAIA,MAAM,CAACC,OAAO,EAAE;EACnDD,MAAM,CAACC,OAAO,GAAG9F,SAAS;AAC5B"}
@@ -0,0 +1 @@
1
+ .tidy-table table{background-color:#fff;border-collapse:collapse;border:1px solid #ccc;cursor:pointer;white-space:nowrap}.tidy-table table tbody input[type=checkbox],.tidy-table table thead input[type=checkbox]{display:block;margin:0 auto}.tidy-table table tbody td,.tidy-table table tbody th,.tidy-table table thead td,.tidy-table table thead th{padding:6px 20px}.tidy-table table tbody td:nth-child(1),.tidy-table table tbody th:nth-child(1),.tidy-table table thead td:nth-child(1),.tidy-table table thead th:nth-child(1){width:10px}.tidy-table table thead{border:none}.tidy-table table thead th{background-color:#ddd}.tidy-table table thead th.arrow-down{background:#eee url(../images/arrow-down.svg) no-repeat right center}.tidy-table table thead th.arrow-up{background:#eee url(../images/arrow-up.svg) no-repeat right center}.tidy-table table tbody tr.check-on{background-color:#f5f5f5}.tidy-table table tbody tr.check-off{background-color:#fff}.tidy-table table tbody tr td{border-right:1px solid #eee;border-top:1px solid #ccc;padding:7px 20px}.tidy-table table tbody tr td .label{display:none}.tidy-table table tbody tr td:nth-child(1){border-right:1px solid #eee}.tidy-table table tbody tr td:nth-last-child(1){border-right:none}@media only screen and (min-device-width:0px) and (max-device-width:800px){.tidy-table.responsive{margin:0!important;overflow:auto;width:auto!important}.tidy-table.responsive table{border:0;border-top:1px solid #ddd;width:100%}.tidy-table.responsive table tbody td,.tidy-table.responsive table tbody th,.tidy-table.responsive table thead td,.tidy-table.responsive table thead th{border:0;box-sizing:border-box;clear:both;float:left;padding-left:10px}.tidy-table.responsive table tbody td:first-child,.tidy-table.responsive table tbody th:first-child,.tidy-table.responsive table thead td:first-child,.tidy-table.responsive table thead th:first-child{background-color:transparent;padding:10px;position:absolute;right:0;top:2px;width:auto}.tidy-table.responsive table thead th{text-align:left;width:100%}.tidy-table.responsive table thead th:first-child{top:-40px}.tidy-table.responsive table tbody tr{border-bottom:1px solid #ccc;position:relative}.tidy-table.responsive table tbody tr:last-child{border:none}.tidy-table.responsive table tbody td{background-color:transparent}.tidy-table.responsive table tbody td:first-child{border:none}}
@@ -0,0 +1 @@
1
+ "use strict";function TidyTable(i,a,n){void 0===n&&(n={});var l=this,c={enableCheckbox:!1,enableMenu:!1,reverseSortDir:!1,responsive:!1};function s(){var e,t=function(){var e=document.createElement("table");if(e.appendChild(function(){for(var e=document.createElement("thead"),o=document.createElement("tr"),r=a.columnTitles,i=l.sortOrder,t=function(t){var e,n=r[t],c=document.createElement("th");c.appendChild(document.createTextNode(n)),c.setAttribute("title",n),o.appendChild(c),l.selected===t&&(i=l.options.reverseSortDir?"desc"!==i&&i?(e="arrow-up","desc"):(e="arrow-down","asc"):"asc"!==i&&i?(e="arrow-up","asc"):(e="arrow-up","desc"),c.classList.add(e));c.addEventListener("click",function(e){l.sortOrder=l.selected===t?i:"asc",function(o,e){var r=a.sortByPattern;"function"!=typeof r&&(r=function(e){return null==e?void 0:e.replace(/\$|%|#/g,"")});var i="desc"===e?-1:1;a.columnValues.sort(function(e,t){var n=r(e[o]),c=r(t[o]);return isNaN(n)?[i*u(n,c)]>[i*u(c,n)]?-1:1:[i*function(e,t){return t-e}(n,c)]})}(e,i),l.selected=e,s()}.bind(null,t),!1)},n=0;n<r.length;n++)t(n);return e.appendChild(o),e}()),e.appendChild(function(){for(var e=document.createElement("tbody"),t=a.columnValues,n=0;n<t.length;n++){for(var c=document.createElement("tr"),o=0;o<t[n].length;o++){var r,i=t[n][o],l=document.createElement("td");l.appendChild(document.createTextNode(i)),l.setAttribute("title",i),c.appendChild(l),"function"==typeof(null==(r=a.postProcess)?void 0:r.column)&&a.postProcess.column(l)}e.appendChild(c)}return e}()),l.options.enableCheckbox)for(var t=e.querySelectorAll("tr"),n=0;n<t.length;n++){var c=r(),o=void 0;0===n?(o=document.createElement("th"),c.addEventListener("click",function(){d(t)})):(o=document.createElement("td"),c.addEventListener("click",function(e){d(t,e)}.bind(null,n),!1)),o.appendChild(c),t[n].insertBefore(o,t[n].firstChild)}return e}();"function"==typeof(null==(e=a.postProcess)?void 0:e.table)&&a.postProcess.table(t);var n=i.querySelector(".tidy-table table");n?n.parentNode.replaceChild(t,n):(l.options.enableMenu&&i.appendChild(function(e){var t,n=document.createElement("select");n.classList.add(e),n.addEventListener("change",function(){var e=a.menuOptions[this.value][1].callback;"function"==typeof e&&e(function(){for(var e=i.querySelectorAll("tbody > tr"),t=[],n=0;n<e.length;n++){var c=e[n].childNodes;if(c[0].firstChild.checked){for(var o=[],r=1;r<c.length;r++)o[r-1]=c[r].textContent;t.push(o)}}return t}()),this.value=0});for(var c=0;c<a.menuOptions.length;c++){var o=document.createElement("option");o.text=a.menuOptions[c][0],o.value=c,n.appendChild(o)}"function"==typeof(null==(t=a.postProcess)?void 0:t.menu)&&a.postProcess.menu(n);return n}("options")),i.classList.add("tidy-table"),i.appendChild(t)),c.responsive&&i.classList.add("responsive")}function r(){var e=document.createElement("input");return e.setAttribute("type","checkbox"),e}function d(e,t){for(var n,c=0;c<e.length;c++){var o=e[c],r=o.querySelector("input[type=checkbox]");if(t){if(0===c)continue;!0===r.checked?(o.classList.replace("check-off","check-on")||o.classList.add("check-on"),r.checked=!0):(o.classList.replace("check-on","check-off"),r.checked=!1)}else{if(0===c){n=r.checked;continue}n?(o.classList.replace("check-off","check-on")||o.classList.add("check-on"),r.checked=!0):(o.classList.replace("check-on","check-off"),r.checked=!1)}}}function u(e,t){return t<e?1:e<t?-1:0}!function(){l.options=Object.assign(c,n);var e=a.columnTitles,t=a.columnValues;if(!e.length||!t.length)throw new Error("Failed to initialize (missing settings)");s()}()}window.tidyTable=function(e,t,n){return new TidyTable(e,t,n)},"undefined"!=typeof module&&module.exports&&(module.exports=TidyTable);
@@ -0,0 +1,143 @@
1
+ /**
2
+ * tidy-table
3
+ * Create a HTML table that can be sorted, selected and
4
+ * post-processed using a simple callback.
5
+ *
6
+ * Copyright 2012-2023, Marc S. Brooks (https://mbrooks.info)
7
+ * Licensed under the MIT license:
8
+ * http://www.opensource.org/licenses/mit-license.php
9
+ */
10
+
11
+ .tidy-table {
12
+ table {
13
+ background-color: #fff;
14
+ border-collapse: collapse;
15
+ border: 1px solid #ccc;
16
+ cursor: pointer;
17
+ white-space: nowrap;
18
+
19
+ thead, tbody {
20
+ input[type='checkbox'] {
21
+ display: block;
22
+ margin: 0px auto;
23
+ }
24
+
25
+ td, th {
26
+ padding: 6px 20px;
27
+
28
+ &:nth-child(1) {
29
+ width: 10px;
30
+ }
31
+ }
32
+ }
33
+
34
+ thead {
35
+ border: none;
36
+
37
+ th {
38
+ background-color: #ddd;
39
+
40
+ &.arrow-down {
41
+ background: #eee url('../images/arrow-down.svg') no-repeat right center;
42
+ }
43
+
44
+ &.arrow-up {
45
+ background: #eee url('../images/arrow-up.svg') no-repeat right center;
46
+ }
47
+ }
48
+ }
49
+
50
+ tbody {
51
+ tr {
52
+ &.check-on {
53
+ background-color: #f5f5f5;
54
+ }
55
+
56
+ &.check-off {
57
+ background-color: #fff;
58
+ }
59
+
60
+ td {
61
+ border-right: 1px solid #eee;
62
+ border-top: 1px solid #ccc;
63
+ padding: 7px 20px;
64
+
65
+ .label {
66
+ display: none;
67
+ }
68
+
69
+ &:nth-child(1) {
70
+ border-right: 1px solid #eee;
71
+ }
72
+
73
+ &:nth-last-child(1) {
74
+ border-right: none;
75
+ }
76
+ }
77
+ }
78
+ }
79
+ }
80
+
81
+ @media only screen and (min-device-width: 0px) and (max-device-width: 800px) {
82
+ &.responsive {
83
+ margin: 0px !important;
84
+ overflow: auto;
85
+ width: auto !important;
86
+
87
+ table {
88
+ border: 0px;
89
+ border-top: 1px solid #ddd;
90
+ width: 100%;
91
+
92
+ thead, tbody {
93
+ td, th {
94
+ border: 0px;
95
+ box-sizing: border-box;
96
+ clear: both;
97
+ float: left;
98
+ padding-left: 10px;
99
+
100
+ &:first-child {
101
+ background-color: transparent;
102
+ padding: 10px;
103
+ position: absolute;
104
+ right: 0px;
105
+ top: 2px;
106
+ width: auto;
107
+ }
108
+ }
109
+ }
110
+
111
+ thead {
112
+ th {
113
+ text-align: left;
114
+ width: 100%;
115
+
116
+ &:first-child {
117
+ top: -40px;
118
+ }
119
+ }
120
+ }
121
+
122
+ tbody {
123
+ tr {
124
+ border-bottom: 1px solid #ccc;
125
+ position: relative;
126
+
127
+ &:last-child {
128
+ border: none;
129
+ }
130
+ }
131
+
132
+ td {
133
+ background-color: transparent;
134
+
135
+ &:first-child {
136
+ border: none;
137
+ }
138
+ }
139
+ }
140
+ }
141
+ }
142
+ }
143
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tidy-table",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "Create a HTML table that can be sorted, selected, and post-processed using a simple callback.",
5
5
  "main": "src/tidy-table.js",
6
6
  "scripts": {