batman-rails 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/batman/rails/version.rb +2 -2
- data/vendor/assets/javascripts/batman/batman.coffee +5825 -0
- data/vendor/assets/javascripts/batman/batman.jquery.coffee +71 -0
- data/vendor/assets/javascripts/batman/batman.rails.coffee +134 -0
- data/vendor/assets/javascripts/batman/batman.solo.coffee +496 -0
- metadata +18 -18
- data/vendor/assets/javascripts/batman/batman.jquery.js +0 -75
- data/vendor/assets/javascripts/batman/batman.js +0 -7134
- data/vendor/assets/javascripts/batman/batman.rails.js +0 -83
- data/vendor/assets/javascripts/batman/batman.solo.js +0 -418
@@ -1,83 +0,0 @@
|
|
1
|
-
(function() {
|
2
|
-
var applyExtra;
|
3
|
-
var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
|
4
|
-
for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
|
5
|
-
function ctor() { this.constructor = child; }
|
6
|
-
ctor.prototype = parent.prototype;
|
7
|
-
child.prototype = new ctor;
|
8
|
-
child.__super__ = parent.prototype;
|
9
|
-
return child;
|
10
|
-
}, __slice = Array.prototype.slice;
|
11
|
-
applyExtra = function(Batman) {
|
12
|
-
Batman.mixin(Batman.Encoders, {
|
13
|
-
railsDate: {
|
14
|
-
encode: function(value) {
|
15
|
-
return value;
|
16
|
-
},
|
17
|
-
decode: function(value) {
|
18
|
-
var a;
|
19
|
-
a = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
|
20
|
-
if (a) {
|
21
|
-
return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4], +a[5], +a[6]));
|
22
|
-
} else {
|
23
|
-
Batman.developer.warn("Unrecognized rails date " + value + "!");
|
24
|
-
return Date.parse(value);
|
25
|
-
}
|
26
|
-
}
|
27
|
-
}
|
28
|
-
});
|
29
|
-
return Batman.RailsStorage = (function() {
|
30
|
-
__extends(RailsStorage, Batman.RestStorage);
|
31
|
-
function RailsStorage() {
|
32
|
-
RailsStorage.__super__.constructor.apply(this, arguments);
|
33
|
-
}
|
34
|
-
RailsStorage.prototype._addJsonExtension = function(options) {
|
35
|
-
return options.url += '.json';
|
36
|
-
};
|
37
|
-
RailsStorage.prototype.optionsForRecord = function() {
|
38
|
-
var args, callback, _i;
|
39
|
-
args = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), callback = arguments[_i++];
|
40
|
-
return RailsStorage.__super__.optionsForRecord.apply(this, __slice.call(args).concat([function(err, options) {
|
41
|
-
if (!err) {
|
42
|
-
this._addJsonExtension(options);
|
43
|
-
}
|
44
|
-
return callback.call(this, err, options);
|
45
|
-
}]));
|
46
|
-
};
|
47
|
-
RailsStorage.prototype.optionsForCollection = function() {
|
48
|
-
var args, callback, _i;
|
49
|
-
args = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), callback = arguments[_i++];
|
50
|
-
return RailsStorage.__super__.optionsForCollection.apply(this, __slice.call(args).concat([function(err, options) {
|
51
|
-
if (!err) {
|
52
|
-
this._addJsonExtension(options);
|
53
|
-
}
|
54
|
-
return callback.call(this, err, options);
|
55
|
-
}]));
|
56
|
-
};
|
57
|
-
RailsStorage.prototype.after('update', 'create', function(_arg) {
|
58
|
-
var err, key, record, recordOptions, response, validationError, validationErrors, _i, _len, _ref;
|
59
|
-
err = _arg[0], record = _arg[1], response = _arg[2], recordOptions = _arg[3];
|
60
|
-
if (err) {
|
61
|
-
if (err.request.get('status') === 422) {
|
62
|
-
_ref = JSON.parse(err.request.get('response'));
|
63
|
-
for (key in _ref) {
|
64
|
-
validationErrors = _ref[key];
|
65
|
-
for (_i = 0, _len = validationErrors.length; _i < _len; _i++) {
|
66
|
-
validationError = validationErrors[_i];
|
67
|
-
record.get('errors').add(key, "" + key + " " + validationError);
|
68
|
-
}
|
69
|
-
}
|
70
|
-
return [record.get('errors'), record, response, recordOptions];
|
71
|
-
}
|
72
|
-
}
|
73
|
-
return arguments[0];
|
74
|
-
});
|
75
|
-
return RailsStorage;
|
76
|
-
})();
|
77
|
-
};
|
78
|
-
if ((typeof module !== "undefined" && module !== null) && (typeof require !== "undefined" && require !== null)) {
|
79
|
-
module.exports = applyExtra;
|
80
|
-
} else {
|
81
|
-
applyExtra(Batman);
|
82
|
-
}
|
83
|
-
}).call(this);
|
@@ -1,418 +0,0 @@
|
|
1
|
-
(function() {
|
2
|
-
|
3
|
-
/*!
|
4
|
-
* Reqwest! A x-browser general purpose XHR connection manager
|
5
|
-
* copyright Dustin Diaz 2011
|
6
|
-
* https://github.com/ded/reqwest
|
7
|
-
* license MIT
|
8
|
-
*/
|
9
|
-
!
|
10
|
-
function(context, win) {
|
11
|
-
|
12
|
-
var twoHundo = /^20\d$/,
|
13
|
-
doc = document,
|
14
|
-
byTag = 'getElementsByTagName',
|
15
|
-
contentType = 'Content-Type',
|
16
|
-
head = doc[byTag]('head')[0],
|
17
|
-
uniqid = 0,
|
18
|
-
lastValue // data stored by the most recent JSONP callback
|
19
|
-
, xhr = ('XMLHttpRequest' in win) ?
|
20
|
-
function() {
|
21
|
-
return new XMLHttpRequest()
|
22
|
-
} : function() {
|
23
|
-
return new ActiveXObject('Microsoft.XMLHTTP')
|
24
|
-
}
|
25
|
-
|
26
|
-
function readyState(o, success, error) {
|
27
|
-
return function() {
|
28
|
-
if (o && o.readyState == 4) {
|
29
|
-
if (twoHundo.test(o.status)) {
|
30
|
-
success(o)
|
31
|
-
} else {
|
32
|
-
error(o)
|
33
|
-
}
|
34
|
-
}
|
35
|
-
}
|
36
|
-
}
|
37
|
-
|
38
|
-
function setHeaders(http, o) {
|
39
|
-
var headers = o.headers || {}
|
40
|
-
headers.Accept = headers.Accept || 'text/javascript, text/html, application/xml, text/xml, */*'
|
41
|
-
|
42
|
-
// breaks cross-origin requests with legacy browsers
|
43
|
-
if (!o.crossOrigin) {
|
44
|
-
headers['X-Requested-With'] = headers['X-Requested-With'] || 'XMLHttpRequest'
|
45
|
-
}
|
46
|
-
|
47
|
-
if (o.data) {
|
48
|
-
headers[contentType] = headers[contentType] || 'application/x-www-form-urlencoded'
|
49
|
-
}
|
50
|
-
for (var h in headers) {
|
51
|
-
headers.hasOwnProperty(h) && http.setRequestHeader(h, headers[h], false)
|
52
|
-
}
|
53
|
-
}
|
54
|
-
|
55
|
-
function getCallbackName(o) {
|
56
|
-
var callbackVar = o.jsonpCallback || "callback"
|
57
|
-
if (o.url.slice(-(callbackVar.length + 2)) == (callbackVar + "=?")) {
|
58
|
-
// Generate a guaranteed unique callback name
|
59
|
-
var callbackName = "reqwest_" + uniqid++
|
60
|
-
|
61
|
-
// Replace the ? in the URL with the generated name
|
62
|
-
o.url = o.url.substr(0, o.url.length - 1) + callbackName
|
63
|
-
return callbackName
|
64
|
-
} else {
|
65
|
-
// Find the supplied callback name
|
66
|
-
var regex = new RegExp(callbackVar + "=([\\w]+)")
|
67
|
-
return o.url.match(regex)[1]
|
68
|
-
}
|
69
|
-
}
|
70
|
-
|
71
|
-
// Store the data returned by the most recent callback
|
72
|
-
|
73
|
-
|
74
|
-
function generalCallback(data) {
|
75
|
-
lastValue = data
|
76
|
-
}
|
77
|
-
|
78
|
-
function getRequest(o, fn, err) {
|
79
|
-
function onload() {
|
80
|
-
// Call the user callback with the last value stored
|
81
|
-
// and clean up values and scripts.
|
82
|
-
o.success && o.success(lastValue)
|
83
|
-
lastValue = undefined
|
84
|
-
head.removeChild(script);
|
85
|
-
}
|
86
|
-
if (o.type == 'jsonp') {
|
87
|
-
var script = doc.createElement('script')
|
88
|
-
|
89
|
-
// Add the global callback
|
90
|
-
win[getCallbackName(o)] = generalCallback;
|
91
|
-
|
92
|
-
// Setup our script element
|
93
|
-
script.type = 'text/javascript'
|
94
|
-
script.src = o.url
|
95
|
-
script.async = true
|
96
|
-
|
97
|
-
script.onload = onload
|
98
|
-
// onload for IE
|
99
|
-
script.onreadystatechange = function() {
|
100
|
-
/^loaded|complete$/.test(script.readyState) && onload()
|
101
|
-
}
|
102
|
-
|
103
|
-
// Add the script to the DOM head
|
104
|
-
head.appendChild(script)
|
105
|
-
} else {
|
106
|
-
var http = xhr()
|
107
|
-
http.open(o.method || 'GET', typeof o == 'string' ? o : o.url, true)
|
108
|
-
setHeaders(http, o)
|
109
|
-
http.onreadystatechange = readyState(http, fn, err)
|
110
|
-
o.before && o.before(http)
|
111
|
-
http.send(o.data || null)
|
112
|
-
return http
|
113
|
-
}
|
114
|
-
}
|
115
|
-
|
116
|
-
function Reqwest(o, fn) {
|
117
|
-
this.o = o
|
118
|
-
this.fn = fn
|
119
|
-
init.apply(this, arguments)
|
120
|
-
}
|
121
|
-
|
122
|
-
function setType(url) {
|
123
|
-
if (/\.json($|\?)/.test(url)) {
|
124
|
-
return 'json'
|
125
|
-
}
|
126
|
-
if (/\.jsonp($|\?)/.test(url)) {
|
127
|
-
return 'jsonp'
|
128
|
-
}
|
129
|
-
if (/\.js($|\?)/.test(url)) {
|
130
|
-
return 'js'
|
131
|
-
}
|
132
|
-
if (/\.html?($|\?)/.test(url)) {
|
133
|
-
return 'html'
|
134
|
-
}
|
135
|
-
if (/\.xml($|\?)/.test(url)) {
|
136
|
-
return 'xml'
|
137
|
-
}
|
138
|
-
return 'js'
|
139
|
-
}
|
140
|
-
|
141
|
-
function init(o, fn) {
|
142
|
-
this.url = typeof o == 'string' ? o : o.url
|
143
|
-
this.timeout = null
|
144
|
-
var type = o.type || setType(this.url),
|
145
|
-
self = this
|
146
|
-
fn = fn ||
|
147
|
-
function() {}
|
148
|
-
|
149
|
-
if (o.timeout) {
|
150
|
-
this.timeout = setTimeout(function() {
|
151
|
-
self.abort()
|
152
|
-
error()
|
153
|
-
}, o.timeout)
|
154
|
-
}
|
155
|
-
|
156
|
-
function complete(resp) {
|
157
|
-
o.complete && o.complete(resp)
|
158
|
-
}
|
159
|
-
|
160
|
-
function success(resp) {
|
161
|
-
o.timeout && clearTimeout(self.timeout) && (self.timeout = null)
|
162
|
-
var r = resp.responseText
|
163
|
-
|
164
|
-
if (r) {
|
165
|
-
switch (type) {
|
166
|
-
case 'json':
|
167
|
-
resp = win.JSON ? win.JSON.parse(r) : eval('(' + r + ')')
|
168
|
-
break;
|
169
|
-
case 'js':
|
170
|
-
resp = eval(r)
|
171
|
-
break;
|
172
|
-
case 'html':
|
173
|
-
resp = r
|
174
|
-
break;
|
175
|
-
}
|
176
|
-
}
|
177
|
-
|
178
|
-
fn(resp)
|
179
|
-
o.success && o.success(resp)
|
180
|
-
complete(resp)
|
181
|
-
}
|
182
|
-
|
183
|
-
function error(resp) {
|
184
|
-
o.error && o.error(resp)
|
185
|
-
complete(resp)
|
186
|
-
}
|
187
|
-
|
188
|
-
this.request = getRequest(o, success, error)
|
189
|
-
}
|
190
|
-
|
191
|
-
Reqwest.prototype = {
|
192
|
-
abort: function() {
|
193
|
-
this.request.abort()
|
194
|
-
}
|
195
|
-
|
196
|
-
,
|
197
|
-
retry: function() {
|
198
|
-
init.call(this, this.o, this.fn)
|
199
|
-
}
|
200
|
-
}
|
201
|
-
|
202
|
-
function reqwest(o, fn) {
|
203
|
-
return new Reqwest(o, fn)
|
204
|
-
}
|
205
|
-
|
206
|
-
function enc(v) {
|
207
|
-
return encodeURIComponent(v)
|
208
|
-
}
|
209
|
-
|
210
|
-
function serial(el) {
|
211
|
-
var n = el.name
|
212
|
-
// don't serialize elements that are disabled or without a name
|
213
|
-
if (el.disabled || !n) {
|
214
|
-
return ''
|
215
|
-
}
|
216
|
-
n = enc(n)
|
217
|
-
switch (el.tagName.toLowerCase()) {
|
218
|
-
case 'input':
|
219
|
-
switch (el.type) {
|
220
|
-
// silly wabbit
|
221
|
-
case 'reset':
|
222
|
-
case 'button':
|
223
|
-
case 'image':
|
224
|
-
case 'file':
|
225
|
-
return ''
|
226
|
-
case 'checkbox':
|
227
|
-
case 'radio':
|
228
|
-
return el.checked ? n + '=' + (el.value ? enc(el.value) : true) + '&' : ''
|
229
|
-
default:
|
230
|
-
// text hidden password submit
|
231
|
-
return n + '=' + (el.value ? enc(el.value) : '') + '&'
|
232
|
-
}
|
233
|
-
break;
|
234
|
-
case 'textarea':
|
235
|
-
return n + '=' + enc(el.value) + '&'
|
236
|
-
case 'select':
|
237
|
-
// @todo refactor beyond basic single selected value case
|
238
|
-
return n + '=' + enc(el.options[el.selectedIndex].value) + '&'
|
239
|
-
}
|
240
|
-
return ''
|
241
|
-
}
|
242
|
-
|
243
|
-
reqwest.serialize = function(form) {
|
244
|
-
var fields = [form[byTag]('input'), form[byTag]('select'), form[byTag]('textarea')],
|
245
|
-
serialized = []
|
246
|
-
|
247
|
-
for (var i = 0, l = fields.length; i < l; ++i) {
|
248
|
-
for (var j = 0, l2 = fields[i].length; j < l2; ++j) {
|
249
|
-
serialized.push(serial(fields[i][j]))
|
250
|
-
}
|
251
|
-
}
|
252
|
-
return serialized.join('').replace(/&$/, '')
|
253
|
-
}
|
254
|
-
|
255
|
-
reqwest.serializeArray = function(f) {
|
256
|
-
for (var pairs = this.serialize(f).split('&'), i = 0, l = pairs.length, r = [], o; i < l; i++) {
|
257
|
-
pairs[i] && (o = pairs[i].split('=')) && r.push({
|
258
|
-
name: o[0],
|
259
|
-
value: o[1]
|
260
|
-
})
|
261
|
-
}
|
262
|
-
return r
|
263
|
-
}
|
264
|
-
|
265
|
-
var old = context.reqwest
|
266
|
-
reqwest.noConflict = function() {
|
267
|
-
context.reqwest = old
|
268
|
-
return this
|
269
|
-
}
|
270
|
-
|
271
|
-
// defined as extern for Closure Compilation
|
272
|
-
if (typeof module !== 'undefined') module.exports = reqwest
|
273
|
-
context['reqwest'] = reqwest
|
274
|
-
|
275
|
-
}(this, window)
|
276
|
-
|
277
|
-
;
|
278
|
-
var buildParams, param, prefixes, r20, rbracket;
|
279
|
-
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
280
|
-
(typeof exports !== "undefined" && exports !== null ? exports : this).reqwest = typeof window !== "undefined" && window !== null ? window.reqwest : reqwest;
|
281
|
-
rbracket = /\[\]$/;
|
282
|
-
r20 = /%20/g;
|
283
|
-
param = function(a) {
|
284
|
-
var add, k, name, s, v, value;
|
285
|
-
s = [];
|
286
|
-
add = function(key, value) {
|
287
|
-
if (typeof value === 'function') {
|
288
|
-
value = value();
|
289
|
-
}
|
290
|
-
return s[s.length] = encodeURIComponent(key) + "=" + encodeURIComponent(value);
|
291
|
-
};
|
292
|
-
if (Batman.typeOf(a) === 'Array') {
|
293
|
-
for (value in a) {
|
294
|
-
name = a[value];
|
295
|
-
add(name, value);
|
296
|
-
}
|
297
|
-
} else {
|
298
|
-
for (k in a) {
|
299
|
-
v = a[k];
|
300
|
-
buildParams(k, v, add);
|
301
|
-
}
|
302
|
-
}
|
303
|
-
return s.join("&").replace(r20, "+");
|
304
|
-
};
|
305
|
-
buildParams = function(prefix, obj, add) {
|
306
|
-
var i, name, v, _len, _results, _results2;
|
307
|
-
if (Batman.typeOf(obj) === 'Array') {
|
308
|
-
_results = [];
|
309
|
-
for (i = 0, _len = obj.length; i < _len; i++) {
|
310
|
-
v = obj[i];
|
311
|
-
_results.push(rbracket.test(prefix) ? add(prefix, v) : buildParams(prefix + "[" + (typeof v === "object" || Batman.typeOf(v) === 'Array' ? i : "") + "]", v, add));
|
312
|
-
}
|
313
|
-
return _results;
|
314
|
-
} else if ((obj != null) && typeof obj === "object") {
|
315
|
-
_results2 = [];
|
316
|
-
for (name in obj) {
|
317
|
-
_results2.push(buildParams(prefix + "[" + name + "]", obj[name], add));
|
318
|
-
}
|
319
|
-
return _results2;
|
320
|
-
} else {
|
321
|
-
return add(prefix, obj);
|
322
|
-
}
|
323
|
-
};
|
324
|
-
Batman.Request.prototype.send = function(data) {
|
325
|
-
var options, params, xhr, _ref;
|
326
|
-
if (data == null) {
|
327
|
-
data = this.get('data');
|
328
|
-
}
|
329
|
-
this.fire('loading');
|
330
|
-
options = {
|
331
|
-
url: this.get('url'),
|
332
|
-
method: this.get('method'),
|
333
|
-
type: this.get('type'),
|
334
|
-
headers: {},
|
335
|
-
success: __bind(function(response) {
|
336
|
-
this.set('response', response);
|
337
|
-
this.set('status', (typeof xhr !== "undefined" && xhr !== null ? xhr.status : void 0) || 200);
|
338
|
-
return this.fire('success', response);
|
339
|
-
}, this),
|
340
|
-
error: __bind(function(xhr) {
|
341
|
-
this.set('response', xhr.responseText || xhr.content);
|
342
|
-
this.set('status', xhr.status);
|
343
|
-
xhr.request = this;
|
344
|
-
return this.fire('error', xhr);
|
345
|
-
}, this),
|
346
|
-
complete: __bind(function() {
|
347
|
-
return this.fire('loaded');
|
348
|
-
}, this)
|
349
|
-
};
|
350
|
-
if (!this.get('formData')) {
|
351
|
-
options.headers['Content-type'] = this.get('contentType');
|
352
|
-
}
|
353
|
-
if ((_ref = options.method) === 'PUT' || _ref === 'POST') {
|
354
|
-
if (this.get('formData')) {
|
355
|
-
options.data = this.constructor.objectToFormData(data);
|
356
|
-
} else {
|
357
|
-
options.data = param(data);
|
358
|
-
}
|
359
|
-
} else if (options.method === 'GET' && (params = param(data))) {
|
360
|
-
options.url += "?" + params;
|
361
|
-
}
|
362
|
-
return xhr = (reqwest(options)).request;
|
363
|
-
};
|
364
|
-
prefixes = ['Webkit', 'Moz', 'O', 'ms', ''];
|
365
|
-
Batman.mixins.animation = {
|
366
|
-
initialize: function() {
|
367
|
-
var prefix, _i, _len;
|
368
|
-
for (_i = 0, _len = prefixes.length; _i < _len; _i++) {
|
369
|
-
prefix = prefixes[_i];
|
370
|
-
this.style["" + prefix + "Transform"] = 'scale(0, 0)';
|
371
|
-
this.style.opacity = 0;
|
372
|
-
this.style["" + prefix + "TransitionProperty"] = "" + (prefix ? '-' + prefix.toLowerCase() + '-' : '') + "transform, opacity";
|
373
|
-
this.style["" + prefix + "TransitionDuration"] = "0.8s, 0.55s";
|
374
|
-
this.style["" + prefix + "TransformOrigin"] = "left top";
|
375
|
-
}
|
376
|
-
return this;
|
377
|
-
},
|
378
|
-
show: function(addToParent) {
|
379
|
-
var show, _ref, _ref2;
|
380
|
-
show = __bind(function() {
|
381
|
-
var prefix, _i, _len;
|
382
|
-
this.style.opacity = 1;
|
383
|
-
for (_i = 0, _len = prefixes.length; _i < _len; _i++) {
|
384
|
-
prefix = prefixes[_i];
|
385
|
-
this.style["" + prefix + "Transform"] = 'scale(1, 1)';
|
386
|
-
}
|
387
|
-
return this;
|
388
|
-
}, this);
|
389
|
-
if (addToParent) {
|
390
|
-
if ((_ref = addToParent.append) != null) {
|
391
|
-
_ref.appendChild(this);
|
392
|
-
}
|
393
|
-
if ((_ref2 = addToParent.before) != null) {
|
394
|
-
_ref2.parentNode.insertBefore(this, addToParent.before);
|
395
|
-
}
|
396
|
-
setTimeout(show, 0);
|
397
|
-
} else {
|
398
|
-
show();
|
399
|
-
}
|
400
|
-
return this;
|
401
|
-
},
|
402
|
-
hide: function(shouldRemove) {
|
403
|
-
var prefix, _i, _len;
|
404
|
-
this.style.opacity = 0;
|
405
|
-
for (_i = 0, _len = prefixes.length; _i < _len; _i++) {
|
406
|
-
prefix = prefixes[_i];
|
407
|
-
this.style["" + prefix + "Transform"] = 'scale(0, 0)';
|
408
|
-
}
|
409
|
-
if (shouldRemove) {
|
410
|
-
setTimeout((__bind(function() {
|
411
|
-
var _ref;
|
412
|
-
return (_ref = this.parentNode) != null ? _ref.removeChild(this) : void 0;
|
413
|
-
}, this)), 600);
|
414
|
-
}
|
415
|
-
return this;
|
416
|
-
}
|
417
|
-
};
|
418
|
-
}).call(this);
|