app/jquery/jquery-ajaxQueue.js
author Lennard de Rijk <ljvderijk@gmail.com>
Thu, 13 Aug 2009 11:52:43 -0700
changeset 2769 279d26439495
parent 1235 41cb87ed9b81
permissions -rw-r--r--
Added export for Org Admins and Mentors, but only one per User.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1212
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
/**
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
 * Ajax Queue Plugin
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     3
 *
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
 * Homepage: http://jquery.com/plugins/project/ajaxqueue
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     5
 * Documentation: http://docs.jquery.com/AjaxQueue
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     6
 */
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     7
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     8
/**
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    10
<script>
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    11
$(function(){
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    12
	jQuery.ajaxQueue({
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    13
		url: "test.php",
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    14
		success: function(html){ jQuery("ul").append(html); }
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    15
	});
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    16
	jQuery.ajaxQueue({
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    17
		url: "test.php",
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    18
		success: function(html){ jQuery("ul").append(html); }
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    19
	});
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    20
	jQuery.ajaxSync({
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    21
		url: "test.php",
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    22
		success: function(html){ jQuery("ul").append("<b>"+html+"</b>"); }
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    23
	});
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    24
	jQuery.ajaxSync({
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    25
		url: "test.php",
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    26
		success: function(html){ jQuery("ul").append("<b>"+html+"</b>"); }
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    27
	});
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    28
});
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
</script>
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    30
<ul style="position: absolute; top: 5px; right: 5px;"></ul>
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    31
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    32
 */
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    33
/*
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    34
 * Queued Ajax requests.
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    35
 * A new Ajax request won't be started until the previous queued
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    36
 * request has finished.
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    37
 */
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    38
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    39
/*
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    40
 * Synced Ajax requests.
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    41
 * The Ajax request will happen as soon as you call this method, but
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    42
 * the callbacks (success/error/complete) won't fire until all previous
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    43
 * synced requests have been completed.
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    44
 */
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    45
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    46
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    47
(function($) {
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    48
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    49
	var ajax = $.ajax;
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    50
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    51
	var pendingRequests = {};
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    52
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    53
	var synced = [];
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    54
	var syncedData = [];
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    55
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    56
	$.ajax = function(settings) {
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    57
		// create settings for compatibility with ajaxSetup
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    58
		settings = jQuery.extend(settings, jQuery.extend({}, jQuery.ajaxSettings, settings));
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    59
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    60
		var port = settings.port;
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    61
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    62
		switch(settings.mode) {
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    63
		case "abort":
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    64
			if ( pendingRequests[port] ) {
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    65
				pendingRequests[port].abort();
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    66
			}
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    67
			return pendingRequests[port] = ajax.apply(this, arguments);
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    68
		case "queue":
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    69
			var _old = settings.complete;
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    70
			settings.complete = function(){
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    71
				if ( _old )
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    72
					_old.apply( this, arguments );
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    73
				jQuery([ajax]).dequeue("ajax" + port );;
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    74
			};
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    75
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    76
			jQuery([ ajax ]).queue("ajax" + port, function(){
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    77
				ajax( settings );
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    78
			});
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    79
			return;
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    80
		case "sync":
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    81
			var pos = synced.length;
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    82
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    83
			synced[ pos ] = {
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    84
				error: settings.error,
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    85
				success: settings.success,
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    86
				complete: settings.complete,
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    87
				done: false
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    88
			};
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    89
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    90
			syncedData[ pos ] = {
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    91
				error: [],
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    92
				success: [],
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    93
				complete: []
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    94
			};
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    95
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    96
			settings.error = function(){ syncedData[ pos ].error = arguments; };
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    97
			settings.success = function(){ syncedData[ pos ].success = arguments; };
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    98
			settings.complete = function(){
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    99
				syncedData[ pos ].complete = arguments;
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   100
				synced[ pos ].done = true;
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   101
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   102
				if ( pos == 0 || !synced[ pos-1 ] )
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   103
					for ( var i = pos; i < synced.length && synced[i].done; i++ ) {
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   104
						if ( synced[i].error ) synced[i].error.apply( jQuery, syncedData[i].error );
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   105
						if ( synced[i].success ) synced[i].success.apply( jQuery, syncedData[i].success );
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   106
						if ( synced[i].complete ) synced[i].complete.apply( jQuery, syncedData[i].complete );
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   107
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   108
						synced[i] = null;
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   109
						syncedData[i] = null;
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   110
					}
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   111
			};
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   112
		}
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   113
		return ajax.apply(this, arguments);
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   114
	};
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   115
1b64b5922227 Added jquery thickbox, ajaxQueue, autocomplete and bgiframe
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   116
})(jQuery);