Permalink
...
Comparing changes
Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .
Open a pull request
Create a new pull request by comparing changes across two branches. If you need to, you can also .
Choose a Base Repository
jashkenas/backbone
Avalon/backbone
Backcountry/backbone
HTML5-Spain/backbone
JasonGiedymin/backbone
JesseQin/backbone
Nerian/backbone-Spark
RodH257/backbone
Rosencrantz/backbone
ScxFiction/backbone
Smarsh/backbone
SponsorPay/backbone
StevenBlack/backbone
SumitMunot/backbone
Whoaa512/backbone-livescript
ZeeAgency/backbone
addyosmani/backbone
afeld/backbone
aflatter/backbone
airhorns/backbone
aitorciki/backbone
aixeiger/backbone
alexgenovese/backbone
amdjs/backbone
antoniogarrote/backbone
asan/backbone
autohaus24/backbone
azethoth/backbone
bROthersRockers/backbone
balwantk/backbone
benchow/backbone
bfirsh/backbone
bgrins/backbone
boazsender/backbone
braddunbar/backbone
bsingr/backbone
campfirelabs/backbone
cawinkelmann/backbone
centraldesktop/backbone
charles-cai/backbone
chetan51/backbone
chrismgrant/backbone
cmonty/backbone
code-ninja/backbone
collin/backbone
corbanbrook/backbone
cureatr/backbone
dalyons/backbone
danigb/backbone
danmascena/backbone
datapimp/backbone
dcneiner/backbone
deleteme/backbone
derickbailey/backbone
devilankur18/backbone
devinhunt/backbone
djadriano/backbone
djia/backbone
djmitche/backbone
doomhz/backbone
dperrymorrow/backbone
dreverri/backbone
drewlesueur/backbone
dshaw/backbone
durdn/backbone
ecocity/backbone
ef4/backbone
enki/backbone
epall/backbone
erawk/backbone
excellentdrums/backbone
extelligence/backbone
fabrik42/backbone
ferbs/backbone
fernandogmar/backbone
fitzgen/backbone
fmaulanaa/backbone
fr1n63/backbone
fractastical/backbone
frankk00/backbone
g6scheme/backbone
gaboom/backbone
garza/backbone
gaustin/backbone-mootools
geddski/backbone
getbpm/backbone
gfranko/backbone
gmccreight/backbone
gsamokovarov/backbone
habuma/backbone
halfbaked/backbone
haoranw/backbone
hlissnake/backbone
hokaccha/backbone
hshoff/backbone
hugohua/backbone
hunterloftis/backbone
ian7/backbone
ianstormtaylor/backbone
jamesyu/backbone
janmonschke/backbone
japetheape/backbone
jcoglan/backbone
jduff/backbone
jentanbernardus/backbone
jeromegn/backbone
jhollingworth/backbone
jhuckabee/backbone
jimmytang/backbone
jo/backbone
jordandobson/backbone
jordanfowler/backbone
jroes/backbone
jstrimpel/backbone
jtescher/backbone
juggy/backbone
keithamus/backbone
krunkosaurus/backbone
kurtharriger/backbone
leeight/backbone
lmorchard/backbone
lmp/backbone
loginx/backbone
lorensr/backbone
luca/backbone
lucianlature/backbone
maccman/backbone
mataspetrikas/backbone
maw/backbone
mbriggs/backbone
mikerice/backbone
mohamedmansour/backbone
morganrallen/backbone
mostly-magic/backbone
n4niks/backbone
nanqiu/backbone
nealstewart/backbone
netmau5/backbone
nguyennamtien/backbone
nibblebot/backbone
nickjs/backbone
nikgraf/backbone
nsb/backbone
olleolleolle/backbone
omnifroodle/backbone
onycloud/backbone
pbombo/backbone-mootools
phamann/backbone
pirelenito/backbone
pkananen/backbone
r00k/backbone
raysrashmi/backbone
reconbot/backbone
rsandor/backbone
rsim/backbone
saimonmoore/backbone
scottopherson/backbone
shalstvedt/backbone
shehuaqigai/backbone
shiftb/backbone
sitron/backbone
solutionio/backbone
sstephenson/backbone
steel/backbone
stephank/backbone
strax/backbone
swalke16/backbone
tapichu/backbone
tauren/backbone
taybenlor/backbone-on-coffee
tbranyen/backbone
tessekkur/backbone
thisduck/backbone
timesselens/backbone
timheap/mootools-backbone
timruffles/backbone
tlray/backbone
toastdriven/backbone
tobie/backbone
tobowers/backbone
tomasztunik/backbone
tomokane/backbone
tonydewan/backbone
tosh/backbone
trcarden/backbone
tzuryby/backbone
ulmus/backbone
vincentbriglia/backbone
vsaar/backbone
wallin/backbone
walmartlabs/backbone
webmat/backbone
webspinner/backbone
wesen/backbone
willmoffat/backbone
wowsoso/backbone
wuzhe/backbone
zackchandler/backbone
zhj3618/backbone
zzurang/backbone
Nothing to show
Choose a Head Repository
jashkenas/backbone
Avalon/backbone
Backcountry/backbone
HTML5-Spain/backbone
JasonGiedymin/backbone
JesseQin/backbone
Nerian/backbone-Spark
RodH257/backbone
Rosencrantz/backbone
ScxFiction/backbone
Smarsh/backbone
SponsorPay/backbone
StevenBlack/backbone
SumitMunot/backbone
Whoaa512/backbone-livescript
ZeeAgency/backbone
addyosmani/backbone
afeld/backbone
aflatter/backbone
airhorns/backbone
aitorciki/backbone
aixeiger/backbone
alexgenovese/backbone
amdjs/backbone
antoniogarrote/backbone
asan/backbone
autohaus24/backbone
azethoth/backbone
bROthersRockers/backbone
balwantk/backbone
benchow/backbone
bfirsh/backbone
bgrins/backbone
boazsender/backbone
braddunbar/backbone
bsingr/backbone
campfirelabs/backbone
cawinkelmann/backbone
centraldesktop/backbone
charles-cai/backbone
chetan51/backbone
chrismgrant/backbone
cmonty/backbone
code-ninja/backbone
collin/backbone
corbanbrook/backbone
cureatr/backbone
dalyons/backbone
danigb/backbone
danmascena/backbone
datapimp/backbone
dcneiner/backbone
deleteme/backbone
derickbailey/backbone
devilankur18/backbone
devinhunt/backbone
djadriano/backbone
djia/backbone
djmitche/backbone
doomhz/backbone
dperrymorrow/backbone
dreverri/backbone
drewlesueur/backbone
dshaw/backbone
durdn/backbone
ecocity/backbone
ef4/backbone
enki/backbone
epall/backbone
erawk/backbone
excellentdrums/backbone
extelligence/backbone
fabrik42/backbone
ferbs/backbone
fernandogmar/backbone
fitzgen/backbone
fmaulanaa/backbone
fr1n63/backbone
fractastical/backbone
frankk00/backbone
g6scheme/backbone
gaboom/backbone
garza/backbone
gaustin/backbone-mootools
geddski/backbone
getbpm/backbone
gfranko/backbone
gmccreight/backbone
gsamokovarov/backbone
habuma/backbone
halfbaked/backbone
haoranw/backbone
hlissnake/backbone
hokaccha/backbone
hshoff/backbone
hugohua/backbone
hunterloftis/backbone
ian7/backbone
ianstormtaylor/backbone
jamesyu/backbone
janmonschke/backbone
japetheape/backbone
jcoglan/backbone
jduff/backbone
jentanbernardus/backbone
jeromegn/backbone
jhollingworth/backbone
jhuckabee/backbone
jimmytang/backbone
jo/backbone
jordandobson/backbone
jordanfowler/backbone
jroes/backbone
jstrimpel/backbone
jtescher/backbone
juggy/backbone
keithamus/backbone
krunkosaurus/backbone
kurtharriger/backbone
leeight/backbone
lmorchard/backbone
lmp/backbone
loginx/backbone
lorensr/backbone
luca/backbone
lucianlature/backbone
maccman/backbone
mataspetrikas/backbone
maw/backbone
mbriggs/backbone
mikerice/backbone
mohamedmansour/backbone
morganrallen/backbone
mostly-magic/backbone
n4niks/backbone
nanqiu/backbone
nealstewart/backbone
netmau5/backbone
nguyennamtien/backbone
nibblebot/backbone
nickjs/backbone
nikgraf/backbone
nsb/backbone
olleolleolle/backbone
omnifroodle/backbone
onycloud/backbone
pbombo/backbone-mootools
phamann/backbone
pirelenito/backbone
pkananen/backbone
r00k/backbone
raysrashmi/backbone
reconbot/backbone
rsandor/backbone
rsim/backbone
saimonmoore/backbone
scottopherson/backbone
shalstvedt/backbone
shehuaqigai/backbone
shiftb/backbone
sitron/backbone
solutionio/backbone
sstephenson/backbone
steel/backbone
stephank/backbone
strax/backbone
swalke16/backbone
tapichu/backbone
tauren/backbone
taybenlor/backbone-on-coffee
tbranyen/backbone
tessekkur/backbone
thisduck/backbone
timesselens/backbone
timheap/mootools-backbone
timruffles/backbone
tlray/backbone
toastdriven/backbone
tobie/backbone
tobowers/backbone
tomasztunik/backbone
tomokane/backbone
tonydewan/backbone
tosh/backbone
trcarden/backbone
tzuryby/backbone
ulmus/backbone
vincentbriglia/backbone
vsaar/backbone
wallin/backbone
walmartlabs/backbone
webmat/backbone
webspinner/backbone
wesen/backbone
willmoffat/backbone
wowsoso/backbone
wuzhe/backbone
zackchandler/backbone
zhj3618/backbone
zzurang/backbone
Nothing to show
6
contributors
Commits on Jan 30, 2012
Commits on Jan 31, 2012
|
|
tomasztunik |
Fixes issue #904
|
bb1a7d7
|
|||
|
|
Joss Crowcroft |
Return `this` from View.setElement
|
4ad12bc
|
|||
|
|
braddunbar |
fixes #907 - `save` with `wait` succeeds without `validate`
|
db95e2c
|
|||
|
|
jashkenas |
added a few missing things to the change log
|
6ffd392
|
|||
|
|
braddunbar |
ensure `options` is present
|
7a48639
|
|||
|
|
jashkenas |
Merge pull request #911 from braddunbar/validate
fixes #907 - `save` with `wait` succeeds without `validate` |
e572881
|
|||
|
|
jashkenas |
Merge pull request #909 from josscrowcroft/master
Return `this` from View.setElement() |
bbee6f1
|
|||
|
|
twobitfool + jsanders |
inject js library with `Backbone.use(myLib)`
|
701350a
|
|||
|
|
jsanders |
Change from Backbone.use to Backbone.setjQuery and fix tests
|
9bd086e
|
Commits on Feb 01, 2012
Commits on Feb 02, 2012
Unified
Split
Showing
with
548 additions
and 283 deletions.
- +33 −31 backbone-min.js
- +69 −35 backbone.js
- +183 −156 docs/backbone.html
- +74 −12 index.html
- +1 −1 package.json
- +18 −12 test/collection.js
- +123 −29 test/model.js
- +30 −0 test/setdomlibrary.js
- +16 −7 test/sync.js
- +1 −0 test/test.html
View
64
backbone-min.js
Oops, something went wrong.
View
104
backbone.js
| @@ -1,4 +1,5 @@ | ||
| -// Backbone.js 0.9.0 | ||
| +// Backbone.js 0.9.1 | ||
| + | ||
| // (c) 2010-2012 Jeremy Ashkenas, DocumentCloud Inc. | ||
| // Backbone may be freely distributed under the MIT license. | ||
| // For all details and documentation: | ||
| @@ -31,7 +32,7 @@ | ||
| } | ||
| // Current version of the library. Keep in sync with `package.json`. | ||
| - Backbone.VERSION = '0.9.0'; | ||
| + Backbone.VERSION = '0.9.1'; | ||
| // Require Underscore, if we're on the server, and it's not already present. | ||
| var _ = root._; | ||
| @@ -40,6 +41,15 @@ | ||
| // For Backbone's purposes, jQuery, Zepto, or Ender owns the `$` variable. | ||
| var $ = root.jQuery || root.Zepto || root.ender; | ||
| + // Set the JavaScript library that will be used for DOM manipulation and | ||
| + // Ajax calls (a.k.a. the `$` variable). By default Backbone will use: jQuery, | ||
| + // Zepto, or Ender; but the `setDomLibrary()` method lets you inject an | ||
| + // alternate JavaScript library (or a mock library for testing your views | ||
| + // outside of a browser). | ||
| + Backbone.setDomLibrary = function(lib) { | ||
| + $ = lib; | ||
| + }; | ||
| + | ||
| // Runs Backbone.js in *noConflict* mode, returning the `Backbone` variable | ||
| // to its previous owner. Returns a reference to this Backbone object. | ||
| Backbone.noConflict = function() { | ||
| @@ -163,11 +173,10 @@ | ||
| this.attributes = {}; | ||
| this._escapedAttributes = {}; | ||
| this.cid = _.uniqueId('c'); | ||
| - this._changed = {}; | ||
| if (!this.set(attributes, {silent: true})) { | ||
| throw new Error("Can't create an invalid model"); | ||
| } | ||
| - this._changed = {}; | ||
| + delete this._changed; | ||
| this._previousAttributes = _.clone(this.attributes); | ||
| this.initialize.apply(this, arguments); | ||
| }; | ||
| @@ -223,35 +232,40 @@ | ||
| options || (options = {}); | ||
| if (!attrs) return this; | ||
| if (attrs instanceof Backbone.Model) attrs = attrs.attributes; | ||
| - if (options.unset) for (var attr in attrs) attrs[attr] = void 0; | ||
| + if (options.unset) for (attr in attrs) attrs[attr] = void 0; | ||
| // Run validation. | ||
| - if (this.validate && !this._performValidation(attrs, options)) return false; | ||
| + if (!this._validate(attrs, options)) return false; | ||
| // Check for changes of `id`. | ||
| if (this.idAttribute in attrs) this.id = attrs[this.idAttribute]; | ||
| var now = this.attributes; | ||
| var escaped = this._escapedAttributes; | ||
| var prev = this._previousAttributes || {}; | ||
| - var alreadyChanging = this._changing; | ||
| - this._changing = true; | ||
| + var alreadySetting = this._setting; | ||
| + this._changed || (this._changed = {}); | ||
| + this._setting = true; | ||
| // Update attributes. | ||
| for (attr in attrs) { | ||
| val = attrs[attr]; | ||
| if (!_.isEqual(now[attr], val)) delete escaped[attr]; | ||
| options.unset ? delete now[attr] : now[attr] = val; | ||
| + if (this._changing && !_.isEqual(this._changed[attr], val)) { | ||
| + this.trigger('change:' + attr, this, val, options); | ||
| + this._moreChanges = true; | ||
| + } | ||
| delete this._changed[attr]; | ||
| if (!_.isEqual(prev[attr], val) || (_.has(now, attr) != _.has(prev, attr))) { | ||
| this._changed[attr] = val; | ||
| } | ||
| } | ||
| // Fire the `"change"` events, if the model has been changed. | ||
| - if (!alreadyChanging) { | ||
| + if (!alreadySetting) { | ||
| if (!options.silent && this.hasChanged()) this.change(options); | ||
| - this._changing = false; | ||
| + this._setting = false; | ||
| } | ||
| return this; | ||
| }, | ||
| @@ -289,7 +303,7 @@ | ||
| // If the server returns an attributes hash that differs, the model's | ||
| // state will be `set` again. | ||
| save: function(key, value, options) { | ||
| - var attrs; | ||
| + var attrs, current; | ||
| if (_.isObject(key) || key == null) { | ||
| attrs = key; | ||
| options = value; | ||
| @@ -299,7 +313,11 @@ | ||
| } | ||
| options = options ? _.clone(options) : {}; | ||
| - if (attrs && !this[options.wait ? '_performValidation' : 'set'](attrs, options)) return false; | ||
| + if (options.wait) current = _.clone(this.attributes); | ||
| + var silentOptions = _.extend({}, options, {silent: true}); | ||
| + if (attrs && !this.set(attrs, options.wait ? silentOptions : options)) { | ||
| + return false; | ||
| + } | ||
| var model = this; | ||
| var success = options.success; | ||
| options.success = function(resp, status, xhr) { | ||
| @@ -314,7 +332,9 @@ | ||
| }; | ||
| options.error = Backbone.wrapError(options.error, model, options); | ||
| var method = this.isNew() ? 'create' : 'update'; | ||
| - return (this.sync || Backbone.sync).call(this, method, this, options); | ||
| + var xhr = (this.sync || Backbone.sync).call(this, method, this, options); | ||
| + if (options.wait) this.set(current, silentOptions); | ||
| + return xhr; | ||
| }, | ||
| // Destroy this model on the server if it was already persisted. | ||
| @@ -373,19 +393,27 @@ | ||
| // a `"change:attribute"` event for each changed attribute. | ||
| // Calling this will cause all objects observing the model to update. | ||
| change: function(options) { | ||
| + if (this._changing || !this.hasChanged()) return this; | ||
| + this._changing = true; | ||
| + this._moreChanges = true; | ||
| for (var attr in this._changed) { | ||
| this.trigger('change:' + attr, this, this._changed[attr], options); | ||
| } | ||
| - this.trigger('change', this, options); | ||
| + while (this._moreChanges) { | ||
| + this._moreChanges = false; | ||
| + this.trigger('change', this, options); | ||
| + } | ||
| this._previousAttributes = _.clone(this.attributes); | ||
| - this._changed = {}; | ||
| + delete this._changed; | ||
| + this._changing = false; | ||
| + return this; | ||
| }, | ||
| // Determine if the model has changed since the last `"change"` event. | ||
| // If you specify an attribute name, determine if that attribute has changed. | ||
| hasChanged: function(attr) { | ||
| - if (attr) return _.has(this._changed, attr); | ||
| - return !_.isEmpty(this._changed); | ||
| + if (!arguments.length) return !_.isEmpty(this._changed); | ||
| + return this._changed && _.has(this._changed, attr); | ||
| }, | ||
| // Return an object containing all the attributes that have changed, or | ||
| @@ -407,7 +435,7 @@ | ||
| // Get the previous value of an attribute, recorded at the time the last | ||
| // `"change"` event was fired. | ||
| previous: function(attr) { | ||
| - if (!attr || !this._previousAttributes) return null; | ||
| + if (!arguments.length || !this._previousAttributes) return null; | ||
| return this._previousAttributes[attr]; | ||
| }, | ||
| @@ -417,21 +445,26 @@ | ||
| return _.clone(this._previousAttributes); | ||
| }, | ||
| + // Check if the model is currently in a valid state. It's only possible to | ||
| + // get into an *invalid* state if you're using silent changes. | ||
| + isValid: function() { | ||
| + return !this.validate(this.attributes); | ||
| + }, | ||
| + | ||
| // Run validation against a set of incoming attributes, returning `true` | ||
| // if all is well. If a specific `error` callback has been passed, | ||
| // call that instead of firing the general `"error"` event. | ||
| - _performValidation: function(attrs, options) { | ||
| - var newAttrs = _.extend({}, this.attributes, attrs); | ||
| - var error = this.validate(newAttrs, options); | ||
| - if (error) { | ||
| - if (options.error) { | ||
| - options.error(this, error, options); | ||
| - } else { | ||
| - this.trigger('error', this, error, options); | ||
| - } | ||
| - return false; | ||
| + _validate: function(attrs, options) { | ||
| + if (options.silent || !this.validate) return true; | ||
| + attrs = _.extend({}, this.attributes, attrs); | ||
| + var error = this.validate(attrs, options); | ||
| + if (!error) return true; | ||
| + if (options && options.error) { | ||
| + options.error(this, error, options); | ||
| + } else { | ||
| + this.trigger('error', this, error, options); | ||
| } | ||
| - return true; | ||
| + return false; | ||
| } | ||
| }); | ||
| @@ -650,7 +683,7 @@ | ||
| var attrs = model; | ||
| options.collection = this; | ||
| model = new this.model(attrs, options); | ||
| - if (model.validate && !model._performValidation(model.attributes, options)) model = false; | ||
| + if (!model._validate(model.attributes, options)) model = false; | ||
| } else if (!model.collection) { | ||
| model.collection = this; | ||
| } | ||
| @@ -815,9 +848,9 @@ | ||
| fragment = window.location.hash; | ||
| } | ||
| } | ||
| - fragment = decodeURIComponent(fragment.replace(routeStripper, '')); | ||
| + fragment = decodeURIComponent(fragment); | ||
| if (!fragment.indexOf(this.options.root)) fragment = fragment.substr(this.options.root.length); | ||
| - return fragment; | ||
| + return fragment.replace(routeStripper, ''); | ||
| }, | ||
| // Start the hash change handling, returning `true` if the current URL matches | ||
| @@ -1031,6 +1064,7 @@ | ||
| this.$el = $(element); | ||
| this.el = this.$el[0]; | ||
| if (delegate !== false) this.delegateEvents(); | ||
| + return this; | ||
| }, | ||
| // Set callbacks, where `this.events` is a hash of | ||
| @@ -1187,11 +1221,11 @@ | ||
| // Wrap an optional error callback with a fallback error event. | ||
| Backbone.wrapError = function(onError, originalModel, options) { | ||
| return function(model, resp) { | ||
| - var resp = model === originalModel ? resp : model; | ||
| + resp = model === originalModel ? resp : model; | ||
| if (onError) { | ||
| - onError(model, resp, options); | ||
| + onError(originalModel, resp, options); | ||
| } else { | ||
| - originalModel.trigger('error', model, resp, options); | ||
| + originalModel.trigger('error', originalModel, resp, options); | ||
| } | ||
| }; | ||
| }; | ||
Oops, something went wrong.