Index: includes/form.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/form.inc,v retrieving revision 1.277 diff -u -p -r1.277 form.inc --- includes/form.inc 18 Jul 2008 07:06:24 -0000 1.277 +++ includes/form.inc 19 Jul 2008 07:20:32 -0000 @@ -1519,6 +1519,7 @@ function theme_radio($element) { _form_set_class($element, array('form-radio')); $output = ''; @@ -1735,6 +1736,9 @@ function form_process_radios($element) { '#parents' => $element['#parents'], '#id' => form_clean_id('edit-' . implode('-', $parents_for_id)), ); + if (isset($element['#js'])) { + $element[$key]['#js'] = $element['#js']; + } } } } @@ -1825,6 +1829,34 @@ function form_process_ahah($element) { } /** + * Automatically attach javascript form behaviors to a form element. This is + * especially convenient for small amounts of javascript for which creating a + * file to contain the javascript for seems tedious and/or boring. + * + * @param $element + * An associative array containing the properties of the element. + * Properties used: js => array(event => code, event2 => code2). + * The fake event 'run' may be used to simply run code without waiting for an + * event to occur. + * @return + * None. Additional code is added to the header of the page using + * drupal_add_js. + */ +function form_process_autojs($element) { + static $added = FALSE; + static $i = 0; + $js = isset($element['#js']) ? $element['#js'] : array(); + foreach ($js as $event => $code) { + if (!$added) { + drupal_add_js('misc/form.js'); + $added = TRUE; + } + drupal_add_js(array('formAutoJS' => array($i => array('selector' => '#' . $element['#id'], 'event' => $event, 'code' => $code))), 'setting'); + } + return $element; +} + +/** * Format a form item. * * @param $element @@ -1903,6 +1935,9 @@ function form_process_checkboxes($elemen foreach ($element['#options'] as $key => $choice) { if (!isset($element[$key])) { $element[$key] = array('#type' => 'checkbox', '#processed' => TRUE, '#title' => $choice, '#return_value' => $key, '#default_value' => isset($value[$key]), '#attributes' => $element['#attributes']); + if (isset($element['#js'])) { + $element[$key]['#js'] = $element['#js']; + } } } } Index: misc/form.js =================================================================== RCS file: /cvs/drupal/drupal/misc/form.js,v retrieving revision 1.1 diff -u -p -r1.1 form.js --- misc/form.js 12 Sep 2007 18:29:32 -0000 1.1 +++ misc/form.js 19 Jul 2008 06:35:45 -0000 @@ -8,3 +8,16 @@ Drupal.behaviors.multiselectSelector = f .attr('checked', true); }); }; + +Drupal.behaviors.formAutoJS = function(context) { + for (var key in Drupal.settings.formAutoJS) { + if (Drupal.settings.formAutoJS[key].event != 'run') { + $(Drupal.settings.formAutoJS[key].selector).bind(Drupal.settings.formAutoJS[key].event, function() { + return eval(Drupal.settings.formAutoJS[key].code); + }); + } + else { + return eval(Drupal.settings.formAutoJS[key].code); + } + } +}; \ No newline at end of file Index: modules/profile/profile.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/profile/profile.admin.inc,v retrieving revision 1.11 diff -u -p -r1.11 profile.admin.inc --- modules/profile/profile.admin.inc 16 Jul 2008 21:59:27 -0000 1.11 +++ modules/profile/profile.admin.inc 19 Jul 2008 07:25:07 -0000 @@ -246,6 +246,14 @@ Unless you know what you are doing, it i '#title' => t('Visibility'), '#default_value' => isset($edit['visibility']) ? $edit['visibility'] : PROFILE_PUBLIC, '#options' => array(PROFILE_HIDDEN => t('Hidden profile field, only accessible by administrators, modules and themes.'), PROFILE_PRIVATE => t('Private field, content only available to privileged users.'), PROFILE_PUBLIC => t('Public field, content shown on profile page but not used on member list pages.'), PROFILE_PUBLIC_LISTINGS => t('Public field, content shown on profile page and on member list pages.')), + '#js' => array( + 'change' => 'if ($(this).val() == ' . PROFILE_PUBLIC . ' || $(this).val() == ' . PROFILE_PUBLIC_LISTINGS . ") { + $('#edit-page').removeAttr('disabled'); + } + else { + $('#edit-page').attr('disabled', 'disabled'); + }", + ), ); if ($type == 'selection' || $type == 'list' || $type == 'textfield') { $form['fields']['page'] = array('#type' => 'textfield', Index: modules/system/system.module =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.module,v retrieving revision 1.610 diff -u -p -r1.610 system.module --- modules/system/system.module 18 Jul 2008 07:06:24 -0000 1.610 +++ modules/system/system.module 19 Jul 2008 07:18:35 -0000 @@ -189,7 +189,7 @@ function system_elements() { '#name' => 'op', '#button_type' => 'submit', '#executes_submit_callback' => TRUE, - '#process' => array('form_process_ahah'), + '#process' => array('form_process_ahah', 'form_process_autojs'), ); $type['button'] = array( @@ -197,14 +197,14 @@ function system_elements() { '#name' => 'op', '#button_type' => 'submit', '#executes_submit_callback' => FALSE, - '#process' => array('form_process_ahah'), + '#process' => array('form_process_ahah', 'form_process_autojs'), ); $type['image_button'] = array( '#input' => TRUE, '#button_type' => 'submit', '#executes_submit_callback' => TRUE, - '#process' => array('form_process_ahah'), + '#process' => array('form_process_ahah', 'form_process_autojs'), '#return_value' => TRUE, '#has_garbage_value' => TRUE, '#src' => NULL, @@ -215,19 +215,19 @@ function system_elements() { '#size' => 60, '#maxlength' => 128, '#autocomplete_path' => FALSE, - '#process' => array('form_process_ahah'), + '#process' => array('form_process_ahah', 'form_process_autojs'), ); $type['password'] = array( '#input' => TRUE, '#size' => 60, '#maxlength' => 128, - '#process' => array('form_process_ahah'), + '#process' => array('form_process_ahah', 'form_process_autojs'), ); $type['password_confirm'] = array( '#input' => TRUE, - '#process' => array('form_process_password_confirm'), + '#process' => array('form_process_password_confirm', 'form_process_autojs'), ); $type['textarea'] = array( @@ -235,7 +235,7 @@ function system_elements() { '#cols' => 60, '#rows' => 5, '#resizable' => TRUE, - '#process' => array('form_process_ahah'), + '#process' => array('form_process_ahah', 'form_process_autojs'), ); $type['radios'] = array( @@ -246,7 +246,7 @@ function system_elements() { $type['radio'] = array( '#input' => TRUE, '#default_value' => NULL, - '#process' => array('form_process_ahah'), + '#process' => array('form_process_ahah', 'form_process_autojs'), ); $type['checkboxes'] = array( @@ -258,21 +258,21 @@ function system_elements() { $type['checkbox'] = array( '#input' => TRUE, '#return_value' => 1, - '#process' => array('form_process_ahah'), + '#process' => array('form_process_ahah', 'form_process_autojs'), ); $type['select'] = array( '#input' => TRUE, '#size' => 0, '#multiple' => FALSE, - '#process' => array('form_process_ahah'), + '#process' => array('form_process_ahah', 'form_process_autojs'), ); $type['weight'] = array( '#input' => TRUE, '#delta' => 10, '#default_value' => 0, - '#process' => array('form_process_weight', 'form_process_ahah'), + '#process' => array('form_process_weight', 'form_process_ahah', 'form_process_autojs'), ); $type['date'] = array( @@ -296,7 +296,7 @@ function system_elements() { $type['hidden'] = array( '#input' => TRUE, - '#process' => array('form_process_ahah'), + '#process' => array('form_process_ahah', 'form_process_autojs'), ); $type['value'] = array( @@ -312,7 +312,7 @@ function system_elements() { '#collapsible' => FALSE, '#collapsed' => FALSE, '#value' => NULL, - '#process' => array('form_process_ahah'), + '#process' => array('form_process_ahah', 'form_process_autojs'), ); $type['token'] = array( Index: modules/user/user.module =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.module,v retrieving revision 1.912 diff -u -p -r1.912 user.module --- modules/user/user.module 16 Jul 2008 21:59:29 -0000 1.912 +++ modules/user/user.module 19 Jul 2008 06:39:47 -0000 @@ -1494,7 +1494,14 @@ function user_edit_form(&$form_state, $u $picture = theme('user_picture', (object)$edit); if ($edit['picture']) { $form['picture']['current_picture'] = array('#markup' => $picture); - $form['picture']['picture_delete'] = array('#type' => 'checkbox', '#title' => t('Delete picture'), '#description' => t('Check this box to delete your current picture.')); + $form['picture']['picture_delete'] = array( + '#type' => 'checkbox', + '#title' => t('Delete picture'), + '#description' => t('Check this box to delete your current picture.'), + '#js' => array( + 'change' => "$(this).parents('fieldset').find('div.picture').slideToggle();", + ), + ); } else { $form['picture']['picture_delete'] = array('#type' => 'hidden');