summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-06-25 20:34:07 +0000
committerDries Buytaert <dries@buytaert.net>2010-06-25 20:34:07 +0000
commit8b0fda82cc390388e753c78b68a46fd1290a497c (patch)
treed58971f0ec1be2faf8775778336d9e8aa41bf82c /misc
parent06ec17f5ea26eb6ba405773f2b7eb7930db9dee0 (diff)
downloadbrdo-8b0fda82cc390388e753c78b68a46fd1290a497c.tar.gz
brdo-8b0fda82cc390388e753c78b68a46fd1290a497c.tar.bz2
- Patch #825318 by effulgentsia, katbailey: Drupal.attachBehaviors() is called an extra time, unnecessarily and for document context, when there is no form.
Diffstat (limited to 'misc')
-rw-r--r--misc/ajax.js26
1 files changed, 18 insertions, 8 deletions
diff --git a/misc/ajax.js b/misc/ajax.js
index a9588261b..0c83d7776 100644
--- a/misc/ajax.js
+++ b/misc/ajax.js
@@ -189,8 +189,14 @@ Drupal.ajax = function (base, element, element_settings) {
*/
Drupal.ajax.prototype.beforeSerialize = function (element, options) {
// Allow detaching behaviors to update field values before collecting them.
- var settings = this.settings || Drupal.settings;
- Drupal.detachBehaviors(this.form, settings, 'serialize');
+ // This is only needed when field values are added to the POST data, so only
+ // when there is a form such that this.form.ajaxSubmit() is used instead of
+ // $.ajax(). When there is no form and $.ajax() is used, beforeSerialize()
+ // isn't called, but don't rely on that: explicitly check this.form.
+ if (this.form) {
+ var settings = this.settings || Drupal.settings;
+ Drupal.detachBehaviors(this.form, settings, 'serialize');
+ }
};
/**
@@ -249,12 +255,14 @@ Drupal.ajax.prototype.success = function (response, status) {
}
}
- // Reattach behaviors that were detached in beforeSerialize(). The
+ // Reattach behaviors, if they were detached in beforeSerialize(). The
// attachBehaviors() called on the new content from processing the response
// commands is not sufficient, because behaviors from the entire form need
// to be reattached.
- var settings = this.settings || Drupal.settings;
- Drupal.attachBehaviors(this.form, settings);
+ if (this.form) {
+ var settings = this.settings || Drupal.settings;
+ Drupal.attachBehaviors(this.form, settings);
+ }
Drupal.unfreezeHeight();
@@ -306,9 +314,11 @@ Drupal.ajax.prototype.error = function (response, uri) {
$(this.wrapper).show();
// Re-enable the element.
$(this.element).removeClass('progress-disabled').attr('disabled', false);
- // Reattach behaviors that were detached in beforeSerialize().
- var settings = response.settings || this.settings || Drupal.settings;
- Drupal.attachBehaviors(this.form, settings);
+ // Reattach behaviors, if they were detached in beforeSerialize().
+ if (this.form) {
+ var settings = response.settings || this.settings || Drupal.settings;
+ Drupal.attachBehaviors(this.form, settings);
+ }
};
/**