ajaxmanager-rails 3.12
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/ajaxmanager-rails.gemspec +23 -0
- data/lib/.DS_Store +0 -0
- data/lib/ajaxmanager-rails.rb +6 -0
- data/lib/ajaxmanager-rails/engine.rb +7 -0
- data/lib/ajaxmanager-rails/version.rb +5 -0
- data/readme.md +15 -0
- data/vendor/assets/javascripts/ajaxmanager.js +342 -0
- metadata +70 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "ajaxmanager-rails/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "ajaxmanager-rails"
|
7
|
+
s.version = Ajaxmanager::Rails::VERSION
|
8
|
+
s.authors = ["Alexander Farkas", "James Burke"]
|
9
|
+
s.email = ["james.burke@examtime.com"]
|
10
|
+
s.homepage = "http://www.protofunc.com/scripts/jquery/ajaxManager/"
|
11
|
+
s.summary = %q{Ajaxmanager (by Alexander Farkas) packaged as a gem for Rails.}
|
12
|
+
s.description = %q{Ajaxmanager (by Alexander Farkas) packaged as a gem for Rails. Ajaxmanager helps you to manage AJAX requests and responses (i.e. abort requests, block requests, order requests). It is inspired by the AJAX Queue Plugin and the AjaxQueue document in the jQuery-Wiki.}
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
# specify any dependencies here; for example:
|
20
|
+
# s.add_development_dependency "rspec"
|
21
|
+
# s.add_runtime_dependency "rest-client"
|
22
|
+
s.add_dependency "jquery-rails"
|
23
|
+
end
|
data/lib/.DS_Store
ADDED
Binary file
|
data/readme.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
About
|
2
|
+
======
|
3
|
+
Ajaxmanager (by Alexander Farkas) packaged as a gem for Rails. Ajaxmanager helps you to manage AJAX requests and responses (i.e. abort requests, block requests, order requests). It is inspired by the AJAX Queue Plugin and the AjaxQueue document in the jQuery-Wiki.
|
4
|
+
|
5
|
+
How to Use
|
6
|
+
===========
|
7
|
+
Add the following to your GemFile:
|
8
|
+
`gem 'ajaxmanager-rails'
|
9
|
+
|
10
|
+
Then add the following to your application.js manifest:
|
11
|
+
`//= require ajaxmanager`
|
12
|
+
|
13
|
+
Full documentation for Ajaxmanager can be found at http://www.protofunc.com/scripts/jquery/ajaxManager/
|
14
|
+
|
15
|
+
Don't forget to run `bundle update` after upgrading to the latest gem version to ensure it's used by your rails app.
|
@@ -0,0 +1,342 @@
|
|
1
|
+
/**!
|
2
|
+
* project-site: http://plugins.jquery.com/project/AjaxManager
|
3
|
+
* repository: http://github.com/aFarkas/Ajaxmanager
|
4
|
+
* @author Alexander Farkas
|
5
|
+
* @version 3.12
|
6
|
+
* Copyright 2010, Alexander Farkas
|
7
|
+
* Dual licensed under the MIT or GPL Version 2 licenses.
|
8
|
+
*/
|
9
|
+
|
10
|
+
(function($){
|
11
|
+
"use strict";
|
12
|
+
var managed = {},
|
13
|
+
cache = {}
|
14
|
+
;
|
15
|
+
$.manageAjax = (function(){
|
16
|
+
function create(name, opts){
|
17
|
+
managed[name] = new $.manageAjax._manager(name, opts);
|
18
|
+
return managed[name];
|
19
|
+
}
|
20
|
+
|
21
|
+
function destroy(name){
|
22
|
+
if(managed[name]){
|
23
|
+
managed[name].clear(true);
|
24
|
+
delete managed[name];
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
|
29
|
+
var publicFns = {
|
30
|
+
create: create,
|
31
|
+
destroy: destroy
|
32
|
+
};
|
33
|
+
|
34
|
+
return publicFns;
|
35
|
+
})();
|
36
|
+
|
37
|
+
$.manageAjax._manager = function(name, opts){
|
38
|
+
this.requests = {};
|
39
|
+
this.inProgress = 0;
|
40
|
+
this.name = name;
|
41
|
+
this.qName = name;
|
42
|
+
|
43
|
+
this.opts = $.extend({}, $.manageAjax.defaults, opts);
|
44
|
+
if(opts && opts.queue && opts.queue !== true && typeof opts.queue === 'string' && opts.queue !== 'clear'){
|
45
|
+
this.qName = opts.queue;
|
46
|
+
}
|
47
|
+
};
|
48
|
+
|
49
|
+
$.manageAjax._manager.prototype = {
|
50
|
+
add: function(url, o){
|
51
|
+
if(typeof url == 'object'){
|
52
|
+
o = url;
|
53
|
+
} else if(typeof url == 'string'){
|
54
|
+
o = $.extend(o || {}, {url: url});
|
55
|
+
}
|
56
|
+
o = $.extend({}, this.opts, o);
|
57
|
+
|
58
|
+
var origCom = o.complete || $.noop,
|
59
|
+
origSuc = o.success || $.noop,
|
60
|
+
beforeSend = o.beforeSend || $.noop,
|
61
|
+
origError = o.error || $.noop,
|
62
|
+
strData = (typeof o.data == 'string') ? o.data : $.param(o.data || {}),
|
63
|
+
xhrID = o.type + o.url + strData,
|
64
|
+
that = this,
|
65
|
+
ajaxFn = this._createAjax(xhrID, o, origSuc, origCom)
|
66
|
+
;
|
67
|
+
if(o.preventDoubleRequests && o.queueDuplicateRequests){
|
68
|
+
if(o.preventDoubleRequests){
|
69
|
+
o.queueDuplicateRequests = false;
|
70
|
+
}
|
71
|
+
setTimeout(function(){
|
72
|
+
throw("preventDoubleRequests and queueDuplicateRequests can't be both true");
|
73
|
+
}, 0);
|
74
|
+
}
|
75
|
+
if(this.requests[xhrID] && o.preventDoubleRequests){
|
76
|
+
return;
|
77
|
+
}
|
78
|
+
ajaxFn.xhrID = xhrID;
|
79
|
+
o.xhrID = xhrID;
|
80
|
+
|
81
|
+
o.beforeSend = function(xhr, opts){
|
82
|
+
var ret = beforeSend.call(this, xhr, opts);
|
83
|
+
if(ret === false){
|
84
|
+
that._removeXHR(xhrID);
|
85
|
+
}
|
86
|
+
xhr = null;
|
87
|
+
return ret;
|
88
|
+
};
|
89
|
+
o.complete = function(xhr, status){
|
90
|
+
that._complete.call(that, this, origCom, xhr, status, xhrID, o);
|
91
|
+
xhr = null;
|
92
|
+
};
|
93
|
+
|
94
|
+
o.success = function(data, status, xhr){
|
95
|
+
that._success.call(that, this, origSuc, data, status, xhr, o);
|
96
|
+
xhr = null;
|
97
|
+
};
|
98
|
+
|
99
|
+
//always add some error callback
|
100
|
+
o.error = function(ahr, status, errorStr){
|
101
|
+
var httpStatus = '',
|
102
|
+
content = ''
|
103
|
+
;
|
104
|
+
if(status !== 'timeout' && ahr){
|
105
|
+
httpStatus = ahr.status;
|
106
|
+
content = ahr.responseXML || ahr.responseText;
|
107
|
+
}
|
108
|
+
if(origError) {
|
109
|
+
origError.call(this, ahr, status, errorStr, o);
|
110
|
+
} else {
|
111
|
+
setTimeout(function(){
|
112
|
+
throw status + '| status: ' + httpStatus + ' | URL: ' + o.url + ' | data: '+ strData + ' | thrown: '+ errorStr + ' | response: '+ content;
|
113
|
+
}, 0);
|
114
|
+
}
|
115
|
+
ahr = null;
|
116
|
+
};
|
117
|
+
|
118
|
+
if(o.queue === 'clear'){
|
119
|
+
$(document).clearQueue(this.qName);
|
120
|
+
}
|
121
|
+
|
122
|
+
if(o.queue || (o.queueDuplicateRequests && this.requests[xhrID])){
|
123
|
+
$.queue(document, this.qName, ajaxFn);
|
124
|
+
if(this.inProgress < o.maxRequests && (!this.requests[xhrID] || !o.queueDuplicateRequests)){
|
125
|
+
$.dequeue(document, this.qName);
|
126
|
+
}
|
127
|
+
return xhrID;
|
128
|
+
}
|
129
|
+
return ajaxFn();
|
130
|
+
},
|
131
|
+
_createAjax: function(id, o, origSuc, origCom){
|
132
|
+
var that = this;
|
133
|
+
return function(){
|
134
|
+
if(o.beforeCreate.call(o.context || that, id, o) === false){return;}
|
135
|
+
that.inProgress++;
|
136
|
+
if(that.inProgress === 1){
|
137
|
+
$.event.trigger(that.name +'AjaxStart');
|
138
|
+
}
|
139
|
+
if(o.cacheResponse && cache[id]){
|
140
|
+
if(!cache[id].cacheTTL || cache[id].cacheTTL < 0 || ((new Date().getTime() - cache[id].timestamp) < cache[id].cacheTTL)){
|
141
|
+
that.requests[id] = {};
|
142
|
+
setTimeout(function(){
|
143
|
+
that._success.call(that, o.context || o, origSuc, cache[id]._successData, 'success', cache[id], o);
|
144
|
+
that._complete.call(that, o.context || o, origCom, cache[id], 'success', id, o);
|
145
|
+
}, 0);
|
146
|
+
} else {
|
147
|
+
delete cache[id];
|
148
|
+
}
|
149
|
+
}
|
150
|
+
if(!o.cacheResponse || !cache[id]) {
|
151
|
+
if (o.async) {
|
152
|
+
that.requests[id] = $.ajax(o);
|
153
|
+
} else {
|
154
|
+
$.ajax(o);
|
155
|
+
}
|
156
|
+
}
|
157
|
+
return id;
|
158
|
+
};
|
159
|
+
},
|
160
|
+
_removeXHR: function(xhrID){
|
161
|
+
if(this.opts.queue || this.opts.queueDuplicateRequests){
|
162
|
+
$.dequeue(document, this.qName);
|
163
|
+
}
|
164
|
+
this.inProgress--;
|
165
|
+
this.requests[xhrID] = null;
|
166
|
+
delete this.requests[xhrID];
|
167
|
+
},
|
168
|
+
clearCache: function () {
|
169
|
+
cache = {};
|
170
|
+
},
|
171
|
+
_isAbort: function(xhr, status, o){
|
172
|
+
if(!o.abortIsNoSuccess || (!xhr && !status)){
|
173
|
+
return false;
|
174
|
+
}
|
175
|
+
var ret = !!( ( !xhr || xhr.readyState === 0 || this.lastAbort === o.xhrID ) );
|
176
|
+
xhr = null;
|
177
|
+
return ret;
|
178
|
+
},
|
179
|
+
_complete: function(context, origFn, xhr, status, xhrID, o){
|
180
|
+
if(this._isAbort(xhr, status, o)){
|
181
|
+
status = 'abort';
|
182
|
+
o.abort.call(context, xhr, status, o);
|
183
|
+
}
|
184
|
+
origFn.call(context, xhr, status, o);
|
185
|
+
|
186
|
+
$.event.trigger(this.name +'AjaxComplete', [xhr, status, o]);
|
187
|
+
|
188
|
+
if(o.domCompleteTrigger){
|
189
|
+
$(o.domCompleteTrigger)
|
190
|
+
.trigger(this.name +'DOMComplete', [xhr, status, o])
|
191
|
+
.trigger('DOMComplete', [xhr, status, o])
|
192
|
+
;
|
193
|
+
}
|
194
|
+
|
195
|
+
this._removeXHR(xhrID);
|
196
|
+
if(!this.inProgress){
|
197
|
+
$.event.trigger(this.name +'AjaxStop');
|
198
|
+
}
|
199
|
+
xhr = null;
|
200
|
+
},
|
201
|
+
_success: function(context, origFn, data, status, xhr, o){
|
202
|
+
var that = this;
|
203
|
+
if(this._isAbort(xhr, status, o)){
|
204
|
+
xhr = null;
|
205
|
+
return;
|
206
|
+
}
|
207
|
+
if(o.abortOld){
|
208
|
+
$.each(this.requests, function(name){
|
209
|
+
if(name === o.xhrID){
|
210
|
+
return false;
|
211
|
+
}
|
212
|
+
that.abort(name);
|
213
|
+
});
|
214
|
+
}
|
215
|
+
if(o.cacheResponse && !cache[o.xhrID]){
|
216
|
+
if(!xhr){
|
217
|
+
xhr = {};
|
218
|
+
}
|
219
|
+
cache[o.xhrID] = {
|
220
|
+
status: xhr.status,
|
221
|
+
statusText: xhr.statusText,
|
222
|
+
responseText: xhr.responseText,
|
223
|
+
responseXML: xhr.responseXML,
|
224
|
+
_successData: data,
|
225
|
+
cacheTTL: o.cacheTTL,
|
226
|
+
timestamp: new Date().getTime()
|
227
|
+
};
|
228
|
+
if('getAllResponseHeaders' in xhr){
|
229
|
+
var responseHeaders = xhr.getAllResponseHeaders();
|
230
|
+
var parsedHeaders;
|
231
|
+
var parseHeaders = function(){
|
232
|
+
if(parsedHeaders){return;}
|
233
|
+
parsedHeaders = {};
|
234
|
+
$.each(responseHeaders.split("\n"), function(i, headerLine){
|
235
|
+
var delimiter = headerLine.indexOf(":");
|
236
|
+
parsedHeaders[headerLine.substr(0, delimiter)] = headerLine.substr(delimiter + 2);
|
237
|
+
});
|
238
|
+
};
|
239
|
+
$.extend(cache[o.xhrID], {
|
240
|
+
getAllResponseHeaders: function() {return responseHeaders;},
|
241
|
+
getResponseHeader: function(name) {
|
242
|
+
parseHeaders();
|
243
|
+
return (name in parsedHeaders) ? parsedHeaders[name] : null;
|
244
|
+
}
|
245
|
+
});
|
246
|
+
}
|
247
|
+
}
|
248
|
+
origFn.call(context, data, status, xhr, o);
|
249
|
+
$.event.trigger(this.name +'AjaxSuccess', [xhr, o, data]);
|
250
|
+
if(o.domSuccessTrigger){
|
251
|
+
$(o.domSuccessTrigger)
|
252
|
+
.trigger(this.name +'DOMSuccess', [data, o])
|
253
|
+
.trigger('DOMSuccess', [data, o])
|
254
|
+
;
|
255
|
+
}
|
256
|
+
xhr = null;
|
257
|
+
},
|
258
|
+
getData: function(id){
|
259
|
+
if( id ){
|
260
|
+
var ret = this.requests[id];
|
261
|
+
if(!ret && this.opts.queue) {
|
262
|
+
ret = $.grep($(document).queue(this.qName), function(fn, i){
|
263
|
+
return (fn.xhrID === id);
|
264
|
+
})[0];
|
265
|
+
}
|
266
|
+
return ret;
|
267
|
+
}
|
268
|
+
return {
|
269
|
+
requests: this.requests,
|
270
|
+
queue: (this.opts.queue) ? $(document).queue(this.qName) : [],
|
271
|
+
inProgress: this.inProgress
|
272
|
+
};
|
273
|
+
},
|
274
|
+
abort: function(id){
|
275
|
+
var xhr;
|
276
|
+
if(id){
|
277
|
+
xhr = this.getData(id);
|
278
|
+
|
279
|
+
if(xhr && xhr.abort){
|
280
|
+
this.lastAbort = id;
|
281
|
+
xhr.abort();
|
282
|
+
this.lastAbort = false;
|
283
|
+
} else {
|
284
|
+
$(document).queue(
|
285
|
+
this.qName, $.grep($(document).queue(this.qName), function(fn, i){
|
286
|
+
return (fn !== xhr);
|
287
|
+
})
|
288
|
+
);
|
289
|
+
}
|
290
|
+
xhr = null;
|
291
|
+
return;
|
292
|
+
}
|
293
|
+
|
294
|
+
var that = this,
|
295
|
+
ids = []
|
296
|
+
;
|
297
|
+
$.each(this.requests, function(id){
|
298
|
+
ids.push(id);
|
299
|
+
});
|
300
|
+
$.each(ids, function(i, id){
|
301
|
+
that.abort(id);
|
302
|
+
});
|
303
|
+
},
|
304
|
+
clear: function(shouldAbort){
|
305
|
+
$(document).clearQueue(this.qName);
|
306
|
+
if(shouldAbort){
|
307
|
+
this.abort();
|
308
|
+
}
|
309
|
+
}
|
310
|
+
};
|
311
|
+
$.manageAjax._manager.prototype.getXHR = $.manageAjax._manager.prototype.getData;
|
312
|
+
$.manageAjax.defaults = {
|
313
|
+
beforeCreate: $.noop,
|
314
|
+
abort: $.noop,
|
315
|
+
abortIsNoSuccess: true,
|
316
|
+
maxRequests: 1,
|
317
|
+
cacheResponse: false,
|
318
|
+
async: true,
|
319
|
+
domCompleteTrigger: false,
|
320
|
+
domSuccessTrigger: false,
|
321
|
+
preventDoubleRequests: true,
|
322
|
+
queueDuplicateRequests: false,
|
323
|
+
cacheTTL: -1,
|
324
|
+
queue: false // true, false, clear
|
325
|
+
};
|
326
|
+
|
327
|
+
$.each($.manageAjax._manager.prototype, function(n, fn){
|
328
|
+
if(n.indexOf('_') === 0 || !$.isFunction(fn)){return;}
|
329
|
+
$.manageAjax[n] = function(name, o){
|
330
|
+
if(!managed[name]){
|
331
|
+
if(n === 'add'){
|
332
|
+
$.manageAjax.create(name, o);
|
333
|
+
} else {
|
334
|
+
return;
|
335
|
+
}
|
336
|
+
}
|
337
|
+
var args = Array.prototype.slice.call(arguments, 1);
|
338
|
+
managed[name][n].apply(managed[name], args);
|
339
|
+
};
|
340
|
+
});
|
341
|
+
|
342
|
+
})(jQuery);
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ajaxmanager-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '3.12'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Alexander Farkas
|
9
|
+
- James Burke
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2012-02-09 00:00:00.000000000Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: jquery-rails
|
17
|
+
requirement: &70344120 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *70344120
|
26
|
+
description: Ajaxmanager (by Alexander Farkas) packaged as a gem for Rails. Ajaxmanager
|
27
|
+
helps you to manage AJAX requests and responses (i.e. abort requests, block requests,
|
28
|
+
order requests). It is inspired by the AJAX Queue Plugin and the AjaxQueue document
|
29
|
+
in the jQuery-Wiki.
|
30
|
+
email:
|
31
|
+
- james.burke@examtime.com
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- .gitignore
|
37
|
+
- Gemfile
|
38
|
+
- Rakefile
|
39
|
+
- ajaxmanager-rails.gemspec
|
40
|
+
- lib/.DS_Store
|
41
|
+
- lib/ajaxmanager-rails.rb
|
42
|
+
- lib/ajaxmanager-rails/engine.rb
|
43
|
+
- lib/ajaxmanager-rails/version.rb
|
44
|
+
- readme.md
|
45
|
+
- vendor/assets/javascripts/ajaxmanager.js
|
46
|
+
homepage: http://www.protofunc.com/scripts/jquery/ajaxManager/
|
47
|
+
licenses: []
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.8.11
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: Ajaxmanager (by Alexander Farkas) packaged as a gem for Rails.
|
70
|
+
test_files: []
|