From 2ceae6ad581701a0ee72eede787583e9140a5eda Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Wed, 4 Jul 2007 15:42:38 +0000 Subject: - 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). --- includes/form.inc | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'includes/form.inc') diff --git a/includes/form.inc b/includes/form.inc index 608fe755e..f135e685b 100644 --- a/includes/form.inc +++ b/includes/form.inc @@ -1382,6 +1382,48 @@ function expand_radios($element) { return $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. * -- cgit v1.2.3