Update vendors.

Former-commit-id: fddaef2be532e30f197f8bdff70dc6ec9bfa3cfc
This commit is contained in:
John-David Dalton
2012-09-18 23:42:52 -07:00
parent f4ba0e1191
commit 00cfb95971
8 changed files with 176 additions and 115 deletions

View File

@@ -735,13 +735,7 @@
throw new Error('Cannot sort a set without a comparator');
}
// If provided an attribute name, use it to sort the collection.
if (_.isString(this.comparator)) {
var attr = this.comparator;
this.comparator = function(model){ return model.get(attr); };
}
if (this.comparator.length === 1) {
if (_.isString(this.comparator) || this.comparator.length === 1) {
this.models = this.sortBy(this.comparator, this);
} else {
this.models.sort(_.bind(this.comparator, this));
@@ -753,7 +747,7 @@
// Pluck an attribute from each model in the collection.
pluck: function(attr) {
return _.map(this.models, function(model){ return model.get(attr); });
return _.invoke(this.models, 'get', attr);
},
// When you have more items than you want to add or remove individually,
@@ -867,9 +861,9 @@
var methods = ['forEach', 'each', 'map', 'collect', 'reduce', 'foldl',
'inject', 'reduceRight', 'foldr', 'find', 'detect', 'filter', 'select',
'reject', 'every', 'all', 'some', 'any', 'include', 'contains', 'invoke',
'max', 'min', 'sortBy', 'sortedIndex', 'toArray', 'size', 'first', 'head',
'take', 'initial', 'rest', 'tail', 'last', 'without', 'indexOf', 'shuffle',
'lastIndexOf', 'isEmpty', 'groupBy'];
'max', 'min', 'sortedIndex', 'toArray', 'size', 'first', 'head', 'take',
'initial', 'rest', 'tail', 'last', 'without', 'indexOf', 'shuffle',
'lastIndexOf', 'isEmpty'];
// Mix in each Underscore method as a proxy to `Collection#models`.
_.each(methods, function(method) {
@@ -880,6 +874,19 @@
};
});
// Underscore methods that take a property name as an argument.
var attributeMethods = ['groupBy', 'countBy', 'sortBy'];
// Use attributes instead of properties.
_.each(attributeMethods, function(method) {
Collection.prototype[method] = function(value, context) {
var iterator = _.isFunction(value) ? value : function(model) {
return model.get(value);
};
return _[method](this.models, iterator, context);
};
});
// Backbone.Router
// -------------------
@@ -964,11 +971,15 @@
// Handles cross-browser history management, based on URL fragments. If the
// browser does not support `onhashchange`, falls back to polling.
var History = Backbone.History = function(options) {
var History = Backbone.History = function() {
this.handlers = [];
_.bindAll(this, 'checkUrl');
this.location = options && options.location || root.location;
this.history = options && options.history || root.history;
// #1653 - Ensure that `History` can be used outside of the browser.
if (typeof window !== 'undefined') {
this.location = window.location;
this.history = window.history;
}
};
// Cached regex for cleaning leading hashes and slashes.
@@ -1160,7 +1171,8 @@
var href = location.href.replace(/(javascript:|#).*$/, '');
location.replace(href + '#' + fragment);
} else {
location.hash = fragment;
// #1649 - Some browsers require that `hash` contains a leading #.
location.hash = '#' + fragment;
}
}