From 22e4fa4023da806b8fab43030e313fae1ea4fd7a Mon Sep 17 00:00:00 2001
From: Chris Hood <chris@univate.com.au>
Date: Thu, 11 Aug 2011 01:36:35 +1000
Subject: [PATCH] Port to D7

---
 block_tab.info   |    3 +-
 block_tab.module |   78 ++++++++++++++++++++++-------------------------------
 js/block_tab.js  |   30 +++++++++++---------
 3 files changed, 50 insertions(+), 61 deletions(-)

diff --git a/block_tab.info b/block_tab.info
index ee0370b..a6c231e 100644
--- a/block_tab.info
+++ b/block_tab.info
@@ -1,2 +1,3 @@
 name = Block tab
-core = 6.x
+description = Transfer all blocks in a region into tabs.
+core = 7.x
diff --git a/block_tab.module b/block_tab.module
index b9f2574..0be92e7 100644
--- a/block_tab.module
+++ b/block_tab.module
@@ -6,7 +6,7 @@
  */
 function block_tab_menu() {
   return array(
-    'admin/settings/block_tab' => array(
+    'admin/config/system/block_tab' => array(
       'type' => MENU_NORMAL_ITEM,
       'title' => 'Block tab settings',
       'page callback' => 'drupal_get_form',
@@ -21,68 +21,54 @@ function block_tab_menu() {
  * Implementation of hook_perm().
  */
 function block_tab_perm() {
-  return array('administer block tab settings');
+  return array('
+    administer block tab settings' => array(
+      'title' => t('Administer block tabs'),
+    ),
+  );
 }
 
 /**
- * Implementation of hook_init().
+ * Template preprocessor function.
  */
-function block_tab_init() {
+function block_tab_preprocess_region(&$variables) {
   $path = drupal_get_path('module', 'block_tab');
   drupal_add_css($path . '/css/block_tab.css');
   drupal_add_js($path . '/js/block_tab.js');
-}
 
-/**
- * Renders a region as a tabbed block group.
- */
-function block_tab_blocks($region) {
   $region_setting = variable_get('block_tab-regions', array());
-
+  $region = $variables['region'];
   if (!isset($region_setting[$region]) || (string) $region_setting[$region] != $region) {
-    return theme_blocks($region);
+
   }
+  else {
+    $titles = array();
+    $output = '';
+    $first_flag = TRUE;
 
-  $titles = array();
-  $output = '';
-  $first_flag = TRUE;
+    foreach (element_children($variables['elements']) as $bid) {
+      if (isset($variables['elements'][$bid]['#block'])) {
 
-  if ($list = block_list($region)) {
-    foreach ($list as $key => $block) {
-      // $key == <i>module</i>_<i>delta</i>
+        $block = $variables['elements'][$bid]['#block'];
+        $titles[] = array(
+          'title' => empty($block->subject) ? $bid : $block->subject,
+          'key' => $bid,
+          'active' => $first_flag ? ' active' : '',
+        );
 
-      $titles[] = array(
-        'title' => empty($block->subject) ? $key : $block->subject,
-        'key' => $key,
-        'active' => $first_flag ? ' active' : '',
-      );
-      $block->subject = '';
+        $variables['elements'][$bid]['#block']->subject = '';
+        $output .= '<div class="block_tab-block' . ($first_flag ? ' visible' : '') . '" id="block_tab-block-' . $bid . '">' . render($variables['elements'][$bid]['content']) . '</div>';
 
-      $output .= '<div class="block_tab-block' . ($first_flag ? ' visible' : '') . '" id="block_tab-block-' . $key . '">' . theme('block', $block) . '</div>';
-      $first_flag = FALSE;
+        $first_flag = FALSE;
+      }
     }
-  }
-
-  // Add any content assigned to this region through drupal_set_content() calls.
-  $output .= drupal_get_content($region);
 
-  $title_html = '';
-  foreach ((array) $titles as $title) {
-    $title_html .= '<span class="block_tab-title' . $title['active'] . '" id="block_tab-title-' . $title['key'] . '">' . check_plain($title['title']) . '</span>';
-  }
+    $title_html = '';
+    foreach ((array) $titles as $title) {
+      $title_html .= '<span class="block_tab-title' . $title['active'] . '" id="block_tab-title-' . $title['key'] . '">' . check_plain($title['title']) . '</span>';
+    }
 
-  return '<div class="block_tab-titles" region="' . $region . '">' . $title_html . '</div>
+    $variables['content'] = '<div class="block_tab-titles" region="' . $region . '">' . $title_html . '</div>
           <div class="block_tab-blocks" region="' . $region . '">' . $output . '</div>';
+  }
 }
-
-/**
- * Implementation of hook_theme().
- */
-function block_tab_theme() {
-  return array(
-    'blocks' => array(
-      'arguments' => array('region' => array()),
-      'function' => 'block_tab_blocks',
-    )
-  );
-}
\ No newline at end of file
diff --git a/js/block_tab.js b/js/block_tab.js
index 9720b08..1782443 100644
--- a/js/block_tab.js
+++ b/js/block_tab.js
@@ -1,17 +1,19 @@
+(function($) {
+  Drupal.behaviors.BlockTab = {
+    attach: function() {
+      $('.block_tab-block').hide();
+      $('.block_tab-block:first').show();
 
+      $('.block_tab-title').click(function() {
+        var region = $(this).parent().attr('region');
+        var id  = $(this).attr('id').replace(/block_tab-title-/, '', 'gi');
 
-Drupal.behaviors.BlockTab = function() {
-  $('.block_tab-block').hide();
-  $('.block_tab-block:first').show();
+        $('[region="' + region + '"] .block_tab-block').hide();
+        $('[region="' + region + '"] .block_tab-title').removeClass('active');
 
-  $('.block_tab-title').click(function() {
-    var region = $(this).parent().attr('region');
-    var id  = $(this).attr('id').replace(/block_tab-title-/, '', 'gi');
-
-    $('[region="' + region + '"] .block_tab-block').hide();
-    $('[region="' + region + '"] .block_tab-title').removeClass('active');
-
-    $('[region="' + region + '"] #block_tab-block-' + id).fadeIn('fast');
-    $(this).addClass('active');
-  });
-}
+        $('[region="' + region + '"] #block_tab-block-' + id).fadeIn('fast');
+        $(this).addClass('active');
+      });
+    }
+  }
+})(jQuery)
-- 
1.7.4.1

