Comparing version 1.1.0 to 1.1.2-2.4.1
163
backbone.js
@@ -1,5 +0,4 @@ | ||
// Backbone.js 1.1.0 | ||
// Backbone.js 1.1.2 | ||
// (c) 2010-2011 Jeremy Ashkenas, DocumentCloud Inc. | ||
// (c) 2011-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors | ||
// (c) 2010-2014 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors | ||
// Backbone may be freely distributed under the MIT license. | ||
@@ -9,11 +8,27 @@ // For all details and documentation: | ||
(function(){ | ||
(function(root, factory) { | ||
// Set up Backbone appropriately for the environment. Start with AMD. | ||
if (typeof define === 'function' && define.amd) { | ||
define(['underscore', 'jquery', 'exports'], function(_, $, exports) { | ||
// Export global even in AMD case in case this script is loaded with | ||
// others that may still expect a global Backbone. | ||
root.Backbone = factory(root, exports, _, $); | ||
}); | ||
// Next for Node.js or CommonJS. jQuery may not be needed as a module. | ||
} else if (typeof exports !== 'undefined') { | ||
var _ = require('lodash'); | ||
factory(root, exports, _); | ||
// Finally, as a browser global. | ||
} else { | ||
root.Backbone = factory(root, {}, root._, (root.jQuery || root.Zepto || root.ender || root.$)); | ||
} | ||
}(this, function(root, Backbone, _, $) { | ||
// Initial Setup | ||
// ------------- | ||
// Save a reference to the global object (`window` in the browser, `exports` | ||
// on the server). | ||
var root = this; | ||
// Save the previous value of the `Backbone` variable, so that it can be | ||
@@ -29,21 +44,8 @@ // restored later on, if `noConflict` is used. | ||
// The top-level namespace. All public Backbone classes and modules will | ||
// be attached to this. Exported for both the browser and the server. | ||
var Backbone; | ||
if (typeof exports !== 'undefined') { | ||
Backbone = exports; | ||
} else { | ||
Backbone = root.Backbone = {}; | ||
} | ||
// Current version of the library. Keep in sync with `package.json`. | ||
Backbone.VERSION = '1.1.0'; | ||
Backbone.VERSION = '1.1.2'; | ||
// Require Underscore, if we're on the server, and it's not already present. | ||
var _ = root._; | ||
if (!_ && (typeof require !== 'undefined')) _ = require('lodash'); | ||
// For Backbone's purposes, jQuery, Zepto, Ender, or My Library (kidding) owns | ||
// the `$` variable. | ||
Backbone.$ = root.jQuery || root.Zepto || root.ender || root.$; | ||
Backbone.$ = $; | ||
@@ -114,3 +116,3 @@ // Runs Backbone.js in *noConflict* mode, returning the `Backbone` variable | ||
if (!name && !callback && !context) { | ||
this._events = {}; | ||
this._events = void 0; | ||
return this; | ||
@@ -211,3 +213,3 @@ } | ||
case 3: while (++i < l) (ev = events[i]).callback.call(ev.ctx, a1, a2, a3); return; | ||
default: while (++i < l) (ev = events[i]).callback.apply(ev.ctx, args); | ||
default: while (++i < l) (ev = events[i]).callback.apply(ev.ctx, args); return; | ||
} | ||
@@ -357,3 +359,3 @@ }; | ||
if (!silent) { | ||
if (changes.length) this._pending = true; | ||
if (changes.length) this._pending = options; | ||
for (var i = 0, l = changes.length; i < l; i++) { | ||
@@ -369,2 +371,3 @@ this.trigger('change:' + changes[i], this, current[changes[i]], options); | ||
while (this._pending) { | ||
options = this._pending; | ||
this._pending = false; | ||
@@ -537,5 +540,8 @@ this.trigger('change', this, options); | ||
url: function() { | ||
var base = _.result(this, 'urlRoot') || _.result(this.collection, 'url') || urlError(); | ||
var base = | ||
_.result(this, 'urlRoot') || | ||
_.result(this.collection, 'url') || | ||
urlError(); | ||
if (this.isNew()) return base; | ||
return base + (base.charAt(base.length - 1) === '/' ? '' : '/') + encodeURIComponent(this.id); | ||
return base.replace(/([^\/])$/, '$1/') + encodeURIComponent(this.id); | ||
}, | ||
@@ -556,3 +562,3 @@ | ||
isNew: function() { | ||
return this.id == null; | ||
return !this.has(this.idAttribute); | ||
}, | ||
@@ -661,3 +667,3 @@ | ||
} | ||
this._removeReference(model); | ||
this._removeReference(model, options); | ||
} | ||
@@ -688,7 +694,7 @@ return singular ? models[0] : models; | ||
for (i = 0, l = models.length; i < l; i++) { | ||
attrs = models[i]; | ||
attrs = models[i] || {}; | ||
if (attrs instanceof Model) { | ||
id = model = attrs; | ||
} else { | ||
id = attrs[targetModel.prototype.idAttribute]; | ||
id = attrs[targetModel.prototype.idAttribute || 'id']; | ||
} | ||
@@ -713,10 +719,9 @@ | ||
toAdd.push(model); | ||
this._addReference(model, options); | ||
} | ||
// Listen to added models' events, and index models for lookup by | ||
// `id` and by `cid`. | ||
model.on('all', this._onModelEvent, this); | ||
this._byId[model.cid] = model; | ||
if (model.id != null) this._byId[model.id] = model; | ||
} | ||
if (order) order.push(existing || model); | ||
// Do not add multiple models with the same `id`. | ||
model = existing || model; | ||
if (order && (model.isNew() || !modelMap[model.id])) order.push(model); | ||
modelMap[model.id] = true; | ||
} | ||
@@ -759,3 +764,3 @@ | ||
} | ||
// Return the added (or merged) model (or models). | ||
@@ -772,3 +777,3 @@ return singular ? models[0] : models; | ||
for (var i = 0, l = this.models.length; i < l; i++) { | ||
this._removeReference(this.models[i]); | ||
this._removeReference(this.models[i], options); | ||
} | ||
@@ -814,3 +819,3 @@ options.previousModels = this.models; | ||
if (obj == null) return void 0; | ||
return this._byId[obj.id] || this._byId[obj.cid] || this._byId[obj]; | ||
return this._byId[obj] || this._byId[obj.id] || this._byId[obj.cid]; | ||
}, | ||
@@ -891,3 +896,3 @@ | ||
var success = options.success; | ||
options.success = function(model, resp, options) { | ||
options.success = function(model, resp) { | ||
if (options.wait) collection.add(model, options); | ||
@@ -922,6 +927,3 @@ if (success) success(model, resp, options); | ||
_prepareModel: function(attrs, options) { | ||
if (attrs instanceof Model) { | ||
if (!attrs.collection) attrs.collection = this; | ||
return attrs; | ||
} | ||
if (attrs instanceof Model) return attrs; | ||
options = options ? _.clone(options) : {}; | ||
@@ -935,4 +937,12 @@ options.collection = this; | ||
// Internal method to create a model's ties to a collection. | ||
_addReference: function(model, options) { | ||
this._byId[model.cid] = model; | ||
if (model.id != null) this._byId[model.id] = model; | ||
if (!model.collection) model.collection = this; | ||
model.on('all', this._onModelEvent, this); | ||
}, | ||
// Internal method to sever a model's ties to a collection. | ||
_removeReference: function(model) { | ||
_removeReference: function(model, options) { | ||
if (this === model.collection) delete model.collection; | ||
@@ -966,3 +976,3 @@ model.off('all', this._onModelEvent, this); | ||
'tail', 'drop', 'last', 'without', 'difference', 'indexOf', 'shuffle', | ||
'lastIndexOf', 'isEmpty', 'chain']; | ||
'lastIndexOf', 'isEmpty', 'chain', 'sample']; | ||
@@ -979,3 +989,3 @@ // Mix in each Underscore method as a proxy to `Collection#models`. | ||
// Underscore methods that take a property name as an argument. | ||
var attributeMethods = ['groupBy', 'countBy', 'sortBy']; | ||
var attributeMethods = ['groupBy', 'countBy', 'sortBy', 'indexBy']; | ||
@@ -1202,3 +1212,5 @@ // Use attributes instead of properties. | ||
var noXhrPatch = typeof window !== 'undefined' && !!window.ActiveXObject && !(window.XMLHttpRequest && (new XMLHttpRequest).dispatchEvent); | ||
var noXhrPatch = | ||
typeof window !== 'undefined' && !!window.ActiveXObject && | ||
!(window.XMLHttpRequest && (new XMLHttpRequest).dispatchEvent); | ||
@@ -1262,3 +1274,3 @@ // Map from CRUD to HTTP for our default `Backbone.sync` implementation. | ||
var args = router._extractParameters(route, fragment); | ||
callback && callback.apply(router, args); | ||
router.execute(callback, args); | ||
router.trigger.apply(router, ['route:' + name].concat(args)); | ||
@@ -1271,2 +1283,8 @@ router.trigger('route', name, args); | ||
// Execute a route handler with the provided parameters. This is an | ||
// excellent place to do pre-route setup or post-route cleanup. | ||
execute: function(callback, args) { | ||
if (callback) callback.apply(this, args); | ||
}, | ||
// Simple proxy to `Backbone.history` to save a fragment into the history. | ||
@@ -1296,6 +1314,6 @@ navigate: function(fragment, options) { | ||
.replace(namedParam, function(match, optional) { | ||
return optional ? match : '([^\/]+)'; | ||
return optional ? match : '([^/?]+)'; | ||
}) | ||
.replace(splatParam, '(.*?)'); | ||
return new RegExp('^' + route + '$'); | ||
.replace(splatParam, '([^?]*?)'); | ||
return new RegExp('^' + route + '(?:\\?([\\s\\S]*))?$'); | ||
}, | ||
@@ -1308,3 +1326,5 @@ | ||
var params = route.exec(fragment).slice(1); | ||
return _.map(params, function(param) { | ||
return _.map(params, function(param, i) { | ||
// Don't decode the search params. | ||
if (i === params.length - 1) return param || null; | ||
return param ? decodeURIComponent(param) : null; | ||
@@ -1347,4 +1367,4 @@ }); | ||
// Cached regex for stripping urls of hash and query. | ||
var pathStripper = /[?#].*$/; | ||
// Cached regex for stripping urls of hash. | ||
var pathStripper = /#.*$/; | ||
@@ -1361,2 +1381,7 @@ // Has the history handling already been started? | ||
// Are we at the app root? | ||
atRoot: function() { | ||
return this.location.pathname.replace(/[^\/]$/, '$&/') === this.root; | ||
}, | ||
// Gets the true hash value. Cannot use location.hash directly due to bug | ||
@@ -1374,3 +1399,3 @@ // in Firefox where location.hash will always be decoded. | ||
if (this._hasPushState || !this._wantsHashChange || forcePushState) { | ||
fragment = this.location.pathname; | ||
fragment = decodeURI(this.location.pathname + this.location.search); | ||
var root = this.root.replace(trailingSlash, ''); | ||
@@ -1406,3 +1431,4 @@ if (!fragment.indexOf(root)) fragment = fragment.slice(root.length); | ||
if (oldIE && this._wantsHashChange) { | ||
this.iframe = Backbone.$('<iframe src="javascript:0" tabindex="-1" />').hide().appendTo('body')[0].contentWindow; | ||
var frame = Backbone.$('<iframe src="javascript:0" tabindex="-1">'); | ||
this.iframe = frame.hide().appendTo('body')[0].contentWindow; | ||
this.navigate(fragment); | ||
@@ -1425,3 +1451,2 @@ } | ||
var loc = this.location; | ||
var atRoot = loc.pathname.replace(/[^\/]$/, '$&/') === this.root; | ||
@@ -1434,5 +1459,5 @@ // Transition from hashChange to pushState or vice versa if both are | ||
// browser, but we're currently in a browser that doesn't support it... | ||
if (!this._hasPushState && !atRoot) { | ||
if (!this._hasPushState && !this.atRoot()) { | ||
this.fragment = this.getFragment(null, true); | ||
this.location.replace(this.root + this.location.search + '#' + this.fragment); | ||
this.location.replace(this.root + '#' + this.fragment); | ||
// Return immediately as browser will do redirect to new url | ||
@@ -1443,5 +1468,5 @@ return true; | ||
// in a browser where it could be `pushState`-based instead... | ||
} else if (this._hasPushState && atRoot && loc.hash) { | ||
} else if (this._hasPushState && this.atRoot() && loc.hash) { | ||
this.fragment = this.getHash().replace(routeStripper, ''); | ||
this.history.replaceState({}, document.title, this.root + this.fragment + loc.search); | ||
this.history.replaceState({}, document.title, this.root + this.fragment); | ||
} | ||
@@ -1458,3 +1483,3 @@ | ||
Backbone.$(window).off('popstate', this.checkUrl).off('hashchange', this.checkUrl); | ||
clearInterval(this._checkUrlInterval); | ||
if (this._checkUrlInterval) clearInterval(this._checkUrlInterval); | ||
History.started = false; | ||
@@ -1507,3 +1532,3 @@ }, | ||
// Strip the fragment of the query and hash for matching. | ||
// Strip the hash for matching. | ||
fragment = fragment.replace(pathStripper, ''); | ||
@@ -1614,2 +1639,4 @@ | ||
}).call(this); | ||
return Backbone; | ||
})); |
{ | ||
"name" : "backbone", | ||
"version" : "1.1.0", | ||
"version" : "1.1.2", | ||
"main" : "backbone.js", | ||
@@ -8,3 +8,3 @@ "dependencies" : { | ||
}, | ||
"ignore" : ["backbone-min.js", "docs", "examples", "test", "*.yml", "*.map", ".html"] | ||
"ignore" : ["backbone-min.js", "docs", "examples", "test", "*.yml", "*.map", "*.html", "*.ico"] | ||
} |
{ | ||
"name" : "backbone", | ||
"version" : "1.1.0", | ||
"version" : "1.1.2", | ||
"description" : "Give your JS App some Backbone with Models, Views, Collections, and Events.", | ||
@@ -5,0 +5,0 @@ "keywords" : ["model", "view", "controller", "router", "server", "client", "browser"], |
@@ -8,8 +8,8 @@ { | ||
"dependencies" : { | ||
"lodash": "1.3.1" | ||
"lodash": "2.4.1" | ||
}, | ||
"devDependencies": { | ||
"phantomjs": "1.9.0-1", | ||
"docco": "0.6.1", | ||
"coffee-script": "1.6.1" | ||
"phantomjs": "1.9.7-1", | ||
"docco": "0.6.3", | ||
"coffee-script": "1.7.1" | ||
}, | ||
@@ -23,3 +23,3 @@ "scripts": { | ||
"main" : "backbone.js", | ||
"version" : "1.1.0", | ||
"version" : "1.1.2-2.4.1", | ||
"license" : "MIT", | ||
@@ -26,0 +26,0 @@ "repository": { |
@@ -18,6 +18,6 @@ backdash | ||
[Line 42](https://github.com/jashkenas/backbone/blob/1.1.0/backbone.js#L42) changed from: | ||
[Line 20](https://github.com/jashkenas/backbone/blob/1.1.2/backbone.js#L20) changed from: | ||
```javascript | ||
if (!_ && (typeof require !== 'undefined')) _ = require('underscore'); | ||
var _ = require('underscore'); | ||
``` | ||
@@ -28,3 +28,3 @@ | ||
```javascript | ||
if (!_ && (typeof require !== 'undefined')) _ = require('lodash'); | ||
var _ = require('lodash'); | ||
``` | ||
@@ -37,3 +37,3 @@ | ||
```javascript | ||
"underscore" : ">=1.4.3" | ||
"underscore" : ">=1.5.0" | ||
``` | ||
@@ -44,3 +44,3 @@ | ||
```javascript | ||
"lodash": "1.3.1" | ||
"lodash": "2.4.1" | ||
``` | ||
@@ -51,3 +51,3 @@ | ||
This version of backdash is based on Backbone 1.1.0 and Lodash 1.3.1 | ||
This version of backdash is based on Backbone 1.1.2 and Lodash 2.4.1 | ||
@@ -63,3 +63,3 @@ Use those versions explicitly in any other module that will build into the target project. Multiple versions of lodash in the dependency tree will cause multiple versions to appear in the built browserify bundle. | ||
````javascript | ||
```javascript | ||
npm install lodash | ||
@@ -66,0 +66,0 @@ npm install backdash |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
123456
14
1476
3
+ Addedlodash@2.4.1(transitive)
- Removedlodash@1.3.1(transitive)
Updatedlodash@2.4.1