Gravatar pretty much equals disregarding privacy
[statusnet:gnu-social.git] / plugins / Autocomplete / jquery-autocomplete / lib / jquery.ajaxQueue.js
1 /**\r
2  * Ajax Queue Plugin\r
3  * \r
4  * Homepage: http://jquery.com/plugins/project/ajaxqueue\r
5  * Documentation: http://docs.jquery.com/AjaxQueue\r
6  */\r
7 \r
8 /**\r
9 \r
10 <script>\r
11 $(function(){\r
12         jQuery.ajaxQueue({\r
13                 url: "test.php",\r
14                 success: function(html){ jQuery("ul").append(html); }\r
15         });\r
16         jQuery.ajaxQueue({\r
17                 url: "test.php",\r
18                 success: function(html){ jQuery("ul").append(html); }\r
19         });\r
20         jQuery.ajaxSync({\r
21                 url: "test.php",\r
22                 success: function(html){ jQuery("ul").append("<b>"+html+"</b>"); }\r
23         });\r
24         jQuery.ajaxSync({\r
25                 url: "test.php",\r
26                 success: function(html){ jQuery("ul").append("<b>"+html+"</b>"); }\r
27         });\r
28 });\r
29 </script>\r
30 <ul style="position: absolute; top: 5px; right: 5px;"></ul>\r
31 \r
32  */\r
33 /*\r
34  * Queued Ajax requests.\r
35  * A new Ajax request won't be started until the previous queued \r
36  * request has finished.\r
37  */\r
38 \r
39 /*\r
40  * Synced Ajax requests.\r
41  * The Ajax request will happen as soon as you call this method, but\r
42  * the callbacks (success/error/complete) won't fire until all previous\r
43  * synced requests have been completed.\r
44  */\r
45 \r
46 \r
47 (function($) {\r
48         \r
49         var ajax = $.ajax;\r
50         \r
51         var pendingRequests = {};\r
52         \r
53         var synced = [];\r
54         var syncedData = [];\r
55         \r
56         $.ajax = function(settings) {\r
57                 // create settings for compatibility with ajaxSetup\r
58                 settings = jQuery.extend(settings, jQuery.extend({}, jQuery.ajaxSettings, settings));\r
59                 \r
60                 var port = settings.port;\r
61                 \r
62                 switch(settings.mode) {\r
63                 case "abort": \r
64                         if ( pendingRequests[port] ) {\r
65                                 pendingRequests[port].abort();\r
66                         }\r
67                         return pendingRequests[port] = ajax.apply(this, arguments);\r
68                 case "queue": \r
69                         var _old = settings.complete;\r
70                         settings.complete = function(){\r
71                                 if ( _old )\r
72                                         _old.apply( this, arguments );\r
73                                 jQuery([ajax]).dequeue("ajax" + port );;\r
74                         };\r
75                 \r
76                         jQuery([ ajax ]).queue("ajax" + port, function(){\r
77                                 ajax( settings );\r
78                         });\r
79                         return;\r
80                 case "sync":\r
81                         var pos = synced.length;\r
82         \r
83                         synced[ pos ] = {\r
84                                 error: settings.error,\r
85                                 success: settings.success,\r
86                                 complete: settings.complete,\r
87                                 done: false\r
88                         };\r
89                 \r
90                         syncedData[ pos ] = {\r
91                                 error: [],\r
92                                 success: [],\r
93                                 complete: []\r
94                         };\r
95                 \r
96                         settings.error = function(){ syncedData[ pos ].error = arguments; };\r
97                         settings.success = function(){ syncedData[ pos ].success = arguments; };\r
98                         settings.complete = function(){\r
99                                 syncedData[ pos ].complete = arguments;\r
100                                 synced[ pos ].done = true;\r
101                 \r
102                                 if ( pos == 0 || !synced[ pos-1 ] )\r
103                                         for ( var i = pos; i < synced.length && synced[i].done; i++ ) {\r
104                                                 if ( synced[i].error ) synced[i].error.apply( jQuery, syncedData[i].error );\r
105                                                 if ( synced[i].success ) synced[i].success.apply( jQuery, syncedData[i].success );\r
106                                                 if ( synced[i].complete ) synced[i].complete.apply( jQuery, syncedData[i].complete );\r
107                 \r
108                                                 synced[i] = null;\r
109                                                 syncedData[i] = null;\r
110                                         }\r
111                         };\r
112                 }\r
113                 return ajax.apply(this, arguments);\r
114         };\r
115         \r
116 })(jQuery);