owlcode.tech/js-src/index.ts

35 lines
1.2 KiB
TypeScript

"use strict";
import Tablesort from 'tablesort';
window.Tablesort = require('tablesort');
require('tablesort/src/sorts/tablesort.number');
window.onload = () => {
const menu_expand = document.querySelector('a.menu-expand');
const mobile_foldable = document.querySelector('nav.mobile-foldable');
const first_box = document.querySelector('#first-box');
const tables = document.querySelectorAll('table')
if (menu_expand !== null && mobile_foldable !== null) {
menu_expand.addEventListener('click', () => {
mobile_foldable.classList.toggle('show');
if (first_box !== null) {
console.log('hola')
first_box.classList.toggle('margin');
}
});
}
for (const table of tables) {
const header = table.querySelector('tr');
if (header !== null) {
header.setAttribute('data-sort-method', 'none')
for (const th of header.querySelectorAll('th')) {
if (th.getAttribute('data-sort-method') == null) {
th.setAttribute('data-sort-method', 'thead')
}
}
}
new Tablesort(table)
}
};