1
|
var AjaxQueue = {
|
2
|
batchSize: 1, //No.of simultaneous AJAX requests allowed, Default : 1
|
3
|
urlQueue: [], //Request URLs will be pushed into this array
|
4
|
elementsQueue: [], //Element IDs of elements to be updated on completion of a request ( as in Ajax.Updater )
|
5
|
optionsQueue: [], //Request options will be pushed into this array
|
6
|
setBatchSize: function(bSize){ //Method to set a different batch size. Recommended: Set batchSize before making requests
|
7
|
this.batchSize = bSize;
|
8
|
},
|
9
|
push: function(url, options, elementID){ //Push the request in the queue. elementID is optional and required only for Ajax.Updater calls
|
10
|
this.urlQueue.push(url);
|
11
|
this.optionsQueue.push(options);
|
12
|
if(elementID!=null){
|
13
|
this.elementsQueue.push(elementID);
|
14
|
} else {
|
15
|
this.elementsQueue.push("NOTSPECIFIED");
|
16
|
}
|
17
|
|
18
|
this._processNext();
|
19
|
},
|
20
|
_processNext: function() { // Method for processing the requests in the queue. Private method. Don't call it explicitly
|
21
|
if(Ajax.activeRequestCount < AjaxQueue.batchSize) // Check if the currently processing request count is less than batch size
|
22
|
{
|
23
|
if(AjaxQueue.elementsQueue.first()=="NOTSPECIFIED") { //Check if an elementID was specified
|
24
|
// Call Ajax.Request if no ElementID specified
|
25
|
//Call Ajax.Request on the first item in the queue and remove it from the queue
|
26
|
new Ajax.Request(AjaxQueue.urlQueue.shift(), AjaxQueue.optionsQueue.shift());
|
27
|
|
28
|
var junk = AjaxQueue.elementsQueue.shift();
|
29
|
} else {
|
30
|
// Call Ajax.Updater if an ElementID was specified.
|
31
|
//Call Ajax.Updater on the first item in the queue and remove it from the queue
|
32
|
new Ajax.Updater(AjaxQueue.elementsQueue.shift(), AjaxQueue.urlQueue.shift(), AjaxQueue.optionsQueue.shift());
|
33
|
}
|
34
|
}
|
35
|
}
|
36
|
};
|
37
|
Ajax.Responders.register({
|
38
|
//Call AjaxQueue._processNext on completion ( success / failure) of any AJAX call.
|
39
|
onComplete: AjaxQueue._processNext
|
40
|
});
|