71 lines
1.6 KiB
JavaScript
71 lines
1.6 KiB
JavaScript
(function collonadeClosure() {
|
|
'use strict';
|
|
|
|
window.utils = window.utils || {};
|
|
|
|
var JS_INITIALIZED_CLASS = 'js-initialized';
|
|
var CHECKBOX_SELECTOR = '.checkbox';
|
|
|
|
window.utils.checkAll = function(wrapper, options) {
|
|
|
|
if (!wrapper || wrapper.classList.contains(JS_INITIALIZED_CLASS)) {
|
|
return false;
|
|
}
|
|
options = options || {};
|
|
|
|
var columns = [];
|
|
|
|
function init() {
|
|
|
|
columns = gatherColumns(wrapper);
|
|
|
|
var checkboxColumn = findCheckboxColumn(columns);
|
|
if (checkboxColumn) {
|
|
setup(checkboxColumn);
|
|
}
|
|
}
|
|
|
|
function gatherColumns(table) {
|
|
var rows = Array.from(table.querySelectorAll('tr'));
|
|
var cols = [];
|
|
rows.forEach(function(tr) {
|
|
var cells = Array.from(tr.querySelectorAll('td'));
|
|
cells.forEach(function(cell, iCell) {
|
|
if (!cols[iCell]) {
|
|
cols[iCell] = [];
|
|
}
|
|
cols[iCell].push(cell);
|
|
});
|
|
});
|
|
return cols;
|
|
}
|
|
|
|
function findCheckboxColumn(cols) {
|
|
var checkboxColumn = null;
|
|
cols.forEach(function(col, i) {
|
|
if (isCheckboxColumn(col)) {
|
|
checkboxColumn = i;
|
|
}
|
|
});
|
|
return checkboxColumn;
|
|
}
|
|
|
|
function isCheckboxColumn(col) {
|
|
var onlyCheckboxes = true;
|
|
col.forEach(function(cell) {
|
|
console.log('checking', cell);
|
|
if (onlyCheckboxes && !cell.querySelector(CHECKBOX_SELECTOR)) {
|
|
onlyCheckboxes = false;
|
|
}
|
|
});
|
|
return onlyCheckboxes;
|
|
}
|
|
|
|
function setup(column) {
|
|
console.log('setting up column', column);
|
|
}
|
|
|
|
init();
|
|
};
|
|
})();
|