Your IP : 18.219.40.177
/**
* jQuery.ajaxq
* queue ajax requests
* @param {string} queue Name of queue
* @param {object} options
*/
jQuery.ajaxq = function(queue, options) {
'use strict';
// Initialize storage for request queues if it's not initialized yet
if (typeof document.ajaxq === 'undefined') {
document.ajaxq = { q: {}, r: null};
}
// Initialize current queue if it's not initialized yet
if (typeof document.ajaxq.q[queue] === 'undefined') {
document.ajaxq.q[queue] = [];
}
// Request settings are given, enqueue the new request
if (typeof options !== 'undefined') {
// Copy the original options, because options.complete is going to be overridden
var optionsCopy = {};
/* jslint forin:true */
for (var o in options) {
optionsCopy[o] = options[o];
}
options = optionsCopy;
// Override the original callback
var originalCompleteCallback = options.complete;
options.complete = function(request, status) {
// Dequeue the current request
document.ajaxq.q[queue].shift();
document.ajaxq.r = null;
// Run the original callback
if (originalCompleteCallback) {
originalCompleteCallback(request, status);
}
// Run the next request from the queue
if (document.ajaxq.q[queue].length > 0) {
document.ajaxq.r = jQuery.ajax(document.ajaxq.q[queue][0]);
}
if (document.ajaxq.q[queue].length === 0) {
delete document.ajaxq.q[queue];
}
};
if (queue !== 'multiload') {
var len = document.ajaxq.q[queue].length;
if (len <= 1) {
document.ajaxq.q[queue].push(options);
} else {
document.ajaxq.q[queue][1] = options;
}
//ставим в очередь
} else {
// Enqueue the request
document.ajaxq.q[queue].push(options);
}
// Also, if no request is currently running, start it
if (document.ajaxq.q[queue].length === 1) {
document.ajaxq.r = jQuery.ajax(options);
}
// No request settings are given, stop current request and clear the queue
} else {
if (document.ajaxq.r) {
document.ajaxq.r.abort();
document.ajaxq.r = null;
}
delete document.ajaxq.q[queue];
}
};