backbone-rails 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +11 -3
- data/vendor/assets/javascripts/backbone-rails.js +3 -0
- data/vendor/assets/javascripts/backbone.js +35 -30
- data/vendor/assets/javascripts/underscore.js +49 -17
- metadata +3 -2
data/README.md
CHANGED
@@ -15,12 +15,20 @@ Add it to your Gemfile:
|
|
15
15
|
|
16
16
|
gem 'backbone-rails'
|
17
17
|
|
18
|
-
Require
|
18
|
+
Require backbone and its dependencies as a group in `app/assets/javascripts/application.js.coffee`:
|
19
|
+
|
20
|
+
#= require backbone-rails
|
21
|
+
|
22
|
+
With pure javascript, the lines would look like `app/assets/javascripts/application.js`:
|
23
|
+
|
24
|
+
//= require backbone-rails
|
25
|
+
|
26
|
+
Or if you need to, require what you need in `app/assets/javascripts/application.js.coffee`:
|
19
27
|
|
20
28
|
#= require json2
|
21
29
|
#= require underscore
|
22
30
|
#= require backbone
|
23
|
-
|
31
|
+
|
24
32
|
With pure javascript, the lines would look like `app/assets/javascripts/application.js`:
|
25
33
|
|
26
34
|
//= require json2
|
@@ -37,4 +45,4 @@ The gem will follow backbone versioning.
|
|
37
45
|
|
38
46
|
## Contributors
|
39
47
|
|
40
|
-
* [John Bintz](https://github.com/johnbintz) (Support for Rails 3.0 via generators)
|
48
|
+
* [John Bintz](https://github.com/johnbintz) (Support for Rails 3.0 via generators)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
// Backbone.js 0.5.
|
1
|
+
// Backbone.js 0.5.2
|
2
2
|
// (c) 2010 Jeremy Ashkenas, DocumentCloud Inc.
|
3
3
|
// Backbone may be freely distributed under the MIT license.
|
4
4
|
// For all details and documentation:
|
@@ -25,7 +25,7 @@
|
|
25
25
|
}
|
26
26
|
|
27
27
|
// Current version of the library. Keep in sync with `package.json`.
|
28
|
-
Backbone.VERSION = '0.5.
|
28
|
+
Backbone.VERSION = '0.5.2';
|
29
29
|
|
30
30
|
// Require Underscore, if we're on the server, and it's not already present.
|
31
31
|
var _ = root._;
|
@@ -68,10 +68,10 @@
|
|
68
68
|
|
69
69
|
// Bind an event, specified by a string name, `ev`, to a `callback` function.
|
70
70
|
// Passing `"all"` will bind the callback to all events fired.
|
71
|
-
bind : function(ev, callback) {
|
71
|
+
bind : function(ev, callback, context) {
|
72
72
|
var calls = this._callbacks || (this._callbacks = {});
|
73
73
|
var list = calls[ev] || (calls[ev] = []);
|
74
|
-
list.push(callback);
|
74
|
+
list.push([callback, context]);
|
75
75
|
return this;
|
76
76
|
},
|
77
77
|
|
@@ -89,7 +89,7 @@
|
|
89
89
|
var list = calls[ev];
|
90
90
|
if (!list) return this;
|
91
91
|
for (var i = 0, l = list.length; i < l; i++) {
|
92
|
-
if (callback === list[i]) {
|
92
|
+
if (list[i] && callback === list[i][0]) {
|
93
93
|
list[i] = null;
|
94
94
|
break;
|
95
95
|
}
|
@@ -114,7 +114,7 @@
|
|
114
114
|
list.splice(i, 1); i--; l--;
|
115
115
|
} else {
|
116
116
|
args = both ? Array.prototype.slice.call(arguments, 1) : arguments;
|
117
|
-
callback.apply(this, args);
|
117
|
+
callback[0].apply(callback[1] || this, args);
|
118
118
|
}
|
119
119
|
}
|
120
120
|
}
|
@@ -133,7 +133,7 @@
|
|
133
133
|
var defaults;
|
134
134
|
attributes || (attributes = {});
|
135
135
|
if (defaults = this.defaults) {
|
136
|
-
if (_.isFunction(defaults)) defaults = defaults();
|
136
|
+
if (_.isFunction(defaults)) defaults = defaults.call(this);
|
137
137
|
attributes = _.extend({}, defaults, attributes);
|
138
138
|
}
|
139
139
|
this.attributes = {};
|
@@ -143,7 +143,7 @@
|
|
143
143
|
this._changed = false;
|
144
144
|
this._previousAttributes = _.clone(this.attributes);
|
145
145
|
if (options && options.collection) this.collection = options.collection;
|
146
|
-
this.initialize
|
146
|
+
this.initialize(attributes, options);
|
147
147
|
};
|
148
148
|
|
149
149
|
// Attach all inheritable methods to the Model prototype.
|
@@ -582,7 +582,7 @@
|
|
582
582
|
options || (options = {});
|
583
583
|
model = this._prepareModel(model, options);
|
584
584
|
if (!model) return false;
|
585
|
-
var already = this.getByCid(model)
|
585
|
+
var already = this.getByCid(model);
|
586
586
|
if (already) throw new Error(["Can't add the same model to a set twice", already.id]);
|
587
587
|
this._byId[model.id] = model;
|
588
588
|
this._byCid[model.cid] = model;
|
@@ -640,7 +640,7 @@
|
|
640
640
|
// Underscore methods that we want to implement on the Collection.
|
641
641
|
var methods = ['forEach', 'each', 'map', 'reduce', 'reduceRight', 'find', 'detect',
|
642
642
|
'filter', 'select', 'reject', 'every', 'all', 'some', 'any', 'include',
|
643
|
-
'invoke', 'max', 'min', 'sortBy', 'sortedIndex', 'toArray', 'size',
|
643
|
+
'contains', 'invoke', 'max', 'min', 'sortBy', 'sortedIndex', 'toArray', 'size',
|
644
644
|
'first', 'rest', 'last', 'without', 'indexOf', 'lastIndexOf', 'isEmpty'];
|
645
645
|
|
646
646
|
// Mix in each Underscore method as a proxy to `Collection#models`.
|
@@ -738,7 +738,7 @@
|
|
738
738
|
};
|
739
739
|
|
740
740
|
// Cached regex for cleaning hashes.
|
741
|
-
var hashStrip =
|
741
|
+
var hashStrip = /^#*/;
|
742
742
|
|
743
743
|
// Cached regex for detecting MSIE.
|
744
744
|
var isExplorer = /msie [\w.]+/;
|
@@ -801,16 +801,18 @@
|
|
801
801
|
// opened by a non-pushState browser.
|
802
802
|
this.fragment = fragment;
|
803
803
|
historyStarted = true;
|
804
|
-
var
|
805
|
-
var atRoot =
|
804
|
+
var loc = window.location;
|
805
|
+
var atRoot = loc.pathname == this.options.root;
|
806
806
|
if (this._wantsPushState && !this._hasPushState && !atRoot) {
|
807
807
|
this.fragment = this.getFragment(null, true);
|
808
|
-
window.location
|
809
|
-
|
810
|
-
|
811
|
-
} else {
|
812
|
-
|
808
|
+
window.location.replace(this.options.root + '#' + this.fragment);
|
809
|
+
// Return immediately as browser will do redirect to new url
|
810
|
+
return true;
|
811
|
+
} else if (this._wantsPushState && this._hasPushState && atRoot && loc.hash) {
|
812
|
+
this.fragment = loc.hash.replace(hashStrip, '');
|
813
|
+
window.history.replaceState({}, document.title, loc.protocol + '//' + loc.host + this.options.root + this.fragment);
|
813
814
|
}
|
815
|
+
return this.loadUrl();
|
814
816
|
},
|
815
817
|
|
816
818
|
// Add a route to be tested when the fragment changes. Routes added later may
|
@@ -847,18 +849,18 @@
|
|
847
849
|
// URL-encoding the fragment in advance. This does not trigger
|
848
850
|
// a `hashchange` event.
|
849
851
|
navigate : function(fragment, triggerRoute) {
|
850
|
-
|
851
|
-
if (this.fragment ==
|
852
|
+
var frag = (fragment || '').replace(hashStrip, '');
|
853
|
+
if (this.fragment == frag || this.fragment == decodeURIComponent(frag)) return;
|
852
854
|
if (this._hasPushState) {
|
853
855
|
var loc = window.location;
|
854
|
-
if (
|
855
|
-
this.fragment =
|
856
|
-
window.history.pushState({}, document.title, loc.protocol + '//' + loc.host +
|
856
|
+
if (frag.indexOf(this.options.root) != 0) frag = this.options.root + frag;
|
857
|
+
this.fragment = frag;
|
858
|
+
window.history.pushState({}, document.title, loc.protocol + '//' + loc.host + frag);
|
857
859
|
} else {
|
858
|
-
window.location.hash = this.fragment =
|
859
|
-
if (this.iframe && (
|
860
|
+
window.location.hash = this.fragment = frag;
|
861
|
+
if (this.iframe && (frag != this.getFragment(this.iframe.location.hash))) {
|
860
862
|
this.iframe.document.open().close();
|
861
|
-
this.iframe.location.hash =
|
863
|
+
this.iframe.location.hash = frag;
|
862
864
|
}
|
863
865
|
}
|
864
866
|
if (triggerRoute) this.loadUrl(fragment);
|
@@ -1035,8 +1037,7 @@
|
|
1035
1037
|
// Default JSON-request options.
|
1036
1038
|
var params = _.extend({
|
1037
1039
|
type: type,
|
1038
|
-
dataType: 'json'
|
1039
|
-
processData: false
|
1040
|
+
dataType: 'json'
|
1040
1041
|
}, options);
|
1041
1042
|
|
1042
1043
|
// Ensure that we have a URL.
|
@@ -1053,7 +1054,6 @@
|
|
1053
1054
|
// For older servers, emulate JSON by encoding the request into an HTML-form.
|
1054
1055
|
if (Backbone.emulateJSON) {
|
1055
1056
|
params.contentType = 'application/x-www-form-urlencoded';
|
1056
|
-
params.processData = true;
|
1057
1057
|
params.data = params.data ? {model : params.data} : {};
|
1058
1058
|
}
|
1059
1059
|
|
@@ -1069,6 +1069,11 @@
|
|
1069
1069
|
}
|
1070
1070
|
}
|
1071
1071
|
|
1072
|
+
// Don't process data on a non-GET request.
|
1073
|
+
if (params.type !== 'GET') {
|
1074
|
+
params.processData = false;
|
1075
|
+
}
|
1076
|
+
|
1072
1077
|
// Make the request.
|
1073
1078
|
return $.ajax(params);
|
1074
1079
|
};
|
@@ -1143,7 +1148,7 @@
|
|
1143
1148
|
|
1144
1149
|
// Helper function to escape a string for HTML rendering.
|
1145
1150
|
var escapeHTML = function(string) {
|
1146
|
-
return string.replace(/&(?!\w+;|#\d+;|#x[\da-f]+;)/gi, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''').replace(/\//g,'/');
|
1151
|
+
return string.replace(/&(?!\w+;|#\d+;|#x[\da-f]+;)/gi, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''').replace(/\//g,'/');
|
1147
1152
|
};
|
1148
1153
|
|
1149
1154
|
}).call(this);
|
@@ -1,4 +1,4 @@
|
|
1
|
-
// Underscore.js 1.1.
|
1
|
+
// Underscore.js 1.1.7
|
2
2
|
// (c) 2011 Jeremy Ashkenas, DocumentCloud Inc.
|
3
3
|
// Underscore is freely distributable under the MIT license.
|
4
4
|
// Portions of Underscore are inspired or borrowed from Prototype,
|
@@ -55,25 +55,26 @@
|
|
55
55
|
module.exports = _;
|
56
56
|
_._ = _;
|
57
57
|
} else {
|
58
|
-
|
58
|
+
// Exported as a string, for Closure Compiler "advanced" mode.
|
59
|
+
root['_'] = _;
|
59
60
|
}
|
60
61
|
|
61
62
|
// Current version.
|
62
|
-
_.VERSION = '1.1.
|
63
|
+
_.VERSION = '1.1.7';
|
63
64
|
|
64
65
|
// Collection Functions
|
65
66
|
// --------------------
|
66
67
|
|
67
68
|
// The cornerstone, an `each` implementation, aka `forEach`.
|
68
|
-
// Handles objects
|
69
|
+
// Handles objects with the built-in `forEach`, arrays, and raw objects.
|
69
70
|
// Delegates to **ECMAScript 5**'s native `forEach` if available.
|
70
71
|
var each = _.each = _.forEach = function(obj, iterator, context) {
|
71
72
|
if (obj == null) return;
|
72
73
|
if (nativeForEach && obj.forEach === nativeForEach) {
|
73
74
|
obj.forEach(iterator, context);
|
74
|
-
} else if (
|
75
|
+
} else if (obj.length === +obj.length) {
|
75
76
|
for (var i = 0, l = obj.length; i < l; i++) {
|
76
|
-
if (iterator.call(context, obj[i], i, obj) === breaker) return;
|
77
|
+
if (i in obj && iterator.call(context, obj[i], i, obj) === breaker) return;
|
77
78
|
}
|
78
79
|
} else {
|
79
80
|
for (var key in obj) {
|
@@ -106,7 +107,7 @@
|
|
106
107
|
return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator);
|
107
108
|
}
|
108
109
|
each(obj, function(value, index, list) {
|
109
|
-
if (!initial
|
110
|
+
if (!initial) {
|
110
111
|
memo = value;
|
111
112
|
initial = true;
|
112
113
|
} else {
|
@@ -181,14 +182,14 @@
|
|
181
182
|
// Delegates to **ECMAScript 5**'s native `some` if available.
|
182
183
|
// Aliased as `any`.
|
183
184
|
var any = _.some = _.any = function(obj, iterator, context) {
|
184
|
-
iterator
|
185
|
+
iterator = iterator || _.identity;
|
185
186
|
var result = false;
|
186
187
|
if (obj == null) return result;
|
187
188
|
if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context);
|
188
189
|
each(obj, function(value, index, list) {
|
189
|
-
if (result
|
190
|
+
if (result |= iterator.call(context, value, index, list)) return breaker;
|
190
191
|
});
|
191
|
-
return result;
|
192
|
+
return !!result;
|
192
193
|
};
|
193
194
|
|
194
195
|
// Determine if a given value is included in the array or object using `===`.
|
@@ -251,6 +252,16 @@
|
|
251
252
|
}), 'value');
|
252
253
|
};
|
253
254
|
|
255
|
+
// Groups the object's values by a criterion produced by an iterator
|
256
|
+
_.groupBy = function(obj, iterator) {
|
257
|
+
var result = {};
|
258
|
+
each(obj, function(value, index) {
|
259
|
+
var key = iterator(value, index);
|
260
|
+
(result[key] || (result[key] = [])).push(value);
|
261
|
+
});
|
262
|
+
return result;
|
263
|
+
};
|
264
|
+
|
254
265
|
// Use a comparator function to figure out at what index an object should
|
255
266
|
// be inserted so as to maintain order. Uses binary search.
|
256
267
|
_.sortedIndex = function(array, obj, iterator) {
|
@@ -267,7 +278,7 @@
|
|
267
278
|
_.toArray = function(iterable) {
|
268
279
|
if (!iterable) return [];
|
269
280
|
if (iterable.toArray) return iterable.toArray();
|
270
|
-
if (_.isArray(iterable)) return iterable;
|
281
|
+
if (_.isArray(iterable)) return slice.call(iterable);
|
271
282
|
if (_.isArguments(iterable)) return slice.call(iterable);
|
272
283
|
return _.values(iterable);
|
273
284
|
};
|
@@ -316,8 +327,7 @@
|
|
316
327
|
|
317
328
|
// Return a version of the array that does not contain the specified value(s).
|
318
329
|
_.without = function(array) {
|
319
|
-
|
320
|
-
return _.filter(array, function(value){ return !_.include(values, value); });
|
330
|
+
return _.difference(array, slice.call(arguments, 1));
|
321
331
|
};
|
322
332
|
|
323
333
|
// Produce a duplicate-free version of the array. If the array has already
|
@@ -330,9 +340,15 @@
|
|
330
340
|
}, []);
|
331
341
|
};
|
332
342
|
|
343
|
+
// Produce an array that contains the union: each distinct element from all of
|
344
|
+
// the passed-in arrays.
|
345
|
+
_.union = function() {
|
346
|
+
return _.uniq(_.flatten(arguments));
|
347
|
+
};
|
348
|
+
|
333
349
|
// Produce an array that contains every item shared between all the
|
334
|
-
// passed-in arrays.
|
335
|
-
_.intersect = function(array) {
|
350
|
+
// passed-in arrays. (Aliased as "intersect" for back-compat.)
|
351
|
+
_.intersection = _.intersect = function(array) {
|
336
352
|
var rest = slice.call(arguments, 1);
|
337
353
|
return _.filter(_.uniq(array), function(item) {
|
338
354
|
return _.every(rest, function(other) {
|
@@ -341,6 +357,12 @@
|
|
341
357
|
});
|
342
358
|
};
|
343
359
|
|
360
|
+
// Take the difference between one array and another.
|
361
|
+
// Only the elements present in just the first array will remain.
|
362
|
+
_.difference = function(array, other) {
|
363
|
+
return _.filter(array, function(value){ return !_.include(other, value); });
|
364
|
+
};
|
365
|
+
|
344
366
|
// Zip together multiple lists into a single array -- elements that share
|
345
367
|
// an index go together.
|
346
368
|
_.zip = function() {
|
@@ -502,7 +524,7 @@
|
|
502
524
|
var funcs = slice.call(arguments);
|
503
525
|
return function() {
|
504
526
|
var args = slice.call(arguments);
|
505
|
-
for (var i=funcs.length-1; i >= 0; i--) {
|
527
|
+
for (var i = funcs.length - 1; i >= 0; i--) {
|
506
528
|
args = [funcs[i].apply(this, args)];
|
507
529
|
}
|
508
530
|
return args[0];
|
@@ -537,7 +559,11 @@
|
|
537
559
|
// Return a sorted list of the function names available on the object.
|
538
560
|
// Aliased as `methods`
|
539
561
|
_.functions = _.methods = function(obj) {
|
540
|
-
|
562
|
+
var names = [];
|
563
|
+
for (var key in obj) {
|
564
|
+
if (_.isFunction(obj[key])) names.push(key);
|
565
|
+
}
|
566
|
+
return names.sort();
|
541
567
|
};
|
542
568
|
|
543
569
|
// Extend a given object with all the properties in passed-in object(s).
|
@@ -589,6 +615,7 @@
|
|
589
615
|
if (b._chain) b = b._wrapped;
|
590
616
|
// One of them implements an isEqual()?
|
591
617
|
if (a.isEqual) return a.isEqual(b);
|
618
|
+
if (b.isEqual) return b.isEqual(a);
|
592
619
|
// Check dates' integer values.
|
593
620
|
if (_.isDate(a) && _.isDate(b)) return a.getTime() === b.getTime();
|
594
621
|
// Both are NaN?
|
@@ -630,6 +657,11 @@
|
|
630
657
|
return toString.call(obj) === '[object Array]';
|
631
658
|
};
|
632
659
|
|
660
|
+
// Is a given variable an object?
|
661
|
+
_.isObject = function(obj) {
|
662
|
+
return obj === Object(obj);
|
663
|
+
};
|
664
|
+
|
633
665
|
// Is a given variable an arguments object?
|
634
666
|
_.isArguments = function(obj) {
|
635
667
|
return !!(obj && hasOwnProperty.call(obj, 'callee'));
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: backbone-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.5.
|
5
|
+
version: 0.5.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Alexander Flatter
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-07
|
13
|
+
date: 2011-08-07 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -39,6 +39,7 @@ files:
|
|
39
39
|
- lib/backbone-rails/railtie.rb
|
40
40
|
- vendor/assets/javascripts/underscore.js
|
41
41
|
- vendor/assets/javascripts/backbone.js
|
42
|
+
- vendor/assets/javascripts/backbone-rails.js
|
42
43
|
- vendor/assets/javascripts/json2.js
|
43
44
|
- vendor/assets/javascripts/backbone.js.old
|
44
45
|
- MIT-LICENSE
|