diff options
author | Dries Buytaert <dries@buytaert.net> | 2007-07-04 15:42:38 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2007-07-04 15:42:38 +0000 |
commit | 2ceae6ad581701a0ee72eede787583e9140a5eda (patch) | |
tree | c5e2a20a20ad3385868ff44415e92ceb877c7cc5 /includes/form.inc | |
parent | 4b3efeffca3c8743ad175eea3171bfd0346e4b70 (diff) | |
download | brdo-2ceae6ad581701a0ee72eede787583e9140a5eda.tar.gz brdo-2ceae6ad581701a0ee72eede787583e9140a5eda.tar.bz2 |
- Patch #154398 by quicksketch et al: add dynamic AHAH submission properties to Forms API. This patch was ready for a long time and is somewhat of a usability improvement (enabler).
Diffstat (limited to 'includes/form.inc')
-rw-r--r-- | includes/form.inc | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/includes/form.inc b/includes/form.inc index 608fe755e..f135e685b 100644 --- a/includes/form.inc +++ b/includes/form.inc @@ -1383,6 +1383,48 @@ function expand_radios($element) { } /** + * Add AHAH information about a form element to the page to communicate with + * javascript. If #ahah_path is set on an element, this additional javascript is + * added to the page header to attach the AHAH behaviors. See ahah.js for more + * information. + * + * @param $element + * An associative array containing the properties of the element. + * Properties used: ahah_event, ahah_path, ahah_wrapper, ahah_parameters, + * ahah_effect. + * @return + * None. Additional code is added to the header of the page using + * drupal_add_js. + */ +function form_expand_ahah($element) { + static $js_added = array(); + + // Adding the same javascript settings twice will cause a recursion error, + // we avoid the problem by checking if the javascript has already been added. + if (!isset($js_added[$element['#id']]) && isset($element['#ahah_event']) && isset($element['#ahah_path'])) { + drupal_add_js('misc/ahah.js'); + drupal_add_js('misc/progress.js'); + + $ahah_binding = array( + 'id' => $element['#id'], + 'uri' => url($element['#ahah_path']), + 'event' => $element['#ahah_event'], + 'effect' => empty($element['#ahah_effect']) ? 'none' : $element['#ahah_effect'], + 'method' => empty($element['#ahah_method']) ? 'replace' : $element['#ahah_method'], + ); + + if (!empty($element['#ahah_wrapper'])) { + $ahah_binding['wrapper'] = $element['#ahah_wrapper']; + } + + drupal_add_js(array('ahah' => array($element['#id'] => $ahah_binding)), 'setting'); + + $js_added[$element['#id']] = TRUE; + } + return $element; +} + +/** * Format a form item. * * @param $element |