Created
December 17, 2014 13:15
-
-
Save KostasBlank/91fe07571d5eb4be701a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @file | |
* A JavaScript file for the theme. | |
* | |
* Resizes all elements having the class equal-height-parent to the same height. | |
*/ | |
(function ($, Drupal, window, document, undefined) { | |
/** | |
* Equal Height Blocks in Rows src: http://css-tricks.com/equal-height-blocks-in-rows/ | |
* Adapted to use outerHeight instead of height and also reset height before calculations. | |
*/ | |
function resizeColumns(selector){ | |
var currentTallest = 0, | |
currentRowStart = 0, | |
rowDivs = new Array(), | |
$el, | |
topPosition = 0; | |
$(selector).each(function() { | |
$el = $(this); | |
$el.height('auto'); | |
topPostion = $el.position().top; | |
if (currentRowStart != topPostion) { | |
// we just came to a new row. Set all the heights on the completed row | |
for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) { | |
rowDivs[currentDiv].height(currentTallest); | |
} | |
// set the variables for the new row | |
rowDivs.length = 0; // empty the array | |
currentRowStart = topPostion; | |
currentTallest = $el.outerHeight(); | |
rowDivs.push($el); | |
} else { | |
// another div on the current row. Add it to the list and check if it's taller | |
rowDivs.push($el); | |
currentTallest = (currentTallest < $el.outerHeight()) ? ($el.outerHeight()) : (currentTallest); | |
} | |
// do the last row | |
for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) { | |
rowDivs[currentDiv].height(currentTallest); | |
} | |
}); | |
} | |
$( window ).load(function() { | |
resizeColumns('.equal-height-parent'); | |
}); | |
$( window ).resize(function() { | |
resizeColumns('.equal-height-parent'); | |
}); | |
})(jQuery, Drupal, this, this.document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment