Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hedleysmith/260a427f1e48f456bb56 to your computer and use it in GitHub Desktop.
Save hedleysmith/260a427f1e48f456bb56 to your computer and use it in GitHub Desktop.
Ever wondered how to override the default Ajax progress throbber? We can change the GIF easily with CSS but if you want to do things like change the position of the actualy HTML this is probably the cleanest way to do so.
/**
* @file
*
* Overrides the default Ajax progress indicator to do things like change the
* styling and positioning.
*/
(function ($) {
// Drupal's core beforeSend function
var beforeSend = Drupal.ajax.prototype.beforeSend;
// Add a trigger when beforeSend fires.
Drupal.ajax.prototype.beforeSend = function (xmlhttprequest, options) {
// Only apply our override on specific fields.
if (this.element.name == "field_name") {
// Copied and modified from Drupal.ajax.prototype.beforeSend in ajax.js
$(this.element).addClass('progress-disabled').attr('disabled', true);
// Modify the actualy progress throbber HTML.
this.progress.element = $('<div class="ajax-progress ajax-progress-throbber"><div class="throbber">&nbsp;</div><div class="message">Loading</div></div>');
// Change the position of the throbber.
$(this.element).parent().parent().after(this.progress.element);
} else {
// Send to the default Drupal Ajax function if we're not looking at our specific field.
beforeSend.call(this, xmlhttprequest, options);
$(document).trigger('beforeSend');
}
};
} (jQuery));
@twfahey1
Copy link

This is great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment