mirror of
https://github.com/jashkenas/backbone.git
synced 2026-01-15 01:47:55 -05:00
Merge branch 'master' into collection-update
Conflicts: test/collection.js
This commit is contained in:
14
backbone.js
14
backbone.js
@@ -588,10 +588,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.
|
||||
@@ -619,7 +616,7 @@
|
||||
// Add a model, or list of models to the set. Pass **silent** to avoid
|
||||
// firing the `add` event for every new model.
|
||||
add: function(models, options) {
|
||||
var i, args, length, model, existing;
|
||||
var i, args, length, model, existing, sort;
|
||||
var at = options && options.at;
|
||||
models = _.isArray(models) ? models.slice() : [models];
|
||||
|
||||
@@ -639,6 +636,7 @@
|
||||
if (existing || this._byCid[model.cid]) {
|
||||
if (options && options.merge && existing) {
|
||||
existing.set(model, options);
|
||||
sort = true;
|
||||
}
|
||||
models.splice(i, 1);
|
||||
continue;
|
||||
@@ -651,14 +649,15 @@
|
||||
if (model.id != null) this._byId[model.id] = model;
|
||||
}
|
||||
|
||||
// Update `length` and splice in new models.
|
||||
// See if sorting is needed, update `length` and splice in new models.
|
||||
if (models.length) sort = true;
|
||||
this.length += models.length;
|
||||
args = [at != null ? at : this.models.length, 0];
|
||||
push.apply(args, models);
|
||||
splice.apply(this.models, args);
|
||||
|
||||
// Sort the collection if appropriate.
|
||||
if (this.comparator && at == null) this.sort({silent: true});
|
||||
if (sort && this.comparator && at == null) this.sort({silent: true});
|
||||
|
||||
if (options && options.silent) return this;
|
||||
|
||||
@@ -800,6 +799,7 @@
|
||||
// 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) {
|
||||
if (options && options.parse) models = this.parse(models);
|
||||
for (var i = 0, l = this.models.length; i < l; i++) {
|
||||
this._removeReference(this.models[i]);
|
||||
}
|
||||
|
||||
BIN
docs/images/jolicloud.jpg
Normal file
BIN
docs/images/jolicloud.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 206 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 80 KiB |
24
index.html
24
index.html
@@ -470,6 +470,7 @@
|
||||
<li>– <a href="#examples-easel">Easel</a></li>
|
||||
<li>– <a href="#examples-prose">Prose</a></li>
|
||||
<li>– <a href="#examples-scrollkit">scroll kit</a></li>
|
||||
<li>- <a href="#examples-jolicloud">Jolicloud</a></li>
|
||||
<li>– <a href="#examples-battlefield">Battlefield Play4Free</a></li>
|
||||
<li>– <a href="#examples-syllabus">Syllabus</a></li>
|
||||
<li>– <a href="#examples-salon">Salon.io</a></li>
|
||||
@@ -3217,21 +3218,24 @@ var model = localBackbone.Model.extend(...);
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<h2 id="examples-scrollkit">scroll kit</h2>
|
||||
<h2 id="examples-jolicloud">Jolicloud</h2>
|
||||
|
||||
<p>
|
||||
<a href="http://scrollkit.com/">scroll kit</a> is a new kind of website
|
||||
builder that makes designing a web page feel more like drawing.
|
||||
The workspace is a single-page web application built with Rails and Backbone.js.
|
||||
In scroll kit, every DOM element is associated with a Backbone model, so that
|
||||
style changes that are made to an element automatically update the model
|
||||
and propagate the change across all its views.
|
||||
<a href="http://scrollkit.com/demo">Try it out</a>.
|
||||
<a href="http://www.jolicloud.com/">Jolicloud</a> is an open and independent
|
||||
platform and <a href="http://www.jolicloud.com/jolios">operating system</a>
|
||||
that provides music playback, video streaming, photo browsing and
|
||||
document editing — transforming low cost computers into beautiful cloud devices.
|
||||
The <a href="https://my.jolicloud.com/">new Jolicloud HTML5 app</a> was built
|
||||
from the ground up using Backbone and talks to the
|
||||
<a href="http://developers.jolicloud.com">Jolicloud Platform</a>, which is
|
||||
based on Node.js. Jolicloud works offline using the HTML5 AppCache, extends
|
||||
Backbone.sync to store data in IndexedDB or localStorage, and communicates
|
||||
with the <a href="http://www.jolicloud.com/jolios">Joli OS</a> via WebSockets.
|
||||
</p>
|
||||
|
||||
<div style="text-align: center;">
|
||||
<a href="http://scrollkit.com">
|
||||
<img width="550" height="453" data-original="docs/images/scrollkit.png" alt="scroll kit" class="example_image" />
|
||||
<a href="http://jolicloud.com/">
|
||||
<img width="510" height="384" data-original="docs/images/jolicloud.jpg" alt="Jolicloud" class="example_retina" />
|
||||
</a>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -715,6 +715,60 @@ $(document).ready(function() {
|
||||
this.ajaxSettings.success([model]);
|
||||
});
|
||||
|
||||
test("`sort` shouldn't always fire on `add`", 1, function() {
|
||||
var c = new Backbone.Collection([{id: 1}, {id: 2}, {id: 3}], {
|
||||
comparator: 'id'
|
||||
});
|
||||
c.sort = function(){ ok(true); };
|
||||
c.add([]);
|
||||
c.add({id: 1});
|
||||
c.add([{id: 2}, {id: 3}]);
|
||||
c.add({id: 4});
|
||||
});
|
||||
|
||||
test("#1407 parse option on constructor parses collection and models", 2, function() {
|
||||
var model = {
|
||||
namespace : [{id: 1}, {id:2}]
|
||||
};
|
||||
var Collection = Backbone.Collection.extend({
|
||||
model: Backbone.Model.extend({
|
||||
parse: function(model) {
|
||||
model.name = 'test';
|
||||
return model;
|
||||
}
|
||||
}),
|
||||
parse: function(model) {
|
||||
return model.namespace;
|
||||
}
|
||||
});
|
||||
var c = new Collection(model, {parse:true});
|
||||
|
||||
equal(c.length, 2);
|
||||
equal(c.at(0).get('name'), 'test');
|
||||
});
|
||||
|
||||
test("#1407 parse option on reset parses collection and models", 2, function() {
|
||||
var model = {
|
||||
namespace : [{id: 1}, {id:2}]
|
||||
};
|
||||
var Collection = Backbone.Collection.extend({
|
||||
model: Backbone.Model.extend({
|
||||
parse: function(model) {
|
||||
model.name = 'test';
|
||||
return model;
|
||||
}
|
||||
}),
|
||||
parse: function(model) {
|
||||
return model.namespace;
|
||||
}
|
||||
});
|
||||
var c = new Collection();
|
||||
c.reset(model, {parse:true});
|
||||
|
||||
equal(c.length, 2);
|
||||
equal(c.at(0).get('name'), 'test');
|
||||
});
|
||||
|
||||
test("update", 5, function() {
|
||||
var m1 = new Backbone.Model;
|
||||
var m2 = new Backbone.Model({id: 2});
|
||||
|
||||
@@ -19,17 +19,6 @@
|
||||
<script src="view.js"></script>
|
||||
<script src="sync.js"></script>
|
||||
<script src="speed.js"></script>
|
||||
<script>
|
||||
_.extend(QUnit.config, {
|
||||
|
||||
noglobals: true,
|
||||
|
||||
urlConfig: _.filter(QUnit.config.urlConfig, function(option) {
|
||||
return option.id !== 'noglobals';
|
||||
})
|
||||
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="qunit"></div>
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Backbone Test Suite</title>
|
||||
<link rel="stylesheet" href="vendor/qunit.css" type="text/css" media="screen" />
|
||||
<script type="text/javascript" src="vendor/json2.js"></script>
|
||||
<script type="text/javascript" src="vendor/ender-jeesh.js"></script>
|
||||
<script type="text/javascript" src="vendor/qunit.js"></script>
|
||||
<script type="text/javascript" src="vendor/jslitmus.js"></script>
|
||||
<script type="text/javascript" src="vendor/underscore.js"></script>
|
||||
<script type="text/javascript" src="../backbone.js"></script>
|
||||
|
||||
<script type="text/javascript" src="events.js"></script>
|
||||
<script type="text/javascript" src="model.js"></script>
|
||||
<script type="text/javascript" src="collection.js"></script>
|
||||
<script type="text/javascript" src="router.js"></script>
|
||||
<script type="text/javascript" src="view.js"></script>
|
||||
<script type="text/javascript" src="sync.js"></script>
|
||||
<script type="text/javascript" src="speed.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1 id="qunit-header">Backbone Test Suite</h1>
|
||||
<h2 id="qunit-banner"></h2>
|
||||
<h2 id="qunit-userAgent"></h2>
|
||||
<ol id="qunit-tests"></ol>
|
||||
<br /><br />
|
||||
<h1 id="qunit-header"><a href="#">Backbone Speed Suite</a></h1>
|
||||
<div id="jslitmus_container" style="margin: 20px 10px;"></div>
|
||||
</body>
|
||||
</html>
|
||||
1678
test/vendor/ender-jeesh.js
vendored
1678
test/vendor/ender-jeesh.js
vendored
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user