From 7ddec8ac5cccbf93126e8b5875867d6c2531148d Mon Sep 17 00:00:00 2001
From: Neil Drumm <drumm@delocalizedham.com>
Date: Fri, 1 Jun 2012 16:42:25 -0700
Subject: [PATCH] [#955072] Make Homebox only equalize heights of columns
 within the same row

---
 homebox.js      |   14 ++++++--------
 homebox.module  |    9 +++++++++
 homebox.tpl.php |    2 +-
 3 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/homebox.js b/homebox.js
index 9c5d941..0f3d995 100644
--- a/homebox.js
+++ b/homebox.js
@@ -81,16 +81,14 @@
    * Set all column heights equal
    */
   Drupal.homebox.equalizeColumnsHeights = function () {
-    var maxHeight = 0;
+    var maxHeight = {}, row;
     Drupal.homebox.$columns.each(function () {
-      if ($(this).parent('.homebox-column-wrapper').attr('style').match(/width: 100%/i) == null) {
-        $(this).height('auto');
-        maxHeight = Math.max($(this).height(), maxHeight);
-      }
+      row = $(this).parent('.homebox-column-wrapper').attr('class').match(/homebox-row-(\d+)/i)[1];
+      $(this).height('auto');
+      maxHeight[row] = maxHeight[row] ? Math.max($(this).height(), maxHeight[row]) : $(this).height();
     }).each(function () {
-      if ($(this).parent('.homebox-column-wrapper').attr('style').match(/width: 100%/i) == null) {
-        $(this).height(maxHeight);
-      }
+      row = $(this).parent('.homebox-column-wrapper').attr('class').match(/homebox-row-(\d+)/i)[1];
+      $(this).height(maxHeight[row]);
     });
   };
 
diff --git a/homebox.module b/homebox.module
index 603ef9d..3c36615 100644
--- a/homebox.module
+++ b/homebox.module
@@ -378,8 +378,17 @@ function homebox_build($page) {
   }
 
   // Sort each region/column based on key value
+  // Also separate the regions into rows based on the region widths
+  $sum_width = 0;
+  $row = 0;
   for ($i = 1; $i <= count($regions); $i++) {
     ksort($regions[$i]);
+    $sum_width += $page->settings['widths'][$i];
+    if ($sum_width > 100) {
+      $row++;
+      $sum_width = 0;
+    }
+    $page->settings['rows'][$i] = $row;
   }
 
   // Add block links
diff --git a/homebox.tpl.php b/homebox.tpl.php
index a9c97eb..da8ab70 100644
--- a/homebox.tpl.php
+++ b/homebox.tpl.php
@@ -23,7 +23,7 @@
 
   <div class="homebox-maximized"></div>
   <?php for ($i = 1; $i <= count($regions); $i++): ?>
-    <div class="homebox-column-wrapper homebox-column-wrapper-<?php print $i; ?>"<?php print count($page->settings['widths']) ? ' style="width: ' . $page->settings['widths'][$i] . '%;"' : ''; ?>>
+    <div class="homebox-column-wrapper homebox-column-wrapper-<?php print $i; ?> homebox-row-<?php print $page->settings['rows'][$i]; ?>"<?php print count($page->settings['widths']) ? ' style="width: ' . $page->settings['widths'][$i] . '%;"' : ''; ?>>
       <div class="homebox-column" id="homebox-column-<?php print $i; ?>">
         <?php foreach ($regions[$i] as $key => $weight): ?>
           <?php foreach ($weight as $block): ?>
-- 
1.7.5.4

