Fix for Fix for Overriding ahah success function to alter Drupal.settings

  1. (function($) {
  2.  
  3. if (Drupal.jsEnabled) {
  4.   $(document).ready(function() {
  5.     if (Drupal.ahah != undefined) {
  6.  
  7.       /**
  8.        * Override of Drupal.ahah.prototype.success. The only difference is that we
  9.        * allow for new Drupal.settings.
  10.        */
  11.       Drupal.ahah.prototype.success = function (response, status) {
  12.         var wrapper = $(this.wrapper);
  13.         var form = $(this.element).parents('form');
  14.         // Manually insert HTML into the jQuery object, using $() directly crashes
  15.         // Safari with long string lengths. http://dev.jquery.com/ticket/1152
  16.         var new_content = $('<div></div>').html(response.data);
  17.      
  18.         // Restore the previous action and target to the form.
  19.         form.attr('action', this.form_action);
  20.         this.form_target ? form.attr('target', this.form_target) : form.removeAttr('target');
  21.         this.form_encattr ? form.attr('target', this.form_encattr) : form.removeAttr('encattr');
  22.      
  23.         // Remove the progress element.
  24.         if (this.progress.element) {
  25.           $(this.progress.element).remove();
  26.         }
  27.         if (this.progress.object) {
  28.           this.progress.object.stopMonitoring();
  29.         }
  30.         $(this.element).removeClass('progress-disabled').attr('disabled', false);
  31.      
  32.         // Add the new content to the page.
  33.         Drupal.freezeHeight();
  34.         if (this.method == 'replace') {
  35.           wrapper.empty().append(new_content);
  36.         }
  37.         else {
  38.           wrapper[this.method](new_content);
  39.         }
  40.      
  41.         // Immediately hide the new content if we're using any effects.
  42.         if (this.showEffect != 'show') {
  43.           new_content.hide();
  44.         }
  45.      
  46.         // Determine what effect use and what content will receive the effect, then
  47.         // show the new content. For browser compatibility, Safari is excluded from
  48.         // using effects on table rows.
  49.         if (($.browser.safari && $("tr.ahah-new-content", new_content).size() > 0)) {
  50.           new_content.show();
  51.         }
  52.         else if ($('.ahah-new-content', new_content).size() > 0) {
  53.           $('.ahah-new-content', new_content).hide();
  54.           new_content.show();
  55.           $(".ahah-new-content", new_content)[this.showEffect](this.showSpeed);
  56.         }
  57.         else if (this.showEffect != 'show') {
  58.           new_content[this.showEffect](this.showSpeed);
  59.         }
  60.      
  61.         // Merge in new and changed settings, if any.
  62.         if (response.settings) {
  63.           $.extend(Drupal.settings, response.settings);
  64.         }
  65.      
  66.         // Attach all javascript behaviors to the new content, if it was successfully
  67.         // added to the page, this if statement allows #ahah[wrapper] to be optional.
  68.         if (new_content.parents('html').length > 0) {
  69.           Drupal.attachBehaviors(new_content);
  70.         }
  71.      
  72.         Drupal.unfreezeHeight();
  73.       };
  74.     }
  75.   });
  76. }
  77.  
  78. })(jQuery);

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.