summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwebchick2011-06-30 05:40:14 (GMT)
committerwebchick2011-06-30 05:40:14 (GMT)
commit9c832e4ced84f6f15099abe69bd662f8e8d91f72 (patch)
tree5aa197c5abdfa6c10ddef4b1f6912e5e665f01f7
parentc53064313389f2e61a529718ef82ce632b3f69af (diff)
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 ac1bd4c..8905687 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 fb03e2b..830c8aa 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);
+ }
};
/**