Index: compact_forms.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/compact_forms/compact_forms.admin.inc,v
retrieving revision 1.1
diff -u -p -r1.1 compact_forms.admin.inc
--- compact_forms.admin.inc	1 May 2009 23:10:11 -0000	1.1
+++ compact_forms.admin.inc	3 May 2009 12:07:37 -0000
@@ -10,15 +10,15 @@
  * Form builder function for Compact Forms settings.
  */
 function compact_forms_admin_form() {
-  $form['compact_forms_ids'] = array(
+  $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'),
+    '#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(
+  $form[COMPACT_FORMS_STARS] = array(
     '#title' => t('"Required field" - stars'),
     '#type' => 'radios',
     '#options' => array(
@@ -26,33 +26,33 @@ function compact_forms_admin_form() {
       1 => t('Leave "required" stars attached to label'),
       2 => t('Insert "required" stars after the field'),
     ),
-    '#default_value' => variable_get('compact_forms_stars', 2),
+    '#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(
+  $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),
+    '#default_value' => variable_get(COMPACT_FORMS_COLONS, 0),
   );
-  $form['compact_forms_field_size'] = array(
+  $form[COMPACT_FORMS_FIELD_SIZE] = array(
     '#title' => t('Textfield size'),
     '#type' => 'textfield',
     '#size' => 3,
-    '#default_value' => variable_get('compact_forms_field_size', ''),
+    '#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(
+  $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),
+    '#default_value' => variable_get(COMPACT_FORMS_DESCRIPTIONS, 1),
     '#description' => t('Optionally hide descriptions of all textfields (in general not recommended).'),
   );
 
Index: compact_forms.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/compact_forms/compact_forms.js,v
retrieving revision 1.2
diff -u -p -r1.2 compact_forms.js
--- compact_forms.js	1 May 2009 23:10:11 -0000	1.2
+++ compact_forms.js	3 May 2009 12:07:37 -0000
@@ -2,8 +2,6 @@
 
 (function ($) {
 
-Drupal.behaviors = Drupal.behaviors || {}; // D5 only.
-
 /**
  * Compact Forms jQuery plugin.
  */
@@ -64,9 +62,4 @@ Drupal.behaviors.compactForms = function
   });
 }
 
-// D5 only.
-$(document).ready(function () {
-  Drupal.behaviors.compactForms(this);
-});
-
 })(jQuery);
Index: compact_forms.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/compact_forms/compact_forms.module,v
retrieving revision 1.4
diff -u -p -r1.4 compact_forms.module
--- compact_forms.module	2 May 2009 00:39:31 -0000	1.4
+++ compact_forms.module	3 May 2009 12:07:37 -0000
@@ -1,6 +1,12 @@
 <?php
 // $Id: compact_forms.module,v 1.4 2009/05/02 00:39:31 sun Exp $
 
+define('COMPACT_FORMS_IDS',          'compact_forms_ids');
+define('COMPACT_FORMS_STARS',        'compact_forms_stars');
+define('COMPACT_FORMS_COLONS',       'compact_forms_colons');
+define('COMPACT_FORMS_FIELD_SIZE',   'compact_forms_field_size');
+define('COMPACT_FORMS_DESCRIPTIONS', 'compact_forms_descriptions');
+
 /**
  * @file
  * Compact Forms Drupal module.
@@ -28,46 +34,61 @@ function compact_forms_perm() {
  */
 function compact_forms_menu() {
   $items['admin/settings/compact_forms'] = array(
-    'title' => 'Compact Forms',
-    'description' => 'Configure Compact Forms settings.',
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('compact_forms_admin_form'),
+    'title'            => 'Compact Forms',
+    'description'      => 'Configure Compact Forms settings.',
+    'page callback'    => 'drupal_get_form',
+    'page arguments'   => array('compact_forms_admin_form'),
     'access arguments' => array('administer Compact Forms'),
-    'file' => 'compact_forms.admin.inc',
+    'file'             => 'compact_forms.admin.inc',
   );
   return $items;
 }
 
 /**
- * Implementation of hook_init().
- */
-function compact_forms_init() {
-  // Load our behavior.
-  _compact_forms_include_js();
-}
-
-/**
- * Implementation of hook_form_alter().
- */
+  * Implementation of hook_form_alter().
+  */
 function compact_forms_form_alter(&$form, $form_state, $form_id) {
-  static $ids;
+  static $loaded = FALSE;
 
-  $field_size = variable_get('compact_forms_field_size', '');
-  $descriptions = variable_get('compact_forms_descriptions', 1);
-  // Nothing to do if no custom field size was configured and form element
-  // descriptions shall not be hidden.
-  if (empty($field_size) && !empty($descriptions)) {
-    return;
+  static $css_ids, $form_ids;
+  static $field_size, $descriptions;
+
+  // Prepare CSS form ids.
+  if (!isset($css_ids)) {
+    $css_ids = explode("\n", variable_get(COMPACT_FORMS_IDS, 'user-login'));
+    $css_ids = array_filter(array_map('trim', $css_ids));
   }
 
-  if (!isset($ids)) {
-    $ids = explode("\n", str_replace('-', '_', variable_get('compact_forms_ids', "user-login-form")));
+  // Prepare Form API form ids.
+  if (!isset($form_ids) && !empty($css_ids)) {
+    $form_ids = array();
+
+    foreach ($css_ids as $id) {
+      $id = strtr($id, array('-' => '_'));
+      // Performance patch, work on array keys
+      $form_ids[$id] = TRUE; 
+    }
   }
-  if (in_array($form_id, $ids)) {
+
+  // Prepare form alteration settings.
+  if (!isset($field_size)) {
+    $field_size   = variable_get(COMPACT_FORMS_FIELD_SIZE, '');
+    $descriptions = variable_get(COMPACT_FORMS_DESCRIPTIONS, 1);
+  }
+
+  if (array_key_exists($form_id, $form_ids)) {
+    // Load our page requisites and JavaScript settings.
+    if (! $loaded) {
+      _compact_forms_include_js($css_ids);
+      $loaded = TRUE;
+    }
+
+    // '0' options exists, so test here was wrong
     _compact_forms_resize_fields($form, $field_size, $descriptions);
   }
 }
 
+
 /**
  * Iterator.
  */
@@ -101,23 +122,20 @@ function _compact_forms_resize_fields(&$
 /**
  * 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');
-  }
+function _compact_forms_include_js($css_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'  => $css_ids,
+      'stars'  => (int) variable_get(COMPACT_FORMS_STARS, 2),
+      'colons' => (int) variable_get(COMPACT_FORMS_COLONS, 0),
+    ),
+  );
+
+  drupal_add_js($settings, 'setting');
 }
 
