diff --git a/output/js/constants.js b/output/js/constants.js index 8fe3d67..027fd7f 100644 --- a/output/js/constants.js +++ b/output/js/constants.js @@ -33,7 +33,7 @@ export const ATTRIBUTES = { ACTIVE: 'data-sort', ASCENDING: 'data-sort-asc', COLUMN: 'data-sorted-by', - COLUMN_LITERAL: 'sorted-by' + // COLUMN_LITERAL: 'sorted-by' } }; @@ -41,7 +41,14 @@ export function columnAscendingByDefault(column) { return column != COLUMN.USERS; } -export function columnIsSortable(column) { return column != COLUMN.QR_CODE; } +export function columnIsSortable(column) { + return ![ + COLUMN.QR_CODE, + COLUMN.PREVIEW, + // Join URL contents are not guaranteed to have visible text. + COLUMN.JOIN_URL + ].includes(column); +} export function columnNeedsCasefold(column) { return [ @@ -64,22 +71,22 @@ export function columnIsNumeric(column) { * @returns {HTMLElement} */ function createElement(tag, ...args) { - const element = document.createElement(tag); - if (args.length === 0) return element; - const propsCandidate = args[0]; - if (typeof propsCandidate !== "string" && !(propsCandidate instanceof Element)) { - // args[0] is not child element or text node - // must be props object - Object.assign(element, propsCandidate); - args.shift(); - } - element.append(...args); - return element; + const element = document.createElement(tag); + if (args.length === 0) return element; + const propsCandidate = args[0]; + if (typeof propsCandidate !== "string" && !(propsCandidate instanceof Element)) { + // args[0] is not child element or text node + // must be props object + Object.assign(element, propsCandidate); + args.shift(); + } + element.append(...args); + return element; } export const element = new Proxy({}, { - get(_, key) { - return (...args) => createElement(key, ...args) - } + get(_, key) { + return (...args) => createElement(key, ...args) + } }); diff --git a/output/main.js b/output/main.js index 8865a5a..8f3fb01 100644 --- a/output/main.js +++ b/output/main.js @@ -248,17 +248,22 @@ function setSortState(table, { ascending, column }) { } table.setAttribute(ATTRIBUTES.SORTING.ASCENDING, ascending); table.setAttribute(ATTRIBUTES.SORTING.COLUMN, column); - // This can be used to style column headers in a consistent way, i.e. - // #tbl_communities[data-sort-asc=true][sorted-by=name]::after #th_name, ... - table.setAttribute(ATTRIBUTES.SORTING.COLUMN_LITERAL, COLUMN_LITERAL[column]); + + // No way around this for brief CSS. + const headers = table.querySelectorAll("th"); + headers.forEach((th, colno) => { + th.removeAttribute(ATTRIBUTES.SORTING.ACTIVE); + }); + headers[column].setAttribute(ATTRIBUTES.SORTING.ACTIVE, true); } // This is best done in JS, as it would require