Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prototype - Are there AJAX start/stop events to global trigger an AJAX modal wait message?

Tags:

prototype

In Prototype, are there AJAX start/stop events that would allow you to create one script for globally displaying a modal wait message during AJAX loads?

Like, with jQuery I'm using this one script in the application layout to globally display a modal wait dialog for any jQuery AJAX events:

<script type="text/javascript">
$(document).ajaxStart(function () {
    $.blockUI({ message: '<h1><img src="../images/busy.gif" /> Just a moment...</h1>' });
});
$(document).ajaxStop(function () {
    $.unblockUI();
});
</script>

Thanks - much appreciated?

like image 418
Reno Avatar asked Jan 21 '23 06:01

Reno


1 Answers

With Prototype you have access to a variable Ajax.activeRequestCount (more info here)

This contains, at any time, the amount of currently active AJAX requests (those created by Prototype, anyway), by monitoring their onCreate and onComplete events

EDIT

Untested but something like this should work:

Ajax.Responders.register({
  onCreate: showProcessing,
  onComplete: hideProcessing
});

function showProcessing() {
  if(Ajax.activeRequestCount > 0){
        $('inProgress').show();
    }
}

function hideProcessing () {
  if(Ajax.activeRequestCount <= 0){
      $('inProgress').hide();
  }
}
like image 156
robjmills Avatar answered Feb 17 '23 10:02

robjmills