Skip to content

Commit

Permalink
Better handling of tables without theads
Browse files Browse the repository at this point in the history
  • Loading branch information
adamschwartz committed Sep 16, 2015
1 parent 474648e commit 06f5c3a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions js/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@
var options = INSTALL_OPTIONS;

Array.prototype.forEach.call(document.querySelectorAll('table'), function(table){
try {
// If there’s no tHead but the first tBody row contains ths, create a tHead and move that row into it.
if (!table.tHead && (var firstTBodyRow = table.tBodies[0].rows[0]).children[0].tagName === 'TH') {
var tHead = document.createElement('thead');
tHead.appendChild(firstTBodyRow);
table.insertBefore(tHead, table.firstChild);
}

// Sortable requires this
if (table.tHead.rows.length !== 1) {
return;
}
} catch (err) {
return;
}

table.setAttribute('data-sortable', '');
table.classList.add('sortable-theme-' + options.theme);
});
Expand Down

0 comments on commit 06f5c3a

Please sign in to comment.