rails-backbone 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- // Backbone.js 0.5.0
1
+ // Backbone.js 0.5.1
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.0';
28
+ Backbone.VERSION = '0.5.1';
29
29
 
30
30
  // Require Underscore, if we're on the server, and it's not already present.
31
31
  var _ = root._;
@@ -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.apply(this, arguments);
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) || this.get(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,16 @@
801
801
  // opened by a non-pushState browser.
802
802
  this.fragment = fragment;
803
803
  historyStarted = true;
804
- var started = this.loadUrl() || this.loadUrl(window.location.hash);
805
- var atRoot = window.location.pathname == this.options.root;
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 = this.options.root + '#' + this.fragment;
809
- } else if (this._wantsPushState && this._hasPushState && atRoot && window.location.hash) {
810
- this.navigate(window.location.hash);
811
- } else {
812
- return started;
808
+ window.location.replace(this.options.root + '#' + this.fragment);
809
+ } else if (this._wantsPushState && this._hasPushState && atRoot && loc.hash) {
810
+ this.fragment = loc.hash.replace(hashStrip, '');
811
+ window.history.replaceState({}, document.title, loc.protocol + '//' + loc.host + this.options.root + this.fragment);
813
812
  }
813
+ return this.loadUrl();
814
814
  },
815
815
 
816
816
  // Add a route to be tested when the fragment changes. Routes added later may
@@ -847,18 +847,18 @@
847
847
  // URL-encoding the fragment in advance. This does not trigger
848
848
  // a `hashchange` event.
849
849
  navigate : function(fragment, triggerRoute) {
850
- fragment = (fragment || '').replace(hashStrip, '');
851
- if (this.fragment == fragment || this.fragment == decodeURIComponent(fragment)) return;
850
+ var frag = (fragment || '').replace(hashStrip, '');
851
+ if (this.fragment == frag || this.fragment == decodeURIComponent(frag)) return;
852
852
  if (this._hasPushState) {
853
853
  var loc = window.location;
854
- if (fragment.indexOf(this.options.root) != 0) fragment = this.options.root + fragment;
855
- this.fragment = fragment;
856
- window.history.pushState({}, document.title, loc.protocol + '//' + loc.host + fragment);
854
+ if (frag.indexOf(this.options.root) != 0) frag = this.options.root + frag;
855
+ this.fragment = frag;
856
+ window.history.pushState({}, document.title, loc.protocol + '//' + loc.host + frag);
857
857
  } else {
858
- window.location.hash = this.fragment = fragment;
859
- if (this.iframe && (fragment != this.getFragment(this.iframe.location.hash))) {
858
+ window.location.hash = this.fragment = frag;
859
+ if (this.iframe && (frag != this.getFragment(this.iframe.location.hash))) {
860
860
  this.iframe.document.open().close();
861
- this.iframe.location.hash = fragment;
861
+ this.iframe.location.hash = frag;
862
862
  }
863
863
  }
864
864
  if (triggerRoute) this.loadUrl(fragment);
@@ -1143,7 +1143,7 @@
1143
1143
 
1144
1144
  // Helper function to escape a string for HTML rendering.
1145
1145
  var escapeHTML = function(string) {
1146
- return string.replace(/&(?!\w+;|#\d+;|#x[\da-f]+;)/gi, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#x27').replace(/\//g,'&#x2F;');
1146
+ return string.replace(/&(?!\w+;|#\d+;|#x[\da-f]+;)/gi, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#x27;').replace(/\//g,'&#x2F;');
1147
1147
  };
1148
1148
 
1149
1149
  }).call(this);
@@ -55,7 +55,8 @@
55
55
  module.exports = _;
56
56
  _._ = _;
57
57
  } else {
58
- root._ = _;
58
+ // Exported as a string, for Closure Compiler "advanced" mode.
59
+ root['_'] = _;
59
60
  }
60
61
 
61
62
  // Current version.
@@ -73,7 +74,7 @@
73
74
  obj.forEach(iterator, context);
74
75
  } else if (_.isNumber(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) {
@@ -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
  };
@@ -502,7 +513,7 @@
502
513
  var funcs = slice.call(arguments);
503
514
  return function() {
504
515
  var args = slice.call(arguments);
505
- for (var i=funcs.length-1; i >= 0; i--) {
516
+ for (var i = funcs.length - 1; i >= 0; i--) {
506
517
  args = [funcs[i].apply(this, args)];
507
518
  }
508
519
  return args[0];
@@ -589,6 +600,7 @@
589
600
  if (b._chain) b = b._wrapped;
590
601
  // One of them implements an isEqual()?
591
602
  if (a.isEqual) return a.isEqual(b);
603
+ if (b.isEqual) return b.isEqual(a);
592
604
  // Check dates' integer values.
593
605
  if (_.isDate(a) && _.isDate(b)) return a.getTime() === b.getTime();
594
606
  // Both are NaN?
@@ -630,6 +642,11 @@
630
642
  return toString.call(obj) === '[object Array]';
631
643
  };
632
644
 
645
+ // Is a given variable an object?
646
+ _.isObject = function(obj) {
647
+ return obj === Object(obj);
648
+ };
649
+
633
650
  // Is a given variable an arguments object?
634
651
  _.isArguments = function(obj) {
635
652
  return !!(obj && hasOwnProperty.call(obj, 'callee'));
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rails-backbone
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.5.0
5
+ version: 0.5.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ryan Fitzgerald
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-07-04 00:00:00 -04:00
14
+ date: 2011-07-08 00:00:00 -04:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
@@ -21,7 +21,7 @@ dependencies:
21
21
  requirements:
22
22
  - - ~>
23
23
  - !ruby/object:Gem::Version
24
- version: "3.1"
24
+ version: 3.1.0.rc4
25
25
  type: :runtime
26
26
  prerelease: false
27
27
  version_requirements: *id001
@@ -32,7 +32,7 @@ dependencies:
32
32
  requirements:
33
33
  - - ~>
34
34
  - !ruby/object:Gem::Version
35
- version: "2.2"
35
+ version: 2.2.0
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: *id002
@@ -103,7 +103,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
103
103
  requirements:
104
104
  - - ">="
105
105
  - !ruby/object:Gem::Version
106
- hash: -730083928370135301
106
+ hash: -4012719302354285017
107
107
  segments:
108
108
  - 0
109
109
  version: "0"
@@ -112,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  requirements:
113
113
  - - ">="
114
114
  - !ruby/object:Gem::Version
115
- hash: -730083928370135301
115
+ hash: -4012719302354285017
116
116
  segments:
117
117
  - 0
118
118
  version: "0"