Skip to content

Instantly share code, notes, and snippets.

@backflip
Last active April 27, 2018 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save backflip/5fc832aa48077eda6dc7fecb0b0d0749 to your computer and use it in GitHub Desktop.
Save backflip/5fc832aa48077eda6dc7fecb0b0d0749 to your computer and use it in GitHub Desktop.
Bookmarklet für TG Hütten Monatsprogramm
;(function() {
var options = {
container: '.j-hgrid',
column: '.cc-m-hgrid-column',
cell: '.j-text',
minWidth: '100px'
};
function setHeights(rows) {
rows.forEach(function(row) {
// Get highest cell
var heights = row.map(function(cell) {
cell.style.minHeight = 0;
return cell.offsetHeight;
}),
maxHeight = Math.max.apply(null, heights);
// Set each cell to max height
row.forEach(function(cell) {
cell.style.minHeight = maxHeight + 'px';
});
});
}
var containers = document.querySelectorAll(options.container);
[].slice.call(containers).forEach(function(container) {
var cells = container.querySelectorAll(options.cell);
// Stop if there are no cells
if (cells.length === 0) {
return;
}
var columns = container.querySelectorAll(options.column);
var rows = [];
// Display columns next to each other
container.style.display = 'flex';
container.style.overflow = 'auto';
[].slice.call(columns).forEach(function(column) {
var columnCells = column.querySelectorAll(options.cell);
// Set smaller min-width (100% by default)
column.style.minWidth = options.minWidth;
// Create arrays of cell rows
[].slice.call(columnCells).forEach(function(cell, i) {
rows[i] = rows[i] || [];
rows[i].push(cell);
});
});
// Set cell heights per row
setHeights(rows);
// Reset height on window resize
window.addEventListener('resize', setHeights.bind(null, rows), false);
});
})();
// javascript:void%20function(){function%20l(l){l.forEach(function(l){var%20e=l.map(function(l){return%20l.style.minHeight=0,l.offsetHeight}),n=Math.max.apply(null,e);l.forEach(function(l){l.style.minHeight=n+%22px%22})})}var%20e={container:%22.j-hgrid%22,column:%22.cc-m-hgrid-column%22,cell:%22.j-text%22,minWidth:%22100px%22},n=document.querySelectorAll(e.container);[].slice.call(n).forEach(function(n){var%20t=n.querySelectorAll(e.cell);if(0!==t.length){var%20c=n.querySelectorAll(e.column),i=[];n.style.display=%22flex%22,n.style.overflow=%22auto%22,[].slice.call(c).forEach(function(l){var%20n=l.querySelectorAll(e.cell);l.style.minWidth=e.minWidth,[].slice.call(n).forEach(function(l,e){i[e]=i[e]||[],i[e].push(l)})}),l(i),window.addEventListener(%22resize%22,l.bind(null,i),!1)}})}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment