Skip to content

Commit

Permalink
Merge pull request #113 from ushahidi/backbone-upgrade-1.1.1
Browse files Browse the repository at this point in the history
Update BackboneJS to 1.1.1 and grab Marionette v1.2.0
  • Loading branch information
rjmackay committed Oct 23, 2013
2 parents 34eaaee + e9a7eca commit 09682de
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 82 deletions.
67 changes: 31 additions & 36 deletions modules/UshahidiUI/media/js/libs/backbone.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Backbone.js 1.0.0 (master @ f6fa0cb87e)
// Backbone.js 1.1.0

// (c) 2010-2011 Jeremy Ashkenas, DocumentCloud Inc.
// (c) 2011-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
Expand Down Expand Up @@ -35,7 +35,7 @@
}

// Current version of the library. Keep in sync with `package.json`.
Backbone.VERSION = '1.0.0';
Backbone.VERSION = '1.1.0';

// Require Underscore, if we're on the server, and it's not already present.
var _ = root._;
Expand Down Expand Up @@ -244,16 +244,13 @@
// Create a new model with the specified attributes. A client id (`cid`)
// is automatically generated and assigned for you.
var Model = Backbone.Model = function(attributes, options) {
var defaults;
var attrs = attributes || {};
options || (options = {});
this.cid = _.uniqueId('c');
this.attributes = {};
if (options.collection) this.collection = options.collection;
if (options.parse) attrs = this.parse(attrs, options) || {};
if (defaults = _.result(this, 'defaults')) {
attrs = _.defaults({}, attrs, defaults);
}
attrs = _.defaults({}, attrs, _.result(this, 'defaults'));
this.set(attrs, options);
this.changed = {};
this.initialize.apply(this, arguments);
Expand Down Expand Up @@ -637,11 +634,12 @@

// Remove a model, or a list of models from the set.
remove: function(models, options) {
models = _.isArray(models) ? models.slice() : [models];
var singular = !_.isArray(models);
models = singular ? [models] : _.clone(models);
options || (options = {});
var i, l, index, model;
for (i = 0, l = models.length; i < l; i++) {
model = this.get(models[i]);
model = models[i] = this.get(models[i]);
if (!model) continue;
delete this._byId[model.id];
delete this._byId[model.cid];
Expand All @@ -654,7 +652,7 @@
}
this._removeReference(model);
}
return this;
return singular ? models[0] : models;
},

// Update a collection by `set`-ing a new list of models, adding new ones,
Expand All @@ -664,7 +662,8 @@
set: function(models, options) {
options = _.defaults({}, options, setOptions);
if (options.parse) models = this.parse(models, options);
if (!_.isArray(models)) models = models ? [models] : [];
var singular = !_.isArray(models);
models = singular ? (models ? [models] : []) : _.clone(models);
var i, l, id, model, attrs, existing, sort;
var at = options.at;
var targetModel = this.model;
Expand Down Expand Up @@ -694,10 +693,12 @@
existing.set(attrs, options);
if (sortable && !sort && existing.hasChanged(sortAttr)) sort = true;
}
models[i] = existing;

// This is a new model, push it to the `toAdd` list.
// If this is a new, valid model, push it to the `toAdd` list.
} else if (add) {
if (!(model = this._prepareModel(attrs, options))) continue;
model = models[i] = this._prepareModel(attrs, options);
if (!model) continue;
toAdd.push(model);

// Listen to added models' events, and index models for lookup by
Expand Down Expand Up @@ -727,26 +728,26 @@
}
} else {
if (order) this.models.length = 0;
models = order || toAdd;
for (i = 0, l = models.length; i < l; i++) {
this.models.push(models[i]);
var orderedModels = order || toAdd;
for (i = 0, l = orderedModels.length; i < l; i++) {
this.models.push(orderedModels[i]);
}
}
}

// Silently sort the collection if appropriate.
if (sort) this.sort({silent: true});

if (options.silent) return this;

// Trigger `add` events.
for (i = 0, l = toAdd.length; i < l; i++) {
(model = toAdd[i]).trigger('add', model, this, options);
// Unless silenced, it's time to fire all appropriate add/sort events.
if (!options.silent) {
for (i = 0, l = toAdd.length; i < l; i++) {
(model = toAdd[i]).trigger('add', model, this, options);
}
if (sort || (order && order.length)) this.trigger('sort', this, options);
}

// Trigger `sort` if the collection was sorted.
if (sort || (order && order.length)) this.trigger('sort', this, options);
return this;

// Return the added (or merged) model (or models).
return singular ? models[0] : models;
},

// When you have more items than you want to add or remove individually,
Expand All @@ -760,15 +761,14 @@
}
options.previousModels = this.models;
this._reset();
this.add(models, _.extend({silent: true}, options));
models = this.add(models, _.extend({silent: true}, options));
if (!options.silent) this.trigger('reset', this, options);
return this;
return models;
},

// Add a model to the end of the collection.
push: function(model, options) {
this.add(model, _.extend({at: this.length}, options));
return model;
return this.add(model, _.extend({at: this.length}, options));
},

// Remove a model from the end of the collection.
Expand All @@ -780,8 +780,7 @@

// Add a model to the beginning of the collection.
unshift: function(model, options) {
this.add(model, _.extend({at: 0}, options));
return model;
return this.add(model, _.extend({at: 0}, options));
},

// Remove a model from the beginning of the collection.
Expand Down Expand Up @@ -909,7 +908,7 @@
if (!attrs.collection) attrs.collection = this;
return attrs;
}
options || (options = {});
options = options ? _.clone(options) : {};
options.collection = this;
var model = new this.model(attrs, options);
if (!model.validationError) return model;
Expand Down Expand Up @@ -982,10 +981,6 @@
// having to worry about render order ... and makes it easy for the view to
// react to specific changes in the state of your models.

// Options with special meaning *(e.g. model, collection, id, className)* are
// attached directly to the view. See `viewOptions` for an exhaustive
// list.

// Creating a Backbone.View creates its initial element outside of the DOM,
// if an existing element is not provided...
var View = Backbone.View = function(options) {
Expand Down Expand Up @@ -1368,7 +1363,7 @@

// Figure out the initial configuration. Do we need an iframe?
// Is pushState desired ... is it available?
this.options = _.extend({}, {root: '/'}, this.options, options);
this.options = _.extend({root: '/'}, this.options, options);
this.root = this.options.root;
this._wantsHashChange = this.options.hashChange !== false;
this._wantsPushState = !!this.options.pushState;
Expand Down
Loading

0 comments on commit 09682de

Please sign in to comment.