Skip to content

Instantly share code, notes, and snippets.

@Rebolon
Created March 23, 2015 08:30
Show Gist options
  • Save Rebolon/fadaf1c67799fb6bc54d to your computer and use it in GitHub Desktop.
Save Rebolon/fadaf1c67799fb6bc54d to your computer and use it in GitHub Desktop.
Improve lisibility
Template.registerHelper('setCardHeight',function(tabletCards){
var tabletCount = tabletCards.length;
var tabletCardWidth = 450;
var screenWidth = $(window).width();
var cardsPerRow = Math.floor(screenWidth / tabletCardWidth);
if (cardsPerRow <= 1) {
return;
}
for (var i=0; i<tabletCount; i+=cardsPerRow) {
var maxHeight = $(tabletCards[i]).height();
for (var j=0; j<cardsPerRow; j++) {
if (j+i >= tabletCount) {
continue;
}
currentCardHeight = $(tabletCards[j+i]).height();
if (currentCardHeight > maxHeight) {
maxHeight = currentCardHeight;
}
}
maxHeight = maxHeight + 10;
var setHeight = 'height: ' + maxHeight + 'px';
for (var j=0; j<cardsPerRow; j++) {
if (j+i < tabletCount) {
tabletCards[j+i].setAttribute('style', setHeight);
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment