I have a suggestion for changing misc/ahah.js. I've used vendor branching to change my own version of the code, but I think it's a worthwhile enough benefit that it maybe could be changed in core for everyone. The change I have made is this:

Original code:

  var options = {
    url: ahah.url,
    data: ahah.button,
    beforeSubmit: function(form_values, element_settings, options) {
      return ahah.beforeSubmit(form_values, element_settings, options);
    },
    success: function(response, status) {
      // Sanity check for browser support (object expected).
      // When using iFrame uploads, responses must be returned as a string.
      if (typeof(response) == 'string') {
        response = Drupal.parseJson(response);
      }
      return ahah.success(response, status);
    },
    complete: function(response, status) {
      if (status == 'error' || status == 'parsererror') {
        return ahah.error(response, ahah.url);
      }
    },
    dataType: 'json',
    type: 'POST'
  };

Changed code:

  var options = {
    url: ahah.url,
    data: ahah.button,
    beforeSubmit: function(form_values, element_settings, options) {
	  $("body").addClass("ahah");
      return ahah.beforeSubmit(form_values, element_settings, options);
    },
    success: function(response, status) {
      // Sanity check for browser support (object expected).
      // When using iFrame uploads, responses must be returned as a string.
      if (typeof(response) == 'string') {
        response = Drupal.parseJson(response);
      }
      return ahah.success(response, status);
    },
    complete: function(response, status) {
	  $("body").removeClass("ahah");
      if (status == 'error' || status == 'parsererror') {
        return ahah.error(response, ahah.url);
      }
    },
    dataType: 'json',
    type: 'POST'
  };

You'll see that I have added calls to add the class 'ahah' to the body upon AHAH submit, and remove this class upon completion. This allows for setting either CSS or javascript calls to other parts of the page during AHAH calls. For example, I have a block with an AHAH call in it. When the block is updating by AHAH, I want the content area to be 'disabled' as it were. So I can put together something like this. At the end of my content area, I add this div:

<div class="whiteout">&nbsp;</div>

And I can use the following CSS:

div.whiteout
{
  display:none;
  color:#FFF;
  filter:alpha(opacity=50); //IE
  opacity:0.5; // other browsers
  width:100%;
  height:100%;
  position:absolute;
  top:0;
  left:0;
}

body.ahah div.whiteout
{
  display:block;
}

(note: code is only an example written off the top of my head without testing). What happens is that by adding the .ahah class to the body during submission, this 'whiteout' div will become visible, being semi-opaque. At the end of the ahah call, it will again disappear. This is only possible if the ahah class is added to the body.

I don't know if this change is worthwhile enough to add to core or not, so I've been a little undecided about whether or not to open an issue for it. But I have used it myself on a number of different ajax driven sites, and it works really well for me, so I thought I would at least bring it up.

Comments

Status: Active » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.