Commit 1cf5ba30 authored by webchick's avatar webchick

#939568 by merlinofchaos, sun: Enable finer control for ajax-using modules of...

#939568 by merlinofchaos, sun: Enable finer control for ajax-using modules of the trigger response in the ajax object.
parent da957d5c
...@@ -114,6 +114,7 @@ Drupal.ajax = function (base, element, element_settings) { ...@@ -114,6 +114,7 @@ Drupal.ajax = function (base, element, element_settings) {
$.extend(this, defaults, element_settings); $.extend(this, defaults, element_settings);
this.element = element; this.element = element;
this.element_settings = element_settings;
// Replacing 'nojs' with 'ajax' in the URL allows for an easy method to let // Replacing 'nojs' with 'ajax' in the URL allows for an easy method to let
// the server detect when it needs to degrade gracefully. // the server detect when it needs to degrade gracefully.
...@@ -171,7 +172,51 @@ Drupal.ajax = function (base, element, element_settings) { ...@@ -171,7 +172,51 @@ Drupal.ajax = function (base, element, element_settings) {
}; };
// Bind the ajaxSubmit function to the element event. // Bind the ajaxSubmit function to the element event.
$(this.element).bind(element_settings.event, function () { $(ajax.element).bind(element_settings.event, function (event) {
return ajax.eventResponse(this, event);
});
// If necessary, enable keyboard submission so that AJAX behaviors
// can be triggered through keyboard input as well as e.g. a mousedown
// action.
if (element_settings.keypress) {
$(element_settings.element).keypress(function (event) {
return ajax.keypressResponse(this, event);
});
}
};
/**
* Handle a key press.
*
* The AJAX object will, if instructed, bind to a key press response. This
* will test to see if the key press is valid to trigger this event and
* if it is, trigger it for us and prevent other keypresses from triggering.
*/
Drupal.ajax.prototype.keypressResponse = function (element, event) {
// Create a synonym for this to reduce code confusion.
var ajax = this;
// Detect enter key and space bar.
if (event.which == 13 || event.which == 32) {
$(ajax.element_settings.element).trigger(ajax.element_settings.event);
return false;
}
};
/**
* Handle an event that triggers an AJAX response.
*
* When an event that triggers an AJAX response happens, this method will
* perform the actual AJAX call. It is bound to the event using
* bind() in the constructor, and it uses the options specified on the
* ajax object.
*/
Drupal.ajax.prototype.eventResponse = function (element, event) {
// Create a synonym for this to reduce code confusion.
var ajax = this;
// Do not perform another ajax command if one is already in progress.
if (ajax.ajaxing) { if (ajax.ajaxing) {
return false; return false;
} }
...@@ -185,7 +230,7 @@ Drupal.ajax = function (base, element, element_settings) { ...@@ -185,7 +230,7 @@ Drupal.ajax = function (base, element, element_settings) {
// ajaxSubmit that tells the system which element got clicked to // ajaxSubmit that tells the system which element got clicked to
// trigger the submit. Without it there would be no 'op' or // trigger the submit. Without it there would be no 'op' or
// equivalent. // equivalent.
this.form.clk = this; element.form.clk = element;
} }
ajax.form.ajaxSubmit(ajax.options); ajax.form.ajaxSubmit(ajax.options);
...@@ -196,24 +241,13 @@ Drupal.ajax = function (base, element, element_settings) { ...@@ -196,24 +241,13 @@ Drupal.ajax = function (base, element, element_settings) {
} }
} }
catch (e) { catch (e) {
// Unset the ajax.ajaxing flag here because it won't be unset during
// the complete response.
ajax.ajaxing = false;
alert("An error occurred while attempting to process " + ajax.options.url + ": " + e.message); alert("An error occurred while attempting to process " + ajax.options.url + ": " + e.message);
} }
return false; return false;
});
// If necessary, enable keyboard submission so that AJAX behaviors
// can be triggered through keyboard input as well as e.g. a mousedown
// action.
if (element_settings.keypress) {
$(element_settings.element).keypress(function (event) {
// Detect enter key and space bar.
if (event.which == 13 || event.which == 32) {
$(element_settings.element).trigger(element_settings.event);
return false;
}
});
}
}; };
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment