Index: modules/dashboard/dashboard.js
===================================================================
RCS file: /cvs/drupal/drupal/modules/dashboard/dashboard.js,v
retrieving revision 1.6
diff -u -r1.6 dashboard.js
--- modules/dashboard/dashboard.js	14 Jan 2010 04:04:30 -0000	1.6
+++ modules/dashboard/dashboard.js	16 Jan 2010 11:59:34 -0000
@@ -1,176 +1,178 @@
 // $Id: dashboard.js,v 1.6 2010/01/14 04:04:30 webchick Exp $
 (function ($) {
 
+Drupal.dashboard = Drupal.dashboard || {};
+
 /**
  * Implementation of Drupal.behaviors for dashboard.
  */
 Drupal.behaviors.dashboard = {
   attach: function () {
     $('#dashboard').prepend('<div class="customize"><ul class="action-links"><a href="#">' + Drupal.t('Customize dashboard') + '</a></ul><div class="canvas"></div></div>');
-    $('#dashboard .customize .action-links a').click(Drupal.behaviors.dashboard.enterCustomizeMode);
+    $('#dashboard .customize .action-links a').click(Drupal.dashboard.enterCustomizeMode);
     if ($('#dashboard .region .block').length == 0) {
       Drupal.settings.dashboard.launchCustomize = true;
     }
-    Drupal.behaviors.dashboard.addPlaceholders();
+    Drupal.dashboard.addPlaceholders();
     if (Drupal.settings.dashboard.launchCustomize) {
-      Drupal.behaviors.dashboard.enterCustomizeMode();
+      Drupal.dashboard.enterCustomizeMode();
     }
-  },
+  }
+};
 
-  addPlaceholders: function() {
-    $('#dashboard .dashboard-region .region').each(function () {
-      var empty_text = "";
-      // If the region is empty
-      if ($('.block', this).length == 0) {
-        // Check if we are in customize mode and grab the correct empty text
-        if ($('#dashboard').hasClass('customize-mode')) {
-          empty_text = Drupal.settings.dashboard.emptyRegionTextActive;
-        } else {
-          empty_text = Drupal.settings.dashboard.emptyRegionTextInactive;
-        }
-        // We need a placeholder.
-        if ($('.placeholder', this).length == 0) {
-          $(this).append('<div class="placeholder"></div>');
-        }
-        $('.placeholder', this).html(empty_text);
+Drupal.dashboard.addPlaceholders = function() {
+  $('#dashboard .dashboard-region .region').each(function () {
+    var empty_text = "";
+    // If the region is empty
+    if ($('.block', this).length == 0) {
+      // Check if we are in customize mode and grab the correct empty text
+      if ($('#dashboard').hasClass('customize-mode')) {
+        empty_text = Drupal.settings.dashboard.emptyRegionTextActive;
+      } else {
+        empty_text = Drupal.settings.dashboard.emptyRegionTextInactive;
       }
-      else {
-        $('.placeholder', this).remove();
+      // We need a placeholder.
+      if ($('.placeholder', this).length == 0) {
+        $(this).append('<div class="placeholder"></div>');
       }
-    });
-  },
+      $('.placeholder', this).html(empty_text);
+    }
+    else {
+      $('.placeholder', this).remove();
+    }
+  });
+};
 
-  /**
-   * Enter "customize" mode by displaying disabled blocks.
-   */
-  enterCustomizeMode: function () {
-    $('#dashboard').addClass('customize-mode');
-    Drupal.behaviors.dashboard.addPlaceholders();
-    // Hide the customize link
-    $('#dashboard .customize .action-links').hide();
-    // Load up the disabled blocks
-    $('div.customize .canvas').load(Drupal.settings.dashboard.drawer, Drupal.behaviors.dashboard.setupDrawer);
-  },
-
-  /**
-   * Exit "customize" mode by simply forcing a page refresh.
-   */
-  exitCustomizeMode: function () {
-    $('#dashboard').removeClass('customize-mode');
-    Drupal.behaviors.dashboard.addPlaceholders();
-    location.href = Drupal.settings.dashboard.dashboard;
-  },
-
-  /**
-   * Helper for enterCustomizeMode; sets up drag-and-drop and close button.
-   */
-  setupDrawer: function () {
-    $('div.customize .canvas-content input').click(Drupal.behaviors.dashboard.exitCustomizeMode);
-    $('div.customize .canvas-content').append('<a class="button" href="">' + Drupal.t('Done') + '</a>');
-
-    // Initialize drag-and-drop.
-    var regions = $('#dashboard div.region');
-    regions.sortable({
-      connectWith: regions,
-      cursor: 'move',
-      cursorAt: {top:0},
-      dropOnEmpty: true,
-      items: '>div.block, div.disabled-block',
-      opacity: 1,
-      helper: 'block-dragging',
-      placeholder: 'block-placeholder clearfix',
-      start: Drupal.behaviors.dashboard.start,
-      update: Drupal.behaviors.dashboard.update
-    });
-  },
+/**
+ * Enter "customize" mode by displaying disabled blocks.
+ */
+Drupal.dashboard.enterCustomizeMode = function () {
+  $('#dashboard').addClass('customize-mode');
+  Drupal.dashboard.addPlaceholders();
+  // Hide the customize link
+  $('#dashboard .customize .action-links').hide();
+  // Load up the disabled blocks
+  $('div.customize .canvas').load(Drupal.settings.dashboard.drawer, Drupal.dashboard.setupDrawer);
+};
 
-  /**
-   * While dragging, make the block appear as a disabled block
-   *
-   * This function is called on the jQuery UI Sortable "start" event.
-   *
-   * @param event
-   *  The event that triggered this callback.
-   * @param ui
-   *  An object containing information about the item that is being dragged.
-   */
-  start: function (event, ui) {
-    var item = $(ui.item);
-
-    // If the block is already in disabled state, don't do anything.
-    if (!item.hasClass('disabled-block')) {
-      item.css({height: 'auto'});
-    }
-  },
+/**
+ * Exit "customize" mode by simply forcing a page refresh.
+ */
+Drupal.dashboard.exitCustomizeMode = function () {
+  $('#dashboard').removeClass('customize-mode');
+  Drupal.dashboard.addPlaceholders();
+  location.href = Drupal.settings.dashboard.dashboard;
+};
 
-  /**
-   * Send block order to the server, and expand previously disabled blocks.
-   *
-   * This function is called on the jQuery UI Sortable "update" event.
-   *
-   * @param event
-   *   The event that triggered this callback.
-   * @param ui
-   *   An object containing information about the item that was just dropped.
-   */
-  update: function (event, ui) {
-    var item = $(ui.item);
-
-    // If the user dragged a disabled block, load the block contents.
-    if (item.hasClass('disabled-block')) {
-      var module, delta, itemClass;
-      itemClass = item.attr('class');
-      // Determine the block module and delta.
-      module = itemClass.match(/\bmodule-(\S+)\b/)[1];
-      delta = itemClass.match(/\bdelta-(\S+)\b/)[1];
-
-      // Load the newly enabled block's content.
-      $.get(Drupal.settings.dashboard.blockContent + '/' + module + '/' + delta, {},
-        function (block) {
-          var blockContent = "";
-          if (block) {
-            blockContent = $("div.content", $(block));
-          }
-
-          if (!blockContent) {
-            blockContent = $('<div class="content">' + Drupal.settings.dashboard.emptyBlockText + '</div>');
-          }
-
-          $("div.content", item).after(blockContent).remove();
-        },
-        'html'
-      );
-      // Remove the "disabled-block" class, so we don't reload its content the
-      // next time it's dragged.
-      item.removeClass("disabled-block");
-    }
+/**
+ * Helper for enterCustomizeMode; sets up drag-and-drop and close button.
+ */
+Drupal.dashboard.setupDrawer = function () {
+  $('div.customize .canvas-content input').click(Drupal.dashboard.exitCustomizeMode);
+  $('div.customize .canvas-content').append('<a class="button" href="">' + Drupal.t('Done') + '</a>');
+
+  // Initialize drag-and-drop.
+  var regions = $('#dashboard div.region');
+  regions.sortable({
+    connectWith: regions,
+    cursor: 'move',
+    cursorAt: {top:0},
+    dropOnEmpty: true,
+    items: '>div.block, div.disabled-block',
+    opacity: 1,
+    helper: 'block-dragging',
+    placeholder: 'block-placeholder clearfix',
+    start: Drupal.dashboard.start,
+    update: Drupal.dashboard.update
+  });
+};
 
-    Drupal.behaviors.dashboard.addPlaceholders();
+/**
+ * While dragging, make the block appear as a disabled block
+ *
+ * This function is called on the jQuery UI Sortable "start" event.
+ *
+ * @param event
+ *  The event that triggered this callback.
+ * @param ui
+ *  An object containing information about the item that is being dragged.
+ */
+Drupal.dashboard.start = function (event, ui) {
+  var item = $(ui.item);
 
-    // Let the server know what the new block order is.
-    $.post(Drupal.settings.dashboard.updatePath, {
-        'form_token': Drupal.settings.dashboard.formToken,
-        'regions': Drupal.behaviors.dashboard.getOrder
-      }
+  // If the block is already in disabled state, don't do anything.
+  if (!item.hasClass('disabled-block')) {
+    item.css({height: 'auto'});
+  }
+};
+
+/**
+ * Send block order to the server, and expand previously disabled blocks.
+ *
+ * This function is called on the jQuery UI Sortable "update" event.
+ *
+ * @param event
+ *   The event that triggered this callback.
+ * @param ui
+ *   An object containing information about the item that was just dropped.
+ */
+Drupal.dashboard.update = function (event, ui) {
+  var item = $(ui.item);
+
+  // If the user dragged a disabled block, load the block contents.
+  if (item.hasClass('disabled-block')) {
+    var module, delta, itemClass;
+    itemClass = item.attr('class');
+    // Determine the block module and delta.
+    module = itemClass.match(/\bmodule-(\S+)\b/)[1];
+    delta = itemClass.match(/\bdelta-(\S+)\b/)[1];
+
+    // Load the newly enabled block's content.
+    $.get(Drupal.settings.dashboard.blockContent + '/' + module + '/' + delta, {},
+      function (block) {
+        var blockContent = "";
+        if (block) {
+          blockContent = $("div.content", $(block));
+        }
+
+        if (!blockContent) {
+          blockContent = $('<div class="content">' + Drupal.settings.dashboard.emptyBlockText + '</div>');
+        }
+
+        $("div.content", item).after(blockContent).remove();
+      },
+      'html'
     );
-  },
+    // Remove the "disabled-block" class, so we don't reload its content the
+    // next time it's dragged.
+    item.removeClass("disabled-block");
+  }
+
+  Drupal.dashboard.addPlaceholders();
+
+  // Let the server know what the new block order is.
+  $.post(Drupal.settings.dashboard.updatePath, {
+      'form_token': Drupal.settings.dashboard.formToken,
+      'regions': Drupal.dashboard.getOrder
+    }
+  );
+};
 
-  /**
-   * Return the current order of the blocks in each of the sortable regions,
-   * in query string format.
-   */
-  getOrder: function () {
-    var order = [];
-    $('#dashboard div.region').each(function () {
-      var region = $(this).parent().attr('id').replace(/-/g, '_');
-      var blocks = $(this).sortable('toArray');
-      $.each(blocks, function() {
-        order.push(region + '[]=' + this);
-      });
+/**
+ * Return the current order of the blocks in each of the sortable regions,
+ * in query string format.
+ */
+Drupal.dashboard.getOrder = function () {
+  var order = [];
+  $('#dashboard div.region').each(function () {
+    var region = $(this).parent().attr('id').replace(/-/g, '_');
+    var blocks = $(this).sortable('toArray');
+    $.each(blocks, function() {
+      order.push(region + '[]=' + this);
     });
-    order = order.join('&');
-    return order;
-  }
+  });
+  order = order.join('&');
+  return order;
 };
 
 })(jQuery);
