The dialog_loading command (Drupal.ajax.prototype.commands.dialog_loading) that is called to insert a loading throbber calls dialog_display (Drupal.ajax.prototype.commands.dialog_display). When calling the function, it passes in this as the ajax parameter.
/**
* Command to open a loading dialog.
*/
Drupal.ajax.prototype.commands.dialog_loading = function(ajax, response, status) {
Drupal.ajax.prototype.commands.dialog_display(this, {
content: Drupal.theme('DialogThrobber'),
title: Drupal.t('Loading...')
});
};
In the context of the function call, this refers to Drupal.ajax.prototype.commands. In dialog_display, a settings variable is created and passed to Drupal.attachBehaviors.
// Apply any settings from the returned JSON if available.
var settings = response.settings || ajax.settings || Drupal.settings;
// Process any other behaviors on the content, and display the dialog box.
Drupal.attachBehaviors(new_content, settings);
response.settings is undefined, but ajax.settings is defined because ajax refers to Drupal.ajax.prototype.commands and Drupal.ajax.prototype.commands.settings is defined as a function in ajax.js.
/**
* Command to set the settings that will be used for other commands in this response.
*/
settings: function (ajax, response, status) {
if (response.merge) {
$.extend(true, Drupal.settings, response.settings);
}
else {
ajax.settings = response.settings;
}
},
So when the attach functions of modules are called, the settings parameter they receive is a function, not an object, as shown here in the contributed extlink module:
https://skitch.com/jesse.beach/gpymr/developer-tools-http-provideotest.w...
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | dialog_ajax_error-1358624-3.patch | 1.23 KB | jessebeach |
| #1 | dialog_ajax_error-1358624-2.patch | 918 bytes | jessebeach |
Comments
Comment #1
jessebeach commentedThis is a bandaid on an issue that should probably be addressed more fundamentally. D7 now has a built-in throbber, so the dialog_loading function is no longer necessary.
I just replaced the reference to
thiswith an empty literal object{}.Comment #2
jessebeach commentedFrom a chat with effulgentsia
effulgentsia
4:42 why an empty object for first param? rather than the ajax object?
Jesse Beach
4:43 in this case, the ajax object is "undefined"
4:43 passing it straight through produces an error
4:43 the whole thing is wrong
4:43 the way the throbber is instantiated
4:43 but that's a big deal to fix
4:44 or a bigger deal than I have time for ATM
effulgentsia
4:45 can you add a code comment to that effect? like
4:45 // For some reason, the ajax parameter is undefined, so pass an empty object instead.
4:45 // @todo Refactor this to blah blah blah.
Jesse Beach
4:55 yes
Comment #3
jessebeach commentedAdded comments explaining the patch to the patch.
Comment #4
jessebeach commentedSetting to needs review.
Comment #5
ezman commentedthanks for this patch - have encountered this problem today and changing "this" to "{}" works for me!
Comment #6
devin carlson commentedThe 7.x-1.x branch of the Dialog module is unsupported.