/* * This is a handler Simon made for things like product names * where the height of the div will be variable depending on content * but you want them to be the same height for neatness. * * The way you use this is to add the css class names from that page * as arguments and it does the rest for you. It works on the assumption * that either the php enforces a character limit OR there is a max-height * set in the css, otherwise the height has the potential to be very large * * example syntax: * * processHeightAdjust('css-class-1', 'css-class-2'); * * * It is recommended that the process height adjust function is put into * resize and load. If you declare the processHeightJSAdjust variable with * global scope it will make the code more efficient as the nodes will then * be cached howeever it still works if you forget. */ //declare the array var processHeightJsNodes = []; //example function call processHeightAdjust('item-name', 'ShopProd_Listing_Price', 'cat-product-wrapper', 'cat-dropdown-col-left'); function processHeightAdjust() { //checks that processHeightJsNodes array exists, if not create it var processHeightJsNodes = processHeightJsNodes || []; //looks to see if the values have been chached if not, assigns them if(! processHeightJsNodes[0]){ for (i = 0; i < arguments.length; i++) { //takes the arguments, finds the nodes and pushes them to the procressHeightJSNodes array processHeightJsNodes.push(document.getElementsByClassName(arguments[i])); } } //for each ccs class for (i = 0; i < processHeightJsNodes.length; i++) { var max = 0; var elements = []; //assign the notes to the elents array elements = processHeightJsNodes[i]; //look through them, if the height is more than the max height make it the max height for (x = 0; x < elements.length; x++) { //this line lowers the efficiency but is necessary if you want //the heights to adapt to making the window bigger, not just shrinking elements[x].setAttribute("style","height:"+"auto"); if(elements[x].clientHeight > max) max=Math.ceil(elements[x].clientHeight); } for (y = 0; y < elements.length; y++) { //loop through the elements and apply that max height to them all elements[y].setAttribute("style","height:"+max+"px"); } } } window.onresize = function(){ processHeightAdjust('item-name', 'ShopProd_Listing_Price', 'cat-product-wrapper', 'cat-dropdown-col-left'); };