Index: compact_forms.admin.inc
===================================================================
RCS file: compact_forms.admin.inc
diff -N compact_forms.admin.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ compact_forms.admin.inc	16 Mar 2009 23:21:04 -0000
@@ -0,0 +1,61 @@
+<?php
+// $Id: compact_forms.module,v 1.1 2007/07/29 17:20:58 tomsun Exp $
+
+/**
+ * @file
+ * Compact Forms administration functions.
+ */
+
+/**
+ * Form builder function for Compact Forms settings.
+ */
+function compact_forms_admin_form() {
+  $form['compact_forms_ids'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Form IDs'),
+    '#rows' => 3,
+    '#cols' => 40,
+    '#default_value' => variable_get('compact_forms_ids', 'user-login-form'),
+    '#description' => 'Enter the CSS #id of the forms that you want to activate compact_forms for. One per line.',
+  );
+  $form['compact_forms_stars'] = array(
+    '#title' => t('"Required field" - stars'),
+    '#type' => 'radios',
+    '#options' => array(
+      0 => t('Remove "required" stars'),
+      1 => t('Leave "required" stars attached to label'),
+      2 => t('Insert "required" stars after the field'),
+    ),
+    '#default_value' => variable_get('compact_forms_stars', 2),
+    '#description' => t('How to deal with the stars added by Drupal to indicate required fields.'),
+  );
+  $form['compact_forms_colons'] = array(
+    '#title' => t('Trailing colons in labels'),
+    '#type' => 'radios',
+    '#options' => array(
+      0 => t('Remove trailing colons from the label'),
+      1 => t('Keep trailing colons'),
+    ),
+    '#default_value' => variable_get('compact_forms_colons', 0),
+  );
+  $form['compact_forms_field_size'] = array(
+    '#title' => t('Textfield size'),
+    '#type' => 'textfield',
+    '#size' => 3,
+    '#default_value' => variable_get('compact_forms_field_size', ''),
+    '#description' => t('Optionally override the width of all text fields in the selected forms'),
+  );
+  $form['compact_forms_descriptions'] = array(
+    '#title' => t('Textfield descriptions'),
+    '#type' => 'radios',
+    '#options' => array(
+      0 => t('Hide descriptions'),
+      1 => t('Show descriptions'),
+    ),
+    '#default_value' => variable_get('compact_forms_descriptions', 1),
+    '#description' => t('Optionally hide descriptions of all textfields (in general not recommended).'),
+  );
+
+  return system_settings_form($form);
+}
+
Index: compact_forms.css
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/compact_forms/compact_forms.css,v
retrieving revision 1.1
diff -u -p -r1.1 compact_forms.css
--- compact_forms.css	29 Jul 2007 17:20:58 -0000	1.1
+++ compact_forms.css	16 Mar 2009 23:17:46 -0000
@@ -1,13 +1,13 @@
-/* $Id: compact_forms.css,v 1.1 2007/07/29 17:20:58 tomsun Exp $ */
+/* $Id: compact_forms.css,v 1.1 2007/07/29 17:20:58 tomsun Exp $ */
 
 .compact-form-wrapper {
   position: relative;
   text-align: left;
 }
 .compact-form-label {
-  position:absolute;
-  top:1px;
-  left:5px;
-  z-index:1;
+  position: absolute;
+  top: 1px;
+  left: 5px;
+  z-index: 1;
   font-size: .9em;
 }
Index: compact_forms.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/compact_forms/compact_forms.js,v
retrieving revision 1.1
diff -u -p -r1.1 compact_forms.js
--- compact_forms.js	29 Jul 2007 17:20:58 -0000	1.1
+++ compact_forms.js	16 Mar 2009 23:17:54 -0000
@@ -1,61 +1,72 @@
-/* $Id: compact_forms.js,v 1.1 2007/07/29 17:20:58 tomsun Exp $
+// $Id: compact_forms.js,v 1.1 2007/07/29 17:20:58 tomsun Exp $
 
-    Compact Forms jQuery plugin
-    Copyright 2007 Tom Sundstršm
+(function($) {
 
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License version 2 as
-    published by the Free Software Foundation.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public
-    License along with this program; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
-
-
-(function($){
-  $.fn.compactForm = function(stars, colons) {
-    var stars = stars || 0;
-    var colons = colons || 0;
-    this.each(function(index) {
-      $(this).find("label").each(function() {
-        var label = $(this);
-        var field = $("#" + label.attr("for"));
-        if (field.attr("type") != "text" && field.attr("type") != "password") {
-          return;
-        }
-
-        if($(field).val() != "") {
-            $(label).fadeOut(1);
-        }
+Drupal.behaviors = Drupal.behaviors || {}; // D5 only.
 
-        $(label).parent().addClass("compact-form-wrapper");
-        label.addClass("compact-form-label");
-        field.addClass("compact-form-field");
-
-        if (stars === 0) {
-          $(label).find(".form-required").hide();
-        } else if (stars === 2) {
-          $(label).find(".form-required").insertAfter(field).prepend("&nbsp;");
+/**
+ * Compact Forms jQuery plugin.
+ */
+$.fn.compactForm = function (stars, colons) {
+  var stars = stars || 0;
+  var colons = colons || 0;
+
+  this.each(function (index) {
+    $(this).find("label").each(function () {
+      var label = $(this);
+      var field = $("#" + label.attr("for"));
+      if (field.attr("type") != "text" && field.attr("type") != "password") {
+        return;
+      }
+
+      if ($(field).val() != "") {
+        $(label).fadeOut(1);
+      }
+
+      $(label).parent().addClass("compact-form-wrapper");
+      label.addClass("compact-form-label");
+      field.addClass("compact-form-field");
+
+      if (stars === 0) {
+        $(label).find(".form-required").hide();
+      }
+      else if (stars === 2) {
+        $(label).find(".form-required").insertAfter(field).prepend("&nbsp;");
+      }
+
+      if (colons === 0) {
+        var lbl = $(label).html();
+        lbl = lbl.replace(/:/," ");
+        $(label).html(lbl);
+      }
+
+      $(field).focus(function () {
+        if($(this).val() === "") {
+          $(label).fadeOut("fast");
         }
+      });
 
-        if (colons === 0) {
-          var lbl = $(label).html();
-          lbl = lbl.replace(/:/," ");
-          $(label).html(lbl);
+      $(field).blur(function () {
+        if($(this).val() === "") {
+          $(label).fadeIn("slow");
         }
-
-        $(field).focus(function() {
-          if($(this).val() === "") {            $(label).fadeOut("fast");          }        });
-
-        $(field).blur(function() {
-          if($(this).val() === "") {            $(label).fadeIn("slow");          }        });
       });
     });
+  });
+}
+
+Drupal.behaviors.compactForms = function (context) {
+  if (!Drupal.settings || !Drupal.settings.compactForms) {
+    return;
   }
+  $.each(Drupal.settings.compactForms.forms, function () {
+    $('#' + this, context).compactForm(Drupal.settings.compactForms.stars, Drupal.settings.compactForms.colons);
+  });
+}
+
+// D5 only.
+$(document).ready(function () {
+  Drupal.behaviors.compactForms(document);
+});
+
 })(jQuery);
Index: compact_forms.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/compact_forms/compact_forms.module,v
retrieving revision 1.1
diff -u -p -r1.1 compact_forms.module
--- compact_forms.module	29 Jul 2007 17:20:58 -0000	1.1
+++ compact_forms.module	16 Mar 2009 23:23:30 -0000
@@ -1,199 +1,126 @@
-<?php // $Id: compact_forms.module,v 1.1 2007/07/29 17:20:58 tomsun Exp $
-/*
-    Compact Forms Drupal module
-    Copyright 2007 Tom SundstrÃ¶m
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License version 2 as
-    published by the Free Software Foundation.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public
-    License along with this program; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
-
-
-/**
- * Implementation of hook_help().
- */
-function compact_forms_help($section) {
-  switch ($section) {
-    case 'admin/help#help':
-      // TODO: expand
-      $output = '<p>'. t('Makes form fields compact by overlaying the field label on top the field itself using jQuery.') . '</p>';
-      return $output;
-  }
-}
-
-
-/**
- * Implementation of hook_perm().
- */
-function compact_forms_perm() {
-  return array(
-    'administer Compact Forms',
-  );
-}
-
-
-/**
- * Implementation of hook_form_alter().
- */
-function compact_forms_form_alter($form_id, &$form) {
-  $field_size = variable_get('compact_forms_field_size', '');
-  $descriptions = variable_get('compact_forms_descriptions', 1);
-  if (empty($field_size) && !empty($descriptions)) {
-    // Nothing to alter.
-    return;
-  }
-
-  static $ids = NULL;
-  if ($ids === NULL) {
-    $ids = explode("\n", str_replace('-', '_', variable_get('compact_forms_ids', "user-login-form")));
-  }
-  if (in_array($form_id, $ids)) {
-    _compact_forms_resize_fields($form, $field_size, $descriptions);
-  }
-}
-
-
-/**
- * Iterator.
- */
-function _compact_forms_resize_fields(&$subform, $field_size, $descriptions) {
-  if (is_array($subform) && !empty($subform)) {
-    foreach($subform as $key => $field) {
-      switch($field['#type']) {
-
-        case 'fieldset':
-          _compact_forms_resize_fields($subform[$key], $field_size);
-          break;
-        
-        case 'textfield':
-        case 'password':
-        case 'password_confirm':
-          if (!empty($field_size)) {
-            $subform[$key]['#size'] = $field_size; 
-          }
-          if (empty($descriptions)) {
-            unset($subform[$key]['#description']);
-          }
-          break;
-      }
-    }  
-  }
-}
-
-/**
- * Implementation of hook_menu().
- */
-function compact_forms_menu($may_cache) {
-  global $user;
-  $items = array();
-
-  if (!$may_cache) {
-    
-    _compact_forms_include_js();
-
-    $items[] = array(
-      'title' => t('Compact Forms'),
-      'path' => 'admin/settings/compact_forms',
-      'description' => t('Makes form fields compact by overlaying the field label on top the field itself using jQuery.'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => 'compact_forms_admin_form',
-      'access' => user_access('administer Compact Forms'),
-    );
-  }
-
-  return $items;
-}
-
-
-/**
- * Compact Forms admin settings.
- */
-function compact_forms_admin_form() {
-
-  $form['compact_forms_ids'] = array(
-    '#type' => 'textarea',
-    '#title' => t('Form ID:s'),
-    '#rows' => 3,
-    '#cols' => 40,
-    '#default_value' => variable_get('compact_forms_ids', "user-login-form"),
-    '#description' => 'Enter the CSS #id of the forms that you want to activate compact_forms for. One per line.',
-  );
-  
-  $form['compact_forms_stars'] = array(
-    '#title' => t('"Required field" - stars'),
-    '#type' => 'radios',
-    '#options' => array(
-      0 => t('Remove "required" stars'),
-      1 => t('Leave "required" stars attached to label'),
-      2 => t('Insert "required" stars after the field'),
-    ),
-    '#default_value' => variable_get('compact_forms_stars', 2),
-    '#description' => t('How to deal with the stars added by Drupal to indicate required fields.'),
-  );
-  
-  $form['compact_forms_colons'] = array(
-    '#title' => t('Trailing colons in labels'),
-    '#type' => 'radios',
-     '#options' => array(
-      0 => t('Remove trailing colons from the label'),
-      1 => t('Keep trailing colons'),
-    ),
-    '#default_value' => variable_get('compact_forms_colons', 0),
-  );
-
-  $form['compact_forms_field_size'] = array(
-    '#title' => t('Textfield size'),
-    '#type' => 'textfield',
-    '#size' => 3,
-    '#default_value' => variable_get('compact_forms_field_size', ''),
-    '#description' => t('Optionally override the width of all text fields in the selected forms'),
-  );
-  $form['compact_forms_descriptions'] = array(
-    '#title' => t('Textfield descriptions'),
-    '#type' => 'radios',
-    '#options' => array(
-      0 => t('Hide descriptions'),
-      1 => t('Show descriptions'),
-    ),
-    '#default_value' => variable_get('compact_forms_descriptions', 1),
-    '#description' => t('Optionally hide descriptions of all textfields (in general not recommended).'),
-  );
-  
-  return system_settings_form($form);
-}
-
-
-/**
- * Include JavaScript and CSS and attach behaviours to all selected forms.
- */
-function _compact_forms_include_js() {
-    $ids = explode("\n", variable_get('compact_forms_ids', "user-login-form"));
-    $inline_js = '';
-    
-    if (is_array($ids) && !empty($ids)) {
-      $stars = variable_get('compact_forms_stars', 2);
-      $colons = variable_get('compact_forms_colons', 0);
-      
-      foreach ($ids as $id) {
-        $id = trim($id);
-        if (!empty($id)) {
-         
-          $inline_js .= '$("#' . $id. '").compactForm(' . $stars . ', ' . $colons . ');';
-        }
-      }
-    }
-    if (!empty($inline_js)) {
-      drupal_add_js(drupal_get_path('module', 'compact_forms') . '/compact_forms.js');
-      drupal_add_css(drupal_get_path('module', 'compact_forms') . '/compact_forms.css');
-      drupal_add_js('$(document).ready(function() {'. $inline_js . '});', 'inline');      
-    }
-}
+<?php
+// $Id: compact_forms.module,v 1.1 2007/07/29 17:20:58 tomsun Exp $
+
+/**
+ * @file
+ * Compact Forms Drupal module.
+ */
+
+/**
+ * Implementation of hook_help().
+ */
+function compact_forms_help($section) {
+  switch ($section) {
+    case 'admin/help#help':
+      return '<p>' . t('Makes form fields compact by overlaying the field label on top the field itself using jQuery.') . '</p>';
+  }
+}
+
+/**
+ * Implementation of hook_perm().
+ */
+function compact_forms_perm() {
+  return array('administer Compact Forms');
+}
+
+/**
+ * Implementation of hook_form_alter().
+ */
+function compact_forms_form_alter($form_id, &$form) {
+  static $ids;
+
+  $field_size = variable_get('compact_forms_field_size', '');
+  $descriptions = variable_get('compact_forms_descriptions', 1);
+  if (empty($field_size) && !empty($descriptions)) {
+    // Nothing to alter.
+    return;
+  }
+
+  if (!isset($ids)) {
+    $ids = explode("\n", str_replace('-', '_', variable_get('compact_forms_ids', "user-login-form")));
+  }
+  if (in_array($form_id, $ids)) {
+    _compact_forms_resize_fields($form, $field_size, $descriptions);
+  }
+}
+
+/**
+ * Iterator.
+ */
+function _compact_forms_resize_fields(&$form, $field_size, $descriptions) {
+  if (empty($form) || !is_array($form)) {
+    return;
+  }
+  foreach (element_children($form) as $key) {
+    if (!isset($form[$key]['#type'])) {
+      continue;
+    }
+    switch ($form[$key]['#type']) {
+      case 'fieldset':
+        _compact_forms_resize_fields($form[$key], $field_size, $descriptions);
+        break;
+
+      case 'textfield':
+      case 'password':
+      case 'password_confirm':
+        if (!empty($field_size)) {
+          $form[$key]['#size'] = $field_size;
+        }
+        if (!$descriptions) {
+          unset($form[$key]['#description']);
+        }
+        break;
+    }
+  }
+}
+
+/**
+ * Implementation of hook_menu().
+ */
+function compact_forms_menu($may_cache) {
+  global $user;
+
+  $items = array();
+  if ($may_cache) {
+    $items[] = array(
+      'title' => t('Compact Forms'),
+      'path' => 'admin/settings/compact_forms',
+      'description' => t('Makes form fields compact by overlaying the field label on top the field itself using jQuery.'),
+      'callback' => 'drupal_get_form',
+      'callback arguments' => 'compact_forms_admin_form',
+      'access' => user_access('administer Compact Forms'),
+    );
+  }
+  else {
+    if (strpos($_GET['q'], 'admin/settings/compact_forms') === 0) {
+      require_once drupal_get_path('module', 'compact_forms') . '/compact_forms.admin.inc';
+    }
+    // Load our behavior.
+    _compact_forms_include_js();
+  }
+  return $items;
+}
+
+/**
+ * Include JavaScript and CSS and attach behaviors to all selected forms.
+ */
+function _compact_forms_include_js() {
+  $ids = explode("\n", variable_get('compact_forms_ids', 'user-login-form'));
+  $ids = array_filter(array_map('trim', $ids));
+
+  if (!empty($ids)) {
+    $path = drupal_get_path('module', 'compact_forms');
+    drupal_add_js($path . '/compact_forms.js');
+    drupal_add_css($path . '/compact_forms.css');
+
+    $settings = array(
+      'compactForms' => array(
+        'forms' => $ids,
+        'stars' => (int) variable_get('compact_forms_stars', 2),
+        'colons' => (int) variable_get('compact_forms_colons', 0),
+      ),
+    );
+    drupal_add_js($settings, 'setting');
+  }
+}
+
