summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwebchick <webchick@24967.no-reply.drupal.org>2011-06-29 22:40:21 -0700
committerwebchick <webchick@24967.no-reply.drupal.org>2011-06-29 22:40:21 -0700
commit33f6c5608c62b27fa86d52e8806435a6c94f3eee (patch)
tree093b712306c925fa6956b069fb64b82b4b03573b
parent8b913661cd4567583f514d8bc87ba220e7e05de2 (diff)
downloadbrdo-33f6c5608c62b27fa86d52e8806435a6c94f3eee.tar.gz
brdo-33f6c5608c62b27fa86d52e8806435a6c94f3eee.tar.bz2
Issue #634616 by effulgentsia, rfay, sun: Fixed Various problems due to AJAX binding to mousedown instead of click.
-rw-r--r--includes/ajax.inc21
-rw-r--r--misc/ajax.js9
2 files changed, 24 insertions, 6 deletions
diff --git a/includes/ajax.inc b/includes/ajax.inc
index 41c69832a..6111d3784 100644
--- a/includes/ajax.inc
+++ b/includes/ajax.inc
@@ -619,13 +619,24 @@ function ajax_pre_render_element($element) {
case 'submit':
case 'button':
case 'image_button':
- // Use the mousedown instead of the click event because form
- // submission via pressing the enter key triggers a click event on
- // submit inputs, inappropriately triggering Ajax behaviors.
+ // Pressing the ENTER key within a textfield triggers the click event of
+ // the form's first submit button. Triggering Ajax in this situation
+ // leads to problems, like breaking autocomplete textfields, so we bind
+ // to mousedown instead of click.
+ // @see http://drupal.org/node/216059
$element['#ajax']['event'] = 'mousedown';
- // Attach an additional event handler so that Ajax behaviors
- // can be triggered still via keyboard input.
+ // Retain keyboard accessibility by setting 'keypress'. This causes
+ // ajax.js to trigger 'event' when SPACE or ENTER are pressed while the
+ // button has focus.
$element['#ajax']['keypress'] = TRUE;
+ // Binding to mousedown rather than click means that it is possible to
+ // trigger a click by pressing the mouse, holding the mouse button down
+ // until the Ajax request is complete and the button is re-enabled, and
+ // then releasing the mouse button. Set 'prevent' so that ajax.js binds
+ // an additional handler to prevent such a click from triggering a
+ // non-Ajax form submission. This also prevents a textfield's ENTER
+ // press triggering this button's non-Ajax form submission behavior.
+ $element['#ajax']['prevent'] = 'click';
break;
case 'password':
diff --git a/misc/ajax.js b/misc/ajax.js
index fb03e2b30..830c8aa1c 100644
--- a/misc/ajax.js
+++ b/misc/ajax.js
@@ -182,10 +182,17 @@ Drupal.ajax = function (base, element, element_settings) {
// can be triggered through keyboard input as well as e.g. a mousedown
// action.
if (element_settings.keypress) {
- $(element_settings.element).keypress(function (event) {
+ $(ajax.element).keypress(function (event) {
return ajax.keypressResponse(this, event);
});
}
+
+ // If necessary, prevent the browser default action of an additional event.
+ // For example, prevent the browser default action of a click, even if the
+ // AJAX behavior binds to mousedown.
+ if (element_settings.prevent) {
+ $(ajax.element).bind(element_settings.prevent, false);
+ }
};
/**