Hi all,
One of the things I like about K2 is the way that the (sub)categories are dispalyed as "boxes", and how they are all given the same height. But maybe you - as well as I - noticed that the height calculation is a bit simplistic: it simple looks for the longest description and then adds the same height to all subcategory boxes. That means that if your category descriptions varies in length, or if you have portrait images mixed with landscape images you might have unneccessary and ugly empty spaces within the dscription boxes. This piece of codes adjusts that by calculating the height on a per row basis.
If you can use it - please feel free. (And if Keris and others want to include it in future versions of K2, please do so!)
Instructions:
1. Change this line in category.php(either in your templates HTML folder, or in com_k2/templates/default/category.php )
<div class="subCategory">to<div class="subCategory" id="subCategory<?php $key;?>">
2. Change the javascript code in k2.js:
Find this:
window.addEvent('load', function(){ // Equal block heights for the "default" view if($$('.subCategory')){ var blocks = $$('.subCategory'); var maxHeight = 0; blocks.each(function(item){ maxHeight = Math.max(maxHeight, parseInt(item.getStyle('height'))); }); blocks.setStyle('height', maxHeight); } });
Replace with:
window.addEvent('load', function(){ // Equal block heights for the "default" view if($$('.subCategory')){ var blocks = $$('.subCategory'); var n = blocks.length; for(var i=0; i<n; i+=2){ var maxHeight = 0; var sublast_id1 = 'subCategory'+i; var sublast_id2 = 'subCategory'+(i+1); if($(sublast_id2)){ maxHeight = Math.max(parseInt($(sublast_id1).getStyle('height')), parseInt($(sublast_id2).getStyle('height'))); $(sublast_id1).setStyle('height', maxHeight); $(sublast_id2).setStyle('height', maxHeight); } } } });
One of the things I like about K2 is the way that the (sub)categories are dispalyed as "boxes", and how they are all given the same height. But maybe you - as well as I - noticed that the height calculation is a bit simplistic: it simple looks for the longest description and then adds the same height to all subcategory boxes. That means that if your category descriptions varies in length, or if you have portrait images mixed with landscape images you might have unneccessary and ugly empty spaces within the dscription boxes. This piece of codes adjusts that by calculating the height on a per row basis.
If you can use it - please feel free. (And if Keris and others want to include it in future versions of K2, please do so!)
Instructions:
1. Change this line in category.php(either in your templates HTML folder, or in com_k2/templates/default/category.php )
<div class="subCategory">to<div class="subCategory" id="subCategory<?php $key;?>">
2. Change the javascript code in k2.js:
Find this:
window.addEvent('load', function(){ // Equal block heights for the "default" view if($$('.subCategory')){ var blocks = $$('.subCategory'); var maxHeight = 0; blocks.each(function(item){ maxHeight = Math.max(maxHeight, parseInt(item.getStyle('height'))); }); blocks.setStyle('height', maxHeight); } });
Replace with:
window.addEvent('load', function(){ // Equal block heights for the "default" view if($$('.subCategory')){ var blocks = $$('.subCategory'); var n = blocks.length; for(var i=0; i<n; i+=2){ var maxHeight = 0; var sublast_id1 = 'subCategory'+i; var sublast_id2 = 'subCategory'+(i+1); if($(sublast_id2)){ maxHeight = Math.max(parseInt($(sublast_id1).getStyle('height')), parseInt($(sublast_id2).getStyle('height'))); $(sublast_id1).setStyle('height', maxHeight); $(sublast_id2).setStyle('height', maxHeight); } } } });