forked from aFarkas/Ajaxmanager
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
379 lines (360 loc) · 13.6 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery: AJAX Queue/Cache/Abort/Block Manager</title>
<link rel="stylesheet" href="../../css/layout.css" type="text/css" media="screen, projection">
<style type="text/css">
#wrapper div {
border: 1px solid #000;
padding: 10px;
margin: 10px;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script src="../../js/jquery.chili.pack.js" type="text/javascript"></script>
<script type="text/javascript">
(function(){
if(!window.ChiliBook){return;}
ChiliBook.recipeFolder = "../../css/chili/";
ChiliBook.stylesheetFolder = "../../css/chili/";
})();
</script>
<script src="jquery.ajaxmanager.js"></script>
<script type="text/javascript">
$(function(){
if(!window.console){
window.console = {
log: function(){}
};
}
$(document).bind('queueAjaxStart', function(e){
console.log('queueAjaxStart');
});
$(document).bind('queueAjaxStop', function(e, data){
console.log('queueAjaxStop');
});
$(document).bind('lifoAjaxStop', function(e){
console.log('lifoStop');
});
var a = $.manageAjax.create('queue', {queue: true});
$('#region1 a').click(function(e){
var $this = $(this);
e.preventDefault();
a.add({
success: function(html) {
$this.parent('div').find('ul').append('<li>'+html+'</li>');
},
url: $this.attr('href')
});
return false;
});
$('#region1 button')
.filter('.abort')
.click(function(){
a.abort();
})
.end()
.filter('.clear')
.click(function(){
a.clear();
})
.end()
.filter('.clear-abort')
.click(function(){
a.clear(true);
});
$.manageAjax.create('lifo', {queue: 'clear', maxRequests: 2, abortOld: true});
$('#region2 a').click(function(){
var $this = $(this);
$.manageAjax.add('lifo', {
success: function(html) {
$this.parent('div').find('ul').append('<li>'+html+'</li>');
},
url: $this.attr('href')
});
return false;
});
$('#region2 button')
.filter('.abort')
.click(function(){
$.manageAjax.abort('lifo');
})
.end()
.filter('.clear')
.click(function(){
$.manageAjax.clear('lifo');
})
.end()
.filter('.clear-abort')
.click(function(){
$.manageAjax.clear('lifo', true);
});
$('#region3 a').click(function(){
var $this = $(this);
$.manageAjax.add('lifo-cache', {
queue: 'clear',
cacheResponse: true,
success: function(html) {
$this.parent('div').find('ul').append('<li>'+html+'</li>');
},
url: $this.attr('href')
});
return false;
});
$('#region3 button')
.filter('.abort')
.click(function(){
$.manageAjax.abort('lifo-cache');
})
.end()
.filter('.clear')
.click(function(){
$.manageAjax.clear('lifo-cache');
})
.end()
.filter('.clear-abort')
.click(function(){
$.manageAjax.clear('lifo-cache', true);
});
var d = $.manageAjax.create('cache', {queue: false, cacheResponse: true, preventDoubleRequests: false});
$('#region4 a').click(function(){
var $this = $(this);
d.add({
success: function(html) {
$this.parent('div').find('ul').append('<li>'+html+'</li>');
},
abort: function(i){
$this.parent('div').find('ul').append('<li style="color: red">'+i+' aborted</li>');
},
url: $this.attr('href')
});
return false;
});
$('#region4 button').click(function(){
d.abort();
});
});
</script>
</head>
<body>
<div id="wrapper">
<h1>AJAX Queue/Cache/Abort/Block Manager v. 3.0</h1>
<p>Helps you to manage AJAX requests and responses (i.e. abort requests, block requests, order requests). It is inspired by the <a href="http://jquery.com/plugins/project/ajaxqueue">AJAX Queue Plugin</a> and the <a href="http://docs.jquery.com/AjaxQueue">AjaxQueue document</a> in the jQuery-Wiki.</p>
<h2>$.manageAjax.create (uniqueName, options)</h2>
<p>Creates a new ajaxmanager and returns it. Takes a list of options:</p>
<ul>
<li><a href="http://docs.jquery.com/Ajax/jQuery.ajax#options">normal jQuery-Ajax-Options</a></li>
<li>queue: (true|<strong>false</strong>|'clear') the queue-type specifies the queue-behaviour. The clear option clears the queue, before it adds a new ajax-task to the queue (similiar to: last in first out)
<li>abortOld (true|<strong>false</strong>): aborts all "older" requests, if there is a response to a newer request</li>
<li>abortIsNoSuccess: (<strong>true</strong>|false): jQuery 1.4 calls the success-callback, if an XHR was aborted. If this option is set to true. Only the complete - callback will be called with status 'abort'.</li>
<li>abort: (function): callback, that will be called, if a XHR is aborted.</li>
<li>beforeCreate ([function]): a function that will be called, before the XHR-object is created. If you return false, the XHR won´t be created.</li>
<li>maxRequests: (number (<strong>1</strong>)) limits the number of simultaneous request in the queue. queue-option must be true or 'clear'.</li>
<li>preventDoubleRequests (<strong>true</strong>|false): prevents multiple equal requests (compares url, data and type)</li>
<li>cacheResponse (true|<strong>false</strong>): caches the response data of succesfull responses (not the xhr-object!)</li>
<li>domCompleteTrigger (<strong>false</strong>| DOM-Element, DOMNodelist, Selector or jQuery-List). Triggers the events uniqueName + "DOMComplete" and "DOMComplete" on the specified element.</li>
<li>domSuccessTrigger (<strong>false</strong> | DOM-Element, DOMNodelist, Selector or jQuery-List). Triggers the events uniqueName + "DOMSuccess" and "DOMSuccess" on the specified element.</li>
</ul>
<p>Your constructed ajaxmanager knows the following methods:</p>
<ul>
<li>add: ([uniqueName], options) returns an id of your XHR object and takes the following options:
<ul>
<li><a href="http://docs.jquery.com/Ajax/jQuery.ajax#options">normal jQuery-Ajax-Options</a></li>
<li>all additional ajaxmanager options, but not 'maxRequests' and 'queue'.</li>
</ul>
</li>
<li>clear: ([uniqueName], [shouldAbort: true|<strong>false</strong>]) Clears the ajax queue of waiting requests. If the second parameter is true, all requests in proccess will be aborted, too.</li>
<li>abort: ([uniqueName], [id]) Aborts all managed XHR-requests. If you pass the optional index number of your XHR object only this XHR will be aborted.</li>
<li>getXHR: ([uniqueName], id) Returns the XHR-Object, if it is already constructed or the queue-function</li>
</ul>
<h3>Note:</h3>
<p>First you have to construct/configure a new Ajaxmanager<p>
<code class="javascript">//create an ajaxmanager named someAjaxProfileName
var someManagedAjax = $.manageAjax.create('someAjaxProfileName', {
queue: true,
cacheResponse: true
});
</code></p>
<p>You have two different ways to call your methods (don´t mix them).</p>
<h4>Calling Ajaxmanager with uniqueName</h4>
<code class="javascript">//and add an ajaxrequest
$.manageAjax.add('someAjaxProfileName', {
success: function(html) {
$('ul').append('<li>'+html+'</li>');
},
url: 'test.html'
});</code></p>
<h4>Calling Ajaxmanager with the returned ajaxmanger-Object</h4>
<code class="javascript">//and add an ajaxrequest with the returned object
$.manageAjax.add({
success: function(html) {
$('ul').append('<li>'+html+'</li>');
},
url: 'test.html'
});</code></p>
<h3>Example:</h3>
<p>
<code class="javascript">//create an ajaxmanager named cacheQueue
var ajaxManager = $.manageAjax.create('cacheQueue', {
queue: true,
cacheResponse: true
});
//and add an ajaxrequest with the returned object
ajaxManager.add({
success: function(html) {
$('ul').append('<li>'+html+'</li>');
},
url: 'test.html'
});</code></p>
<p>or only with the uniqueName parameter</p>
<p>
<code class="javascript">//generate an ajaxmanger named clearQueue
$.manageAjax.create('clearQueue', {queue: 'clear', maxRequests: 2});
//and add an ajaxrequest with the name parameter
$.manageAjax.add('clearQueue', {
success: function(html) {
$('ul').append('<li>'+html+'</li>');
},
url: 'test.html'
});</code></p>
<h3>$.manageAjax.destroy (uniqueName)</h3>
<p>Destroys an existing Ajaxmanager. Any requests in progress are aborted and waiting requests are cleared.</p>
<h2 id="events">Events/Callbacks:</h2>
<p>The ajaxmanager adds some new events or enhances some existing callbacks.</p>
<table>
<thead>
<tr>
<th>name</th>
<th>arguments</th>
<th>new/enhanced</th>
</tr>
</thead>
<tbody>
<tr>
<th>beforeCreate (local)</th>
<td>XHR-ID, options</td>
<td>new</td>
</tr>
<tr>
<th>beforeSend (local)</th>
<td>XMLHttpRequest, options</td>
<td>enhanced: options arguments is passed</td>
</tr>
<tr>
<th>managerName + 'AjaxStart' (global)</th>
<td>event</td>
<td>new</td>
</tr>
<tr>
<th>complete (local)</th>
<td>
xhr*, status, options
</td>
<td>enhanced: the options arguments is additionally passed.</td>
</tr>
<tr>
<th>managerName + 'AjaxComplete' (global)</th>
<td>
event, xhr*, status, options
</td>
<td>new</td>
</tr>
<tr>
<th>managerName + 'DOMComplete' (DOM-Event**)</th>
<td>
event, xhr*, status, options
</td>
<td>new</td>
</tr>
<tr>
<th>'DOMComplete' (DOM-Event**)</th>
<td>
event, xhr*, status, options
</td>
<td>new</td>
</tr>
<tr>
<th>success (local)</th>
<td>
data, textStatus, xhr*, options
</td>
<td>enhanced: the options arguments is additionally passed.</td>
</tr>
<tr>
<th>managerName + 'AjaxSuccess' (global)</th>
<td>
event, xhr, options, data
</td>
<td>new</td>
</tr>
<tr>
<th>managerName + 'DOMSuccess' (DOM-Event**)</th>
<td>
event, data, options
</td>
<td>new</td>
</tr>
<tr>
<th>'DOMSuccess' (DOM-Event**)</th>
<td>
event, data, options
</td>
<td>new</td>
</tr>
<tr>
<th>managerName + 'AjaxStop' (global)</th>
<td>
event
</td>
<td>new</td>
</tr>
</tbody>
</table>
<p><small>*Note: If the cacheResponse - option is true, the xhr-argument can be an empty object.</small></p>
<p><small>**Note: You need to configure 'domCompleteTrigger' / 'domSuccessTrigger' to trigger these events.</small></p>
<h2 id="demo">Demo:</h2>
<p>Tip: Open your Firebug-Console, log the XHR´s and click around.</p>
<div id="region1">
<h2>{queue: true}</h2>
<ul></ul>
<a href="0.html">0 secound delay</a> | <a href="1.php">1 secound delay</a> | <a href="2.php">2 secounds delay</a> | <a href="3.php">3 secounds delay</a> |
<button class="clear">clear</button> <button class="abort">abort</button> <button class="clear-abort">clear + abort</button>
</div>
<div id="region2" class="box">
<h2>{queue: 'clear', maxRequests: 2, abortOld: true}</h2>
<ul></ul>
<a href="0.html">0 second delay</a> | <a href="1.php">1 second delay</a> | <a href="2.php">2 seconds delay</a> | <a href="3.php">3 secounds delay</a> |
<button class="clear">clear</button> <button class="abort">abort</button> <button class="clear-abort">clear + abort</button>
</div>
<div id="region3">
<h2>{queue: 'clear', cacheResponse: true}</h2>
<ul></ul>
<a href="0.html">0 second delay</a> | <a href="1.php">1 second delay</a> | <a href="2.php">2 seconds delay</a> | <a href="3.php">3 secounds delay</a> |
<button class="clear">clear</button> <button class="abort">abort</button> <button class="clear-abort">clear + abort</button>
</div>
<div id="region4" class="box">
<h2>{queue: false, cacheResponse: true, preventDoubleRequests: false}</h2>
<ul></ul>
<a href="0.html">0 second delay</a> | <a href="1.php">1 second delay</a> | <a href="2.php">2 seconds delay</a> | <a href="3.php">3 secounds delay</a> |
<button class="abort">abort</button>
</div>
<p>If you find bugs please report them!!!</p>
<h2 id="project">Project Site & Bugtracker</h2>
<ul>
<li><a href="http://plugins.jquery.com/project/AjaxManager">ajaxmanager Project Site</a></li>
<li><a href="http://github.com/aFarkas/Ajaxmanager">public github-repository</a></li>
</ul>
<h2 id="download">Download</h2>
<ul>
<li><a href="jquery.ajaxmanager.js">ajaxmanager Download</a></li>
</ul>
<h2 id="licenses">Licenses</h2>
<ul>
<li><a href="http://jquery.com/dev/svn/trunk/jquery/MIT-LICENSE.txt" target="_blank">MIT License</a></li>
<li><a href="http://jquery.com/dev/svn/trunk/jquery/GPL-LICENSE.txt" target="_blank">GPL License</a></li>
</ul>
<p><a href="/">Back to protofunc</a></p>
</div>
</body>
</html>