mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 09:47:48 +00:00
Update vendors, rebuild minified files, update docs/license.
Former-commit-id: 689793b6e5c4bbae917e726dc646902c697ce3a7
This commit is contained in:
127
vendor/backbone/backbone.js
vendored
127
vendor/backbone/backbone.js
vendored
@@ -1,4 +1,4 @@
|
||||
// Backbone.js 0.9.2
|
||||
// Backbone.js 0.9.9-pre
|
||||
|
||||
// (c) 2010-2012 Jeremy Ashkenas, DocumentCloud Inc.
|
||||
// Backbone may be freely distributed under the MIT license.
|
||||
@@ -34,7 +34,7 @@
|
||||
}
|
||||
|
||||
// Current version of the library. Keep in sync with `package.json`.
|
||||
Backbone.VERSION = '0.9.2';
|
||||
Backbone.VERSION = '0.9.9-pre';
|
||||
|
||||
// Require Underscore, if we're on the server, and it's not already present.
|
||||
var _ = root._;
|
||||
@@ -67,6 +67,9 @@
|
||||
// Regular expression used to split event strings
|
||||
var eventSplitter = /\s+/;
|
||||
|
||||
// Internal flag used to set event callbacks `once`.
|
||||
var once = false;
|
||||
|
||||
// A module that can be mixed in to *any object* in order to provide it with
|
||||
// custom events. You may bind with `on` or remove with `off` callback functions
|
||||
// to an event; `trigger`-ing an event fires all callbacks in succession.
|
||||
@@ -81,6 +84,13 @@
|
||||
// Bind one or more space separated events, `events`, to a `callback`
|
||||
// function. Passing `"all"` will bind the callback to all events fired.
|
||||
on: function(events, callback, context) {
|
||||
if (_.isObject(events)) {
|
||||
for (var key in events) {
|
||||
this.on(key, events[key], callback);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
var calls, event, list;
|
||||
if (!callback) return this;
|
||||
|
||||
@@ -89,16 +99,32 @@
|
||||
|
||||
while (event = events.shift()) {
|
||||
list = calls[event] || (calls[event] = []);
|
||||
list.push(callback, context);
|
||||
list.push(callback, context, once ? {} : null);
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
// Bind events to only be triggered a single time. After the first time
|
||||
// the callback is invoked, it will be removed.
|
||||
once: function(events, callback, context) {
|
||||
once = true;
|
||||
this.on(events, callback, context);
|
||||
once = false;
|
||||
return this;
|
||||
},
|
||||
|
||||
// Remove one or many callbacks. If `context` is null, removes all callbacks
|
||||
// with that function. If `callback` is null, removes all callbacks for the
|
||||
// event. If `events` is null, removes all bound callbacks for all events.
|
||||
off: function(events, callback, context) {
|
||||
if (_.isObject(events)) {
|
||||
for (var key in events) {
|
||||
this.off(key, events[key], callback);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
var event, calls, list, i;
|
||||
|
||||
// No events, or removing *all* events.
|
||||
@@ -117,9 +143,9 @@
|
||||
continue;
|
||||
}
|
||||
|
||||
for (i = list.length - 2; i >= 0; i -= 2) {
|
||||
for (i = list.length - 3; i >= 0; i -= 3) {
|
||||
if (!(callback && list[i] !== callback || context && list[i + 1] !== context)) {
|
||||
list.splice(i, 2);
|
||||
list.splice(i, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -132,7 +158,7 @@
|
||||
// (unless you're listening on `"all"`, which will cause your callback to
|
||||
// receive the true name of the event as the first argument).
|
||||
trigger: function(events) {
|
||||
var event, calls, list, i, length, args, all, rest;
|
||||
var event, calls, list, i, length, args, all, rest, callback, context, onced;
|
||||
if (!(calls = this._callbacks)) return this;
|
||||
|
||||
rest = [];
|
||||
@@ -153,15 +179,18 @@
|
||||
|
||||
// Execute event callbacks.
|
||||
if (list) {
|
||||
for (i = 0, length = list.length; i < length; i += 2) {
|
||||
list[i].apply(list[i + 1] || this, rest);
|
||||
for (i = 0, length = list.length; i < length; i += 3) {
|
||||
callback = list[i], context = list[i + 1], onced = list[i + 2];
|
||||
if (onced) calls[event].splice(i, 3);
|
||||
if (!onced || !onced.dead) callback.apply(context || this, rest);
|
||||
if (onced) onced.dead = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Execute "all" callbacks.
|
||||
if (all) {
|
||||
args = [event].concat(rest);
|
||||
for (i = 0, length = all.length; i < length; i += 2) {
|
||||
for (i = 0, length = all.length; i < length; i += 3) {
|
||||
all[i].apply(all[i + 1] || this, args);
|
||||
}
|
||||
}
|
||||
@@ -176,6 +205,10 @@
|
||||
Events.bind = Events.on;
|
||||
Events.unbind = Events.off;
|
||||
|
||||
// Allow the `Backbone` object to serve as a global event bus, for folks who
|
||||
// want global "pubsub" in a convenient place.
|
||||
_.extend(Backbone, Events);
|
||||
|
||||
// Backbone.Model
|
||||
// --------------
|
||||
|
||||
@@ -390,7 +423,9 @@
|
||||
};
|
||||
|
||||
// Finish configuring and sending the Ajax request.
|
||||
var xhr = this.sync(this.isNew() ? 'create' : 'update', this, options);
|
||||
var method = this.isNew() ? 'create' : (options.patch ? 'patch' : 'update');
|
||||
if (method == 'patch') options.attrs = attrs;
|
||||
var xhr = this.sync(method, this, options);
|
||||
|
||||
// When using `wait`, reset attributes to original values unless
|
||||
// `success` has been called already.
|
||||
@@ -565,7 +600,7 @@
|
||||
// returning `true` if all is well. If a specific `error` callback has
|
||||
// been passed, call that instead of firing the general `"error"` event.
|
||||
_validate: function(attrs, options) {
|
||||
if (options && options.silent || !this.validate) return true;
|
||||
if (!this.validate) return true;
|
||||
attrs = _.extend({}, this.attributes, attrs);
|
||||
var error = this.validate(attrs, options);
|
||||
if (!error) return true;
|
||||
@@ -588,10 +623,7 @@
|
||||
if (options.comparator !== void 0) this.comparator = options.comparator;
|
||||
this._reset();
|
||||
this.initialize.apply(this, arguments);
|
||||
if (models) {
|
||||
if (options.parse) models = this.parse(models);
|
||||
this.reset(models, {silent: true, parse: options.parse});
|
||||
}
|
||||
if (models) this.reset(models, _.extend({silent: true}, options));
|
||||
};
|
||||
|
||||
// Define the Collection's inheritable methods.
|
||||
@@ -679,7 +711,7 @@
|
||||
options || (options = {});
|
||||
models = _.isArray(models) ? models.slice() : [models];
|
||||
for (i = 0, l = models.length; i < l; i++) {
|
||||
model = this.getByCid(models[i]) || this.get(models[i]);
|
||||
model = this.get(models[i]);
|
||||
if (!model) continue;
|
||||
delete this._byId[model.id];
|
||||
delete this._byCid[model.cid];
|
||||
@@ -729,14 +761,9 @@
|
||||
},
|
||||
|
||||
// Get a model from the set by id.
|
||||
get: function(id) {
|
||||
if (id == null) return void 0;
|
||||
return this._byId[id.id != null ? id.id : id];
|
||||
},
|
||||
|
||||
// Get a model from the set by client id.
|
||||
getByCid: function(cid) {
|
||||
return cid && this._byCid[cid.cid || cid];
|
||||
get: function(obj) {
|
||||
if (obj == null) return void 0;
|
||||
return this._byId[obj.id != null ? obj.id : obj] || this._byCid[obj.cid || obj];
|
||||
},
|
||||
|
||||
// Get the model at the given index.
|
||||
@@ -769,7 +796,7 @@
|
||||
this.models.sort(_.bind(this.comparator, this));
|
||||
}
|
||||
|
||||
if (!options || !options.silent) this.trigger('reset', this, options);
|
||||
if (!options || !options.silent) this.trigger('sort', this, options);
|
||||
return this;
|
||||
},
|
||||
|
||||
@@ -778,16 +805,46 @@
|
||||
return _.invoke(this.models, 'get', attr);
|
||||
},
|
||||
|
||||
// Smartly update a collection with a change set of models, adding,
|
||||
// removing, and merging as necessary.
|
||||
update: function(models, options) {
|
||||
var model, i, l, id, cid, existing;
|
||||
var add = [], remove = [];
|
||||
options = _.extend({add: true, merge: true, remove: false}, options);
|
||||
|
||||
// Determine which models to add and merge, and which to remove.
|
||||
for (i = 0, l = models.length; i < l; i++) {
|
||||
model = models[i];
|
||||
existing = this.get(model);
|
||||
if (options.add || options.merge && existing) add.push(model);
|
||||
}
|
||||
if (options.remove) {
|
||||
var changeset = new Collection(models);
|
||||
for (i = 0, l = this.models.length; i < l; i++) {
|
||||
model = this.models[i];
|
||||
if (!changeset.get(model)) remove.push(model);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove models (if applicable) before we add and merge the rest.
|
||||
if (remove.length) this.remove(remove, options);
|
||||
if (add.length) this.add(add, options);
|
||||
return this;
|
||||
},
|
||||
|
||||
// When you have more items than you want to add or remove individually,
|
||||
// you can reset the entire set with a new list of models, without firing
|
||||
// any `add` or `remove` events. Fires `reset` when finished.
|
||||
reset: function(models, options) {
|
||||
options || (options = {});
|
||||
if (options.parse) models = this.parse(models);
|
||||
for (var i = 0, l = this.models.length; i < l; i++) {
|
||||
this._removeReference(this.models[i]);
|
||||
}
|
||||
options.previousModels = this.models;
|
||||
this._reset();
|
||||
if (models) this.add(models, _.extend({silent: true}, options));
|
||||
if (!options || !options.silent) this.trigger('reset', this, options);
|
||||
if (!options.silent) this.trigger('reset', this, options);
|
||||
return this;
|
||||
},
|
||||
|
||||
@@ -800,7 +857,8 @@
|
||||
var collection = this;
|
||||
var success = options.success;
|
||||
options.success = function(resp, status, xhr) {
|
||||
collection[options.add ? 'add' : 'reset'](collection.parse(resp, xhr), options);
|
||||
var method = options.update ? 'update' : 'reset';
|
||||
collection[method](collection.parse(resp, xhr), options);
|
||||
if (success) success(collection, resp, options);
|
||||
};
|
||||
return this.sync('read', this, options);
|
||||
@@ -859,7 +917,7 @@
|
||||
options || (options = {});
|
||||
options.collection = this;
|
||||
var model = new this.model(attrs, options);
|
||||
if (!model._validate(model.attributes, options)) return false;
|
||||
if (!model._validate(attrs, options)) return false;
|
||||
return model;
|
||||
},
|
||||
|
||||
@@ -932,7 +990,7 @@
|
||||
var optionalParam = /\((.*?)\)/g;
|
||||
var namedParam = /:\w+/g;
|
||||
var splatParam = /\*\w+/g;
|
||||
var escapeRegExp = /[-{}[\]+?.,\\^$|#\s]/g;
|
||||
var escapeRegExp = /[\-{}\[\]+?.,\\\^$|#\s]/g;
|
||||
|
||||
// Set up all inheritable **Backbone.Router** properties and methods.
|
||||
_.extend(Router.prototype, Events, {
|
||||
@@ -1051,7 +1109,7 @@
|
||||
fragment = this.getHash();
|
||||
}
|
||||
}
|
||||
return decodeURIComponent(fragment.replace(routeStripper, ''));
|
||||
return fragment.replace(routeStripper, '');
|
||||
},
|
||||
|
||||
// Start the hash change handling, returning `true` if the current URL matches
|
||||
@@ -1364,6 +1422,7 @@
|
||||
var methodMap = {
|
||||
'create': 'POST',
|
||||
'update': 'PUT',
|
||||
'patch': 'PATCH',
|
||||
'delete': 'DELETE',
|
||||
'read': 'GET'
|
||||
};
|
||||
@@ -1401,9 +1460,9 @@
|
||||
}
|
||||
|
||||
// Ensure that we have the appropriate request data.
|
||||
if (!options.data && model && (method === 'create' || method === 'update')) {
|
||||
if (options.data == null && model && (method === 'create' || method === 'update')) {
|
||||
params.contentType = 'application/json';
|
||||
params.data = JSON.stringify(model.toJSON(options));
|
||||
params.data = JSON.stringify(options.attrs || model.toJSON(options));
|
||||
}
|
||||
|
||||
// For older servers, emulate JSON by encoding the request into an HTML-form.
|
||||
@@ -1442,7 +1501,9 @@
|
||||
};
|
||||
|
||||
// Make the request, allowing the user to override any Ajax options.
|
||||
return Backbone.ajax(_.extend(params, options));
|
||||
var xhr = Backbone.ajax(_.extend(params, options));
|
||||
model.trigger('request', model, xhr, options);
|
||||
return xhr;
|
||||
};
|
||||
|
||||
// Set the default implementation of `Backbone.ajax` to proxy through to `$`.
|
||||
|
||||
Reference in New Issue
Block a user