Update Underscore/Backbone vendors.

Former-commit-id: beb38126acaebf1045c2676aeda037e35f0b99c8
This commit is contained in:
John-David Dalton
2012-09-06 20:56:02 -07:00
parent 102d6d8c84
commit e3ec76418b
16 changed files with 265 additions and 236 deletions

View File

@@ -1118,10 +1118,10 @@
navigate: function(fragment, options) {
if (!History.started) return false;
if (!options || options === true) options = {trigger: options};
var frag = (fragment || '').replace(routeStripper, '');
if (this.fragment === frag) return;
this.fragment = frag;
var url = (frag.indexOf(this.root) !== 0 ? this.root : '') + frag;
fragment = this.getFragment(fragment || '');
if (this.fragment === fragment) return;
this.fragment = fragment;
var url = (fragment.indexOf(this.root) !== 0 ? this.root : '') + fragment;
// If pushState is available, we use it to set the fragment as a real URL.
if (this._hasPushState) {
@@ -1130,13 +1130,13 @@
// If hash changes haven't been explicitly disabled, update the hash
// fragment to store history.
} else if (this._wantsHashChange) {
this._updateHash(this.location, frag, options.replace);
if (this.iframe && (frag !== this.getFragment(this.getHash(this.iframe)))) {
this._updateHash(this.location, fragment, options.replace);
if (this.iframe && (fragment !== this.getFragment(this.getHash(this.iframe)))) {
// Opening and closing the iframe tricks IE7 and earlier to push a
// history entry on hash-tag change. When replace is true, we don't
// want this.
if(!options.replace) this.iframe.document.open().close();
this._updateHash(this.iframe.location, frag, options.replace);
this._updateHash(this.iframe.location, fragment, options.replace);
}
// If you've told us that you explicitly don't want fallback hashchange-

View File

@@ -18,7 +18,7 @@ $(document).ready(function() {
}));
test("Collection: new and sort", 7, function() {
test("new and sort", 7, function() {
equal(col.first(), a, "a should be first");
equal(col.last(), d, "d should be last");
col.comparator = function(a, b) {
@@ -34,7 +34,7 @@ $(document).ready(function() {
equal(col.length, 4);
});
test("Collection: new and parse", 3, function() {
test("new and parse", 3, function() {
var Collection = Backbone.Collection.extend({
parse : function(data) {
return _.filter(data, function(datum) {
@@ -49,13 +49,13 @@ $(document).ready(function() {
strictEqual(collection.last().get('a'), 4);
});
test("Collection: get, getByCid", 3, function() {
test("get, getByCid", 3, function() {
equal(col.get(0), d);
equal(col.get(2), b);
equal(col.getByCid(col.first().cid), col.first());
});
test("Collection: get with non-default ids", 2, function() {
test("get with non-default ids", 2, function() {
var col = new Backbone.Collection();
var MongoModel = Backbone.Model.extend({
idAttribute: '_id'
@@ -67,7 +67,7 @@ $(document).ready(function() {
equal(col.get(101), model);
});
test("Collection: update index when id changes", 3, function() {
test("update index when id changes", 3, function() {
var col = new Backbone.Collection();
col.add([
{id : 0, name : 'one'},
@@ -80,15 +80,15 @@ $(document).ready(function() {
equal(col.get(101).get('name'), 'one');
});
test("Collection: at", 1, function() {
test("at", 1, function() {
equal(col.at(2), c);
});
test("Collection: pluck", 1, function() {
test("pluck", 1, function() {
equal(col.pluck('label').join(' '), 'a b c d');
});
test("Collection: add", 11, function() {
test("add", 11, function() {
var added, opts, secondAdded;
added = opts = secondAdded = null;
e = new Backbone.Model({id: 10, label : 'e'});
@@ -120,7 +120,7 @@ $(document).ready(function() {
equal(atCol.last(), h);
});
test("Collection: add multiple models", 6, function() {
test("add multiple models", 6, function() {
var col = new Backbone.Collection([{at: 0}, {at: 1}, {at: 9}]);
col.add([{at: 2}, {at: 3}, {at: 4}, {at: 5}, {at: 6}, {at: 7}, {at: 8}], {at: 2});
for (var i = 0; i <= 5; i++) {
@@ -128,7 +128,7 @@ $(document).ready(function() {
}
});
test("Collection: add; at should have preference over comparator", 1, function() {
test("add; at should have preference over comparator", 1, function() {
var Col = Backbone.Collection.extend({
comparator: function(a,b) {
return a.id > b.id ? -1 : 1;
@@ -141,19 +141,19 @@ $(document).ready(function() {
equal(col.pluck('id').join(' '), '3 1 2');
});
test("Collection: can't add model to collection twice", function() {
test("can't add model to collection twice", function() {
var col = new Backbone.Collection([{id: 1}, {id: 2}, {id: 1}, {id: 2}, {id: 3}]);
equal(col.pluck('id').join(' '), '1 2 3');
});
test("Collection: can't add different model with same id to collection twice", 1, function() {
test("can't add different model with same id to collection twice", 1, function() {
var col = new Backbone.Collection;
col.unshift({id: 101});
col.add({id: 101});
equal(col.length, 1);
});
test("Collection: merge in duplicate models with {merge: true}", 3, function() {
test("merge in duplicate models with {merge: true}", 3, function() {
var col = new Backbone.Collection;
col.add([{id: 1, name: 'Moe'}, {id: 2, name: 'Curly'}, {id: 3, name: 'Larry'}]);
col.add({id: 1, name: 'Moses'});
@@ -164,7 +164,7 @@ $(document).ready(function() {
equal(col.first().get('name'), 'Tim');
});
test("Collection: add model to multiple collections", 10, function() {
test("add model to multiple collections", 10, function() {
var counter = 0;
var e = new Backbone.Model({id: 10, label : 'e'});
e.on('add', function(model, collection) {
@@ -192,7 +192,7 @@ $(document).ready(function() {
equal(e.collection, colE);
});
test("Collection: add model with parse", 1, function() {
test("add model with parse", 1, function() {
var Model = Backbone.Model.extend({
parse: function(obj) {
obj.value += 1;
@@ -206,7 +206,7 @@ $(document).ready(function() {
equal(col.at(0).get('value'), 2);
});
test("Collection: add model to collection with sort()-style comparator", 3, function() {
test("add model to collection with sort()-style comparator", 3, function() {
var col = new Backbone.Collection;
col.comparator = function(a, b) {
return a.get('name') < b.get('name') ? -1 : 1;
@@ -222,7 +222,7 @@ $(document).ready(function() {
equal(col.indexOf(tom), 2);
});
test("Collection: comparator that depends on `this`", 1, function() {
test("comparator that depends on `this`", 1, function() {
var col = new Backbone.Collection;
col.negative = function(num) {
return -num;
@@ -234,7 +234,7 @@ $(document).ready(function() {
equal(col.pluck('id').join(' '), '3 2 1');
});
test("Collection: remove", 5, function() {
test("remove", 5, function() {
var removed = null;
var otherRemoved = null;
col.on('remove', function(model, col, options) {
@@ -251,20 +251,20 @@ $(document).ready(function() {
equal(otherRemoved, null);
});
test("Collection: shift and pop", 2, function() {
test("shift and pop", 2, function() {
var col = new Backbone.Collection([{a: 'a'}, {b: 'b'}, {c: 'c'}]);
equal(col.shift().get('a'), 'a');
equal(col.pop().get('c'), 'c');
});
test("Collection: slice", 2, function() {
test("slice", 2, function() {
var col = new Backbone.Collection([{a: 'a'}, {b: 'b'}, {c: 'c'}]);
var array = col.slice(1, 3);
equal(array.length, 2);
equal(array[0].get('b'), 'b');
});
test("Collection: events are unbound on remove", 3, function() {
test("events are unbound on remove", 3, function() {
var counter = 0;
var dj = new Backbone.Model();
var emcees = new Backbone.Collection([dj]);
@@ -277,7 +277,7 @@ $(document).ready(function() {
equal(counter, 1);
});
test("Collection: remove in multiple collections", 7, function() {
test("remove in multiple collections", 7, function() {
var modelData = {
id : 5,
title : 'Othello'
@@ -301,7 +301,7 @@ $(document).ready(function() {
equal(passed, true);
});
test("Collection: remove same model in multiple collection", 16, function() {
test("remove same model in multiple collection", 16, function() {
var counter = 0;
var e = new Backbone.Model({id: 5, title: 'Othello'});
e.on('remove', function(model, collection) {
@@ -335,7 +335,7 @@ $(document).ready(function() {
equal(counter, 2);
});
test("Collection: model destroy removes from all collections", 3, function() {
test("model destroy removes from all collections", 3, function() {
var e = new Backbone.Model({id: 5, title: 'Othello'});
e.sync = function(method, model, options) { options.success({}); };
var colE = new Backbone.Collection([e]);
@@ -357,7 +357,7 @@ $(document).ready(function() {
equal(undefined, e.collection);
});
test("Collection: fetch", 4, function() {
test("fetch", 4, function() {
var collection = new Backbone.Collection;
collection.url = '/test';
collection.fetch();
@@ -369,7 +369,7 @@ $(document).ready(function() {
equal(this.syncArgs.options.parse, false);
});
test("Collection: create", 4, function() {
test("create", 4, function() {
var collection = new Backbone.Collection;
collection.url = '/test';
var model = collection.create({label: 'f'}, {wait: true});
@@ -379,7 +379,7 @@ $(document).ready(function() {
equal(model.collection, collection);
});
test("Collection: create enforces validation", 1, function() {
test("create enforces validation", 1, function() {
var ValidatingModel = Backbone.Model.extend({
validate: function(attrs) {
return "fail";
@@ -392,7 +392,7 @@ $(document).ready(function() {
equal(col.create({"foo":"bar"}), false);
});
test("Collection: a failing create runs the error callback", 1, function() {
test("a failing create runs the error callback", 1, function() {
var ValidatingModel = Backbone.Model.extend({
validate: function(attrs) {
return "fail";
@@ -408,7 +408,7 @@ $(document).ready(function() {
equal(flag, true);
});
test("collection: initialize", 1, function() {
test("initialize", 1, function() {
var Collection = Backbone.Collection.extend({
initialize: function() {
this.one = 1;
@@ -418,11 +418,11 @@ $(document).ready(function() {
equal(coll.one, 1);
});
test("Collection: toJSON", 1, function() {
test("toJSON", 1, function() {
equal(JSON.stringify(col), '[{"id":3,"label":"a"},{"id":2,"label":"b"},{"id":1,"label":"c"},{"id":0,"label":"d"}]');
});
test("Collection: where", 6, function() {
test("where", 6, function() {
var coll = new Backbone.Collection([
{a: 1},
{a: 1},
@@ -438,7 +438,7 @@ $(document).ready(function() {
equal(coll.where({a: 1, b: 2}).length, 1);
});
test("Collection: Underscore methods", 13, function() {
test("Underscore methods", 13, function() {
equal(col.map(function(model){ return model.get('label'); }).join(' '), 'a b c d');
equal(col.any(function(model){ return model.id === 100; }), false);
equal(col.any(function(model){ return model.id === 0; }), true);
@@ -458,7 +458,7 @@ $(document).ready(function() {
[4, 0]);
});
test("Collection: reset", 10, function() {
test("reset", 10, function() {
var resetCount = 0;
var models = col.models;
col.on('reset', function() { resetCount += 1; });
@@ -477,7 +477,7 @@ $(document).ready(function() {
ok(_.isEqual(col.last().attributes, d.attributes));
});
test("Collection: reset passes caller options", 3, function() {
test("reset passes caller options", 3, function() {
var Model = Backbone.Model.extend({
initialize: function(attrs, options) {
this.model_parameter = options.model_parameter;
@@ -491,14 +491,14 @@ $(document).ready(function() {
});
});
test("Collection: trigger custom events on models", 1, function() {
test("trigger custom events on models", 1, function() {
var fired = null;
a.on("custom", function() { fired = true; });
a.trigger("custom");
equal(fired, true);
});
test("Collection: add does not alter arguments", 2, function(){
test("add does not alter arguments", 2, function(){
var attrs = {};
var models = [attrs];
new Backbone.Collection().add(models);
@@ -549,7 +549,7 @@ $(document).ready(function() {
});
});
test("Collection: index with comparator", 4, function() {
test("index with comparator", 4, function() {
var counter = 0;
var col = new Backbone.Collection([{id: 2}, {id: 4}], {
comparator: function(model){ return model.id; }
@@ -566,7 +566,7 @@ $(document).ready(function() {
col.add([{id: 3}, {id: 1}]);
});
test("Collection: throwing during add leaves consistent state", 4, function() {
test("throwing during add leaves consistent state", 4, function() {
var col = new Backbone.Collection();
col.on('test', function() { ok(false); });
col.model = Backbone.Model.extend({
@@ -580,7 +580,7 @@ $(document).ready(function() {
equal(col.length, 0);
});
test("Collection: multiple copies of the same model", 3, function() {
test("multiple copies of the same model", 3, function() {
var col = new Backbone.Collection();
var model = new Backbone.Model();
col.add([model, model]);
@@ -613,7 +613,7 @@ $(document).ready(function() {
ok(!collection.get('undefined'));
});
test("Collection: falsy comparator", 4, function(){
test("falsy comparator", 4, function(){
var Col = Backbone.Collection.extend({
comparator: function(model){ return model.id; }
});

View File

@@ -2,7 +2,7 @@ $(document).ready(function() {
module("Backbone.Events");
test("Events: on and trigger", 2, function() {
test("on and trigger", 2, function() {
var obj = { counter: 0 };
_.extend(obj,Backbone.Events);
obj.on('event', function() { obj.counter += 1; });
@@ -15,7 +15,7 @@ $(document).ready(function() {
equal(obj.counter, 5, 'counter should be incremented five times.');
});
test("Events: binding and triggering multiple events", 4, function() {
test("binding and triggering multiple events", 4, function() {
var obj = { counter: 0 };
_.extend(obj,Backbone.Events);
@@ -35,7 +35,7 @@ $(document).ready(function() {
equal(obj.counter, 5);
});
test("Events: trigger all for each event", 3, function() {
test("trigger all for each event", 3, function() {
var a, b, obj = { counter: 0 };
_.extend(obj, Backbone.Events);
obj.on('all', function(event) {
@@ -49,7 +49,7 @@ $(document).ready(function() {
equal(obj.counter, 2);
});
test("Events: on, then unbind all functions", 1, function() {
test("on, then unbind all functions", 1, function() {
var obj = { counter: 0 };
_.extend(obj,Backbone.Events);
var callback = function() { obj.counter += 1; };
@@ -60,7 +60,7 @@ $(document).ready(function() {
equal(obj.counter, 1, 'counter should have only been incremented once.');
});
test("Events: bind two callbacks, unbind only one", 2, function() {
test("bind two callbacks, unbind only one", 2, function() {
var obj = { counterA: 0, counterB: 0 };
_.extend(obj,Backbone.Events);
var callback = function() { obj.counterA += 1; };
@@ -73,7 +73,7 @@ $(document).ready(function() {
equal(obj.counterB, 2, 'counterB should have been incremented twice.');
});
test("Events: unbind a callback in the midst of it firing", 1, function() {
test("unbind a callback in the midst of it firing", 1, function() {
var obj = {counter: 0};
_.extend(obj, Backbone.Events);
var callback = function() {
@@ -87,7 +87,7 @@ $(document).ready(function() {
equal(obj.counter, 1, 'the callback should have been unbound.');
});
test("Events: two binds that unbind themeselves", 2, function() {
test("two binds that unbind themeselves", 2, function() {
var obj = { counterA: 0, counterB: 0 };
_.extend(obj,Backbone.Events);
var incrA = function(){ obj.counterA += 1; obj.off('event', incrA); };
@@ -101,7 +101,7 @@ $(document).ready(function() {
equal(obj.counterB, 1, 'counterB should have only been incremented once.');
});
test("Events: bind a callback with a supplied context", 1, function () {
test("bind a callback with a supplied context", 1, function () {
var TestClass = function () {
return this;
};
@@ -114,7 +114,7 @@ $(document).ready(function() {
obj.trigger('event');
});
test("Events: nested trigger with unbind", 1, function () {
test("nested trigger with unbind", 1, function () {
var obj = { counter: 0 };
_.extend(obj, Backbone.Events);
var incr1 = function(){ obj.counter += 1; obj.off('event', incr1); obj.trigger('event'); };
@@ -125,7 +125,7 @@ $(document).ready(function() {
equal(obj.counter, 3, 'counter should have been incremented three times');
});
test("Events: callback list is not altered during trigger", 2, function () {
test("callback list is not altered during trigger", 2, function () {
var counter = 0, obj = _.extend({}, Backbone.Events);
var incr = function(){ counter++; };
obj.on('event', function(){ obj.on('event', incr).on('all', incr); })

View File

@@ -22,7 +22,7 @@ $(document).ready(function() {
}));
test("Model: initialize", 3, function() {
test("initialize", 3, function() {
var Model = Backbone.Model.extend({
initialize: function() {
this.one = 1;
@@ -34,7 +34,7 @@ $(document).ready(function() {
equal(model.collection, collection);
});
test("Model: initialize with attributes and options", 1, function() {
test("initialize with attributes and options", 1, function() {
var Model = Backbone.Model.extend({
initialize: function(attributes, options) {
this.one = options.one;
@@ -44,7 +44,7 @@ $(document).ready(function() {
equal(model.one, 1);
});
test("Model: initialize with parsed attributes", 1, function() {
test("initialize with parsed attributes", 1, function() {
var Model = Backbone.Model.extend({
parse: function(obj) {
obj.value += 1;
@@ -55,7 +55,7 @@ $(document).ready(function() {
equal(model.get('value'), 2);
});
test("Model: url", 3, function() {
test("url", 3, function() {
doc.urlRoot = null;
equal(doc.url(), '/collection/1-the-tempest');
doc.collection.url = '/collection/';
@@ -65,7 +65,7 @@ $(document).ready(function() {
doc.collection = collection;
});
test("Model: url when using urlRoot, and uri encoding", 2, function() {
test("url when using urlRoot, and uri encoding", 2, function() {
var Model = Backbone.Model.extend({
urlRoot: '/collection'
});
@@ -75,7 +75,7 @@ $(document).ready(function() {
equal(model.url(), '/collection/%2B1%2B');
});
test("Model: url when using urlRoot as a function to determine urlRoot at runtime", 2, function() {
test("url when using urlRoot as a function to determine urlRoot at runtime", 2, function() {
var Model = Backbone.Model.extend({
urlRoot: function() {
return '/nested/' + this.get('parent_id') + '/collection';
@@ -88,7 +88,7 @@ $(document).ready(function() {
equal(model.url(), '/nested/1/collection/2');
});
test("Model: clone", 8, function() {
test("clone", 8, function() {
var a = new Backbone.Model({ 'foo': 1, 'bar': 2, 'baz': 3});
var b = a.clone();
equal(a.get('foo'), 1);
@@ -102,7 +102,7 @@ $(document).ready(function() {
equal(b.get('foo'), 1, "Changing a parent attribute does not change the clone.");
});
test("Model: isNew", 6, function() {
test("isNew", 6, function() {
var a = new Backbone.Model({ 'foo': 1, 'bar': 2, 'baz': 3});
ok(a.isNew(), "it should be new");
a = new Backbone.Model({ 'foo': 1, 'bar': 2, 'baz': 3, 'id': -5 });
@@ -114,12 +114,12 @@ $(document).ready(function() {
ok(!new Backbone.Model({ 'id': -5 }).isNew(), "is false for a negative integer");
});
test("Model: get", 2, function() {
test("get", 2, function() {
equal(doc.get('title'), 'The Tempest');
equal(doc.get('author'), 'Bill Shakespeare');
});
test("Model: escape", 5, function() {
test("escape", 5, function() {
equal(doc.escape('title'), 'The Tempest');
doc.set({audience: 'Bill & Bob'});
equal(doc.escape('audience'), 'Bill &amp; Bob');
@@ -131,7 +131,7 @@ $(document).ready(function() {
equal(doc.escape('audience'), '');
});
test("Model: has", 10, function() {
test("has", 10, function() {
var model = new Backbone.Model();
strictEqual(model.has('name'), false);
@@ -161,7 +161,7 @@ $(document).ready(function() {
strictEqual(model.has('undefined'), false);
});
test("Model: set and unset", 8, function() {
test("set and unset", 8, function() {
var a = new Backbone.Model({id: 'id', foo: 1, bar: 2, baz: 3});
var changeCount = 0;
a.on("change:foo", function() { changeCount += 1; });
@@ -184,7 +184,7 @@ $(document).ready(function() {
equal(a.id, undefined, "Unsetting the id should remove the id property.");
});
test("Model: multiple unsets", 1, function() {
test("multiple unsets", 1, function() {
var i = 0;
var counter = function(){ i++; };
var model = new Backbone.Model({a: 1});
@@ -195,7 +195,7 @@ $(document).ready(function() {
equal(i, 2, 'Unset does not fire an event for missing attributes.');
});
test("Model: unset and changedAttributes", 2, function() {
test("unset and changedAttributes", 2, function() {
var model = new Backbone.Model({a: 1});
model.unset('a', {silent: true});
var changedAttributes = model.changedAttributes();
@@ -205,7 +205,7 @@ $(document).ready(function() {
ok('a' in changedAttributes, 'changedAttributes should contain unset properties when running changedAttributes again after an unset.');
});
test("Model: using a non-default id attribute.", 5, function() {
test("using a non-default id attribute.", 5, function() {
var MongoModel = Backbone.Model.extend({idAttribute : '_id'});
var model = new MongoModel({id: 'eye-dee', _id: 25, title: 'Model'});
equal(model.get('id'), 'eye-dee');
@@ -216,13 +216,13 @@ $(document).ready(function() {
equal(model.isNew(), true);
});
test("Model: set an empty string", 1, function() {
test("set an empty string", 1, function() {
var model = new Backbone.Model({name : "Model"});
model.set({name : ''});
equal(model.get('name'), '');
});
test("Model: clear", 3, function() {
test("clear", 3, function() {
var changed;
var model = new Backbone.Model({id: 1, name : "Model"});
model.on("change:name", function(){ changed = true; });
@@ -235,7 +235,7 @@ $(document).ready(function() {
equal(model.get('name'), undefined);
});
test("Model: defaults", 4, function() {
test("defaults", 4, function() {
var Defaulted = Backbone.Model.extend({
defaults: {
"one": 1,
@@ -258,7 +258,7 @@ $(document).ready(function() {
equal(model.get('two'), null);
});
test("Model: change, hasChanged, changedAttributes, previous, previousAttributes", 12, function() {
test("change, hasChanged, changedAttributes, previous, previousAttributes", 12, function() {
var model = new Backbone.Model({name : "Tim", age : 10});
equal(model.changedAttributes(), false);
model.on('change', function() {
@@ -279,14 +279,14 @@ $(document).ready(function() {
});
test("Model: changedAttributes", 3, function() {
test("changedAttributes", 3, function() {
var model = new Backbone.Model({a: 'a', b: 'b'});
equal(model.changedAttributes(), false);
equal(model.changedAttributes({a: 'a'}), false);
equal(model.changedAttributes({a: 'b'}).a, 'b');
});
test("Model: change with options", 2, function() {
test("change with options", 2, function() {
var value;
var model = new Backbone.Model({name: 'Rob'});
model.on('change', function(model, options) {
@@ -299,7 +299,7 @@ $(document).ready(function() {
equal(value, 'Ms. Sue');
});
test("Model: change after initialize", 1, function () {
test("change after initialize", 1, function () {
var changed = 0;
var attrs = {id: 1, label: 'c'};
var obj = new Backbone.Model(attrs);
@@ -308,7 +308,7 @@ $(document).ready(function() {
equal(changed, 0);
});
test("Model: save within change event", 1, function () {
test("save within change event", 1, function () {
var env = this;
var model = new Backbone.Model({firstName : "Taylor", lastName: "Swift"});
model.url = '/test';
@@ -319,7 +319,7 @@ $(document).ready(function() {
model.set({lastName: 'Hicks'});
});
test("Model: validate after save", 1, function() {
test("validate after save", 1, function() {
var lastError, model = new Backbone.Model();
model.validate = function(attrs) {
if (attrs.admin) return "Can't change admin status.";
@@ -334,7 +334,7 @@ $(document).ready(function() {
equal(lastError, "Can't change admin status.");
});
test("Model: isValid", 5, function() {
test("isValid", 5, function() {
var model = new Backbone.Model({valid: true});
model.validate = function(attrs) {
if (!attrs.valid) return "invalid";
@@ -346,13 +346,13 @@ $(document).ready(function() {
equal(model.isValid(), false);
});
test("Model: save", 2, function() {
test("save", 2, function() {
doc.save({title : "Henry V"});
equal(this.syncArgs.method, 'update');
ok(_.isEqual(this.syncArgs.model, doc));
});
test("Model: save in positional style", 1, function() {
test("save in positional style", 1, function() {
var model = new Backbone.Model();
model.sync = function(method, model, options) {
options.success();
@@ -363,13 +363,13 @@ $(document).ready(function() {
test("Model: fetch", 2, function() {
test("fetch", 2, function() {
doc.fetch();
equal(this.syncArgs.method, 'read');
ok(_.isEqual(this.syncArgs.model, doc));
});
test("Model: destroy", 3, function() {
test("destroy", 3, function() {
doc.destroy();
equal(this.syncArgs.method, 'delete');
ok(_.isEqual(this.syncArgs.model, doc));
@@ -378,14 +378,14 @@ $(document).ready(function() {
equal(newModel.destroy(), false);
});
test("Model: non-persisted destroy", 1, function() {
test("non-persisted destroy", 1, function() {
var a = new Backbone.Model({ 'foo': 1, 'bar': 2, 'baz': 3});
a.sync = function() { throw "should not be called"; };
a.destroy();
ok(true, "non-persisted model should not call sync");
});
test("Model: validate", 7, function() {
test("validate", 7, function() {
var lastError;
var model = new Backbone.Model();
model.validate = function(attrs) {
@@ -406,7 +406,7 @@ $(document).ready(function() {
equal(model.get('a'), 100);
});
test("Model: validate on unset and clear", 6, function() {
test("validate on unset and clear", 6, function() {
var error;
var model = new Backbone.Model({name: "One"});
model.validate = function(attrs) {
@@ -428,7 +428,7 @@ $(document).ready(function() {
equal(model.get('name'), undefined);
});
test("Model: validate with error callback", 8, function() {
test("validate with error callback", 8, function() {
var lastError, boundError;
var model = new Backbone.Model();
model.validate = function(attrs) {
@@ -452,7 +452,7 @@ $(document).ready(function() {
equal(boundError, true);
});
test("Model: defaults always extend attrs (#459)", 2, function() {
test("defaults always extend attrs (#459)", 2, function() {
var Defaulted = Backbone.Model.extend({
defaults: {one: 1},
initialize : function(attrs, opts) {
@@ -463,7 +463,7 @@ $(document).ready(function() {
var emptyattrs = new Defaulted();
});
test("Model: Inherit class properties", 6, function() {
test("Inherit class properties", 6, function() {
var Parent = Backbone.Model.extend({
instancePropSame: function() {},
instancePropDiff: function() {}
@@ -487,7 +487,7 @@ $(document).ready(function() {
notEqual(Child.prototype.instancePropDiff, undefined);
});
test("Model: Nested change events don't clobber previous attributes", 4, function() {
test("Nested change events don't clobber previous attributes", 4, function() {
new Backbone.Model()
.on('change:state', function(model, newState) {
equal(model.previous('state'), undefined);

View File

@@ -2,7 +2,7 @@ $(document).ready(function() {
module("Backbone.noConflict");
test('Backbone.noConflict', 2, function() {
test('noConflict', 2, function() {
var noconflictBackbone = Backbone.noConflict();
equal(window.Backbone, undefined, 'Returned window.Backbone');
window.Backbone = noconflictBackbone;

View File

@@ -126,11 +126,11 @@ $(document).ready(function() {
});
test("Router: initialize", 1, function() {
test("initialize", 1, function() {
equal(router.testing, 101);
});
test("Router: routes (simple)", 4, function() {
test("routes (simple)", 4, function() {
location.replace('http://example.com#search/news');
Backbone.history.checkUrl();
equal(router.query, 'news');
@@ -139,26 +139,26 @@ $(document).ready(function() {
equal(lastArgs[0], 'news');
});
test("Router: routes (two part)", 2, function() {
test("routes (two part)", 2, function() {
location.replace('http://example.com#search/nyc/p10');
Backbone.history.checkUrl();
equal(router.query, 'nyc');
equal(router.page, '10');
});
test("Router: routes via navigate", 2, function() {
test("routes via navigate", 2, function() {
Backbone.history.navigate('search/manhattan/p20', {trigger: true});
equal(router.query, 'manhattan');
equal(router.page, '20');
});
test("Router: routes via navigate for backwards-compatibility", 2, function() {
test("routes via navigate for backwards-compatibility", 2, function() {
Backbone.history.navigate('search/manhattan/p20', true);
equal(router.query, 'manhattan');
equal(router.page, '20');
});
test("Router: route precedence via navigate", 6, function(){
test("route precedence via navigate", 6, function(){
// check both 0.9.x and backwards-compatibility options
_.each([ { trigger: true }, true ], function( options ){
Backbone.history.navigate('contacts', options);
@@ -178,13 +178,13 @@ $(document).ready(function() {
Backbone.history.navigate('/route');
});
test("Router: use implicit callback if none provided", 1, function() {
test("use implicit callback if none provided", 1, function() {
router.count = 0;
router.navigate('implicit', {trigger: true});
equal(router.count, 1);
});
test("Router: routes via navigate with {replace: true}", 1, function() {
test("routes via navigate with {replace: true}", 1, function() {
location.replace('http://example.com#start_here');
Backbone.history.checkUrl();
location.replace = function(href) {
@@ -193,13 +193,13 @@ $(document).ready(function() {
Backbone.history.navigate('end_here', {replace: true});
});
test("Router: routes (splats)", 1, function() {
test("routes (splats)", 1, function() {
location.replace('http://example.com#splat/long-list/of/splatted_99args/end');
Backbone.history.checkUrl();
equal(router.args, 'long-list/of/splatted_99args');
});
test("Router: routes (complex)", 3, function() {
test("routes (complex)", 3, function() {
location.replace('http://example.com#one/two/three/complex-part/four/five/six/seven');
Backbone.history.checkUrl();
equal(router.first, 'one/two/three');
@@ -207,7 +207,7 @@ $(document).ready(function() {
equal(router.rest, 'four/five/six/seven');
});
test("Router: routes (query)", 5, function() {
test("routes (query)", 5, function() {
location.replace('http://example.com#mandel?a=b&c=d');
Backbone.history.checkUrl();
equal(router.entity, 'mandel');
@@ -217,13 +217,13 @@ $(document).ready(function() {
equal(lastArgs[1], 'a=b&c=d');
});
test("Router: routes (anything)", 1, function() {
test("routes (anything)", 1, function() {
location.replace('http://example.com#doesnt-match-a-route');
Backbone.history.checkUrl();
equal(router.anything, 'doesnt-match-a-route');
});
test("Router: fires event when router doesn't have callback on it", 1, function() {
test("fires event when router doesn't have callback on it", 1, function() {
router.on("route:noCallback", function(){ ok(true); });
location.replace('http://example.com#noCallback');
Backbone.history.checkUrl();
@@ -251,7 +251,7 @@ $(document).ready(function() {
if (!Backbone.history.iframe) ok(true);
});
test("Router: route callback gets passed decoded values", 3, function() {
test("route callback gets passed decoded values", 3, function() {
var route = 'has%2Fslash/complex-has%23hash/has%20space';
Backbone.history.navigate(route, {trigger: true});
equal(router.first, 'has/slash');
@@ -259,7 +259,7 @@ $(document).ready(function() {
equal(router.rest, 'has space');
});
test("Router: correctly handles URLs with % (#868)", 3, function() {
test("correctly handles URLs with % (#868)", 3, function() {
location.replace('http://example.com#search/fat%3A1.5%25');
Backbone.history.checkUrl();
location.replace('http://example.com#search/fat');
@@ -317,7 +317,7 @@ $(document).ready(function() {
strictEqual(Backbone.history.fragment, 'x');
});
test("Router: Normalize root.", 1, function() {
test("Normalize root.", 1, function() {
Backbone.history.stop();
location.replace('http://example.com/root');
Backbone.history = new Backbone.History({
@@ -336,7 +336,7 @@ $(document).ready(function() {
Backbone.history.navigate('fragment');
});
test("Router: Normalize root.", 1, function() {
test("Normalize root.", 1, function() {
Backbone.history.stop();
location.replace('http://example.com/root#fragment');
Backbone.history = new Backbone.History({
@@ -354,7 +354,7 @@ $(document).ready(function() {
});
});
test("Router: Normalize root.", 1, function() {
test("Normalize root.", 1, function() {
Backbone.history.stop();
location.replace('http://example.com/root');
Backbone.history = new Backbone.History({location: location});

View File

@@ -21,7 +21,7 @@ $(document).ready(function() {
}));
test("sync: read", 4, function() {
test("read", 4, function() {
library.fetch();
equal(this.ajaxSettings.url, '/library');
equal(this.ajaxSettings.type, 'GET');
@@ -29,14 +29,14 @@ $(document).ready(function() {
ok(_.isEmpty(this.ajaxSettings.data));
});
test("sync: passing data", 3, function() {
test("passing data", 3, function() {
library.fetch({data: {a: 'a', one: 1}});
equal(this.ajaxSettings.url, '/library');
equal(this.ajaxSettings.data.a, 'a');
equal(this.ajaxSettings.data.one, 1);
});
test("sync: create", 6, function() {
test("create", 6, function() {
equal(this.ajaxSettings.url, '/library');
equal(this.ajaxSettings.type, 'POST');
equal(this.ajaxSettings.dataType, 'json');
@@ -46,7 +46,7 @@ $(document).ready(function() {
equal(data.length, 123);
});
test("sync: update", 7, function() {
test("update", 7, function() {
library.first().save({id: '1-the-tempest', author: 'William Shakespeare'});
equal(this.ajaxSettings.url, '/library/1-the-tempest');
equal(this.ajaxSettings.type, 'PUT');
@@ -58,7 +58,7 @@ $(document).ready(function() {
equal(data.length, 123);
});
test("sync: update with emulateHTTP and emulateJSON", 7, function() {
test("update with emulateHTTP and emulateJSON", 7, function() {
Backbone.emulateHTTP = Backbone.emulateJSON = true;
library.first().save({id: '2-the-tempest', author: 'Tim Shakespeare'});
equal(this.ajaxSettings.url, '/library/2-the-tempest');
@@ -72,7 +72,7 @@ $(document).ready(function() {
Backbone.emulateHTTP = Backbone.emulateJSON = false;
});
test("sync: update with just emulateHTTP", 6, function() {
test("update with just emulateHTTP", 6, function() {
Backbone.emulateHTTP = true;
library.first().save({id: '2-the-tempest', author: 'Tim Shakespeare'});
equal(this.ajaxSettings.url, '/library/2-the-tempest');
@@ -85,7 +85,7 @@ $(document).ready(function() {
Backbone.emulateHTTP = false;
});
test("sync: update with just emulateJSON", 6, function() {
test("update with just emulateJSON", 6, function() {
Backbone.emulateJSON = true;
library.first().save({id: '2-the-tempest', author: 'Tim Shakespeare'});
equal(this.ajaxSettings.url, '/library/2-the-tempest');
@@ -98,7 +98,7 @@ $(document).ready(function() {
Backbone.emulateJSON = false;
});
test("sync: read model", 3, function() {
test("read model", 3, function() {
library.first().save({id: '2-the-tempest', author: 'Tim Shakespeare'});
library.first().fetch();
equal(this.ajaxSettings.url, '/library/2-the-tempest');
@@ -106,7 +106,7 @@ $(document).ready(function() {
ok(_.isEmpty(this.ajaxSettings.data));
});
test("sync: destroy", 3, function() {
test("destroy", 3, function() {
library.first().save({id: '2-the-tempest', author: 'Tim Shakespeare'});
library.first().destroy({wait: true});
equal(this.ajaxSettings.url, '/library/2-the-tempest');
@@ -114,7 +114,7 @@ $(document).ready(function() {
equal(this.ajaxSettings.data, null);
});
test("sync: destroy with emulateHTTP", 3, function() {
test("destroy with emulateHTTP", 3, function() {
library.first().save({id: '2-the-tempest', author: 'Tim Shakespeare'});
Backbone.emulateHTTP = Backbone.emulateJSON = true;
library.first().destroy();
@@ -124,7 +124,7 @@ $(document).ready(function() {
Backbone.emulateHTTP = Backbone.emulateJSON = false;
});
test("sync: urlError", 2, function() {
test("urlError", 2, function() {
var model = new Backbone.Model();
raises(function() {
model.fetch();

View File

@@ -13,27 +13,27 @@ $(document).ready(function() {
});
test("View: constructor", 4, function() {
test("constructor", 4, function() {
equal(view.el.id, 'test-view');
equal(view.el.className, 'test-view');
equal(view.options.id, 'test-view');
equal(view.options.className, 'test-view');
});
test("View: jQuery", 2, function() {
test("jQuery", 2, function() {
view.setElement(document.body);
ok(view.$('#qunit-header a').get(0).innerHTML.match(/Backbone Test Suite/));
ok(view.$('#qunit-header a').get(1).innerHTML.match(/Backbone Speed Suite/));
});
test("View: make", 3, function() {
test("make", 3, function() {
var div = view.make('div', {id: 'test-div'}, "one two three");
equal(div.tagName.toLowerCase(), 'div');
equal(div.id, 'test-div');
equal($(div).text(), 'one two three');
});
test("View: make can take falsy values for content", 2, function() {
test("make can take falsy values for content", 2, function() {
var div = view.make('div', {id: 'test-div'}, 0);
equal($(div).text(), '0');
@@ -41,7 +41,7 @@ $(document).ready(function() {
equal($(div).text(), '');
});
test("View: initialize", 1, function() {
test("initialize", 1, function() {
var View = Backbone.View.extend({
initialize: function() {
this.one = 1;
@@ -51,7 +51,7 @@ $(document).ready(function() {
equal(view.one, 1);
});
test("View: delegateEvents", 6, function() {
test("delegateEvents", 6, function() {
var counter = 0;
var counter2 = 0;
view.setElement(document.body);
@@ -71,7 +71,7 @@ $(document).ready(function() {
equal(counter2, 3);
});
test("View: delegateEvents allows functions for callbacks", 3, function() {
test("delegateEvents allows functions for callbacks", 3, function() {
view.counter = 0;
view.setElement("#qunit-banner");
var events = {"click": function() { this.counter++; }};
@@ -85,7 +85,7 @@ $(document).ready(function() {
equal(view.counter, 3);
});
test("View: undelegateEvents", 6, function() {
test("undelegateEvents", 6, function() {
var counter = 0;
var counter2 = 0;
view.setElement(document.body);
@@ -107,7 +107,7 @@ $(document).ready(function() {
equal(counter2, 3);
});
test("View: _ensureElement with DOM node el", 1, function() {
test("_ensureElement with DOM node el", 1, function() {
var ViewClass = Backbone.View.extend({
el: document.body
});
@@ -115,7 +115,7 @@ $(document).ready(function() {
equal(view.el, document.body);
});
test("View: _ensureElement with string el", 3, function() {
test("_ensureElement with string el", 3, function() {
var ViewClass = Backbone.View.extend({
el: "body"
});
@@ -135,7 +135,7 @@ $(document).ready(function() {
ok(!view.el);
});
test("View: with className and id functions", 2, function() {
test("with className and id functions", 2, function() {
var View = Backbone.View.extend({
className: function() {
return 'className';
@@ -149,13 +149,13 @@ $(document).ready(function() {
strictEqual(view.el.id, 'id');
});
test("View: with attributes", 2, function() {
test("with attributes", 2, function() {
var view = new Backbone.View({attributes : {'class': 'one', id: 'two'}});
equal(view.el.className, 'one');
equal(view.el.id, 'two');
});
test("View: with attributes as a function", 1, function() {
test("with attributes as a function", 1, function() {
var viewClass = Backbone.View.extend({
attributes: function() {
return {'class': 'dynamic'};
@@ -164,7 +164,7 @@ $(document).ready(function() {
equal((new viewClass).el.className, 'dynamic');
});
test("View: multiple views per element", 3, function() {
test("multiple views per element", 3, function() {
var count = 0, ViewClass = Backbone.View.extend({
el: $("body"),
events: {
@@ -188,7 +188,7 @@ $(document).ready(function() {
equal(5, count);
});
test("View: custom events, with namespaces", 2, function() {
test("custom events, with namespaces", 2, function() {
var count = 0;
var ViewClass = Backbone.View.extend({
el: $('body'),

View File

@@ -2,7 +2,7 @@ $(document).ready(function() {
module("Arrays");
test("arrays: first", function() {
test("first", function() {
equal(_.first([1,2,3]), 1, 'can pull out the first element of an array');
equal(_([1, 2, 3]).first(), 1, 'can perform OO-style "first()"');
equal(_.first([1,2,3], 0).join(', '), "", 'can pass an index to first');
@@ -16,7 +16,7 @@ $(document).ready(function() {
equal(result.join(','), '1,2', 'aliased as take');
});
test("arrays: rest", function() {
test("rest", function() {
var numbers = [1, 2, 3, 4];
equal(_.rest(numbers).join(", "), "2, 3, 4", 'working rest()');
equal(_.rest(numbers, 0).join(", "), "1, 2, 3, 4", 'working rest(0)');
@@ -29,7 +29,7 @@ $(document).ready(function() {
equal(result.join(', '), '2, 3, 4', 'aliased as drop and works on arguments object');
});
test("arrays: initial", function() {
test("initial", function() {
equal(_.initial([1,2,3,4,5]).join(", "), "1, 2, 3, 4", 'working initial()');
equal(_.initial([1,2,3,4],2).join(", "), "1, 2", 'initial can take an index');
var result = (function(){ return _(arguments).initial(); })(1, 2, 3, 4);
@@ -38,7 +38,7 @@ $(document).ready(function() {
equal(_.flatten(result).join(','), '1,2,1,2', 'initial works with _.map');
});
test("arrays: last", function() {
test("last", function() {
equal(_.last([1,2,3]), 3, 'can pull out the last element of an array');
equal(_.last([1,2,3], 0).join(', '), "", 'can pass an index to last');
equal(_.last([1,2,3], 2).join(', '), '2, 3', 'can pass an index to last');
@@ -49,13 +49,13 @@ $(document).ready(function() {
equal(result.join(','), '3,3', 'works well with _.map');
});
test("arrays: compact", function() {
test("compact", function() {
equal(_.compact([0, 1, false, 2, false, 3]).length, 3, 'can trim out all falsy values');
var result = (function(){ return _(arguments).compact().length; })(0, 1, false, 2, false, 3);
equal(result, 3, 'works on an arguments object');
});
test("arrays: flatten", function() {
test("flatten", function() {
if (window.JSON) {
var list = [1, [2], [3, [[[4]]]]];
equal(JSON.stringify(_.flatten(list)), '[1,2,3,4]', 'can flatten nested arrays');
@@ -65,7 +65,7 @@ $(document).ready(function() {
}
});
test("arrays: without", function() {
test("without", function() {
var list = [1, 2, 1, 0, 3, 1, 4];
equal(_.without(list, 0, 1).join(', '), '2, 3, 4', 'can remove all instances of an object');
var result = (function(){ return _.without(arguments, 0, 1); })(1, 2, 1, 0, 3, 1, 4);
@@ -76,7 +76,7 @@ $(document).ready(function() {
ok(_.without(list, list[0]).length == 1, 'ditto.');
});
test("arrays: uniq", function() {
test("uniq", function() {
var list = [1, 2, 1, 3, 1, 4];
equal(_.uniq(list).join(', '), '1, 2, 3, 4', 'can find the unique values of an unsorted array');
@@ -95,7 +95,7 @@ $(document).ready(function() {
equal(result.join(', '), '1, 2, 3, 4', 'works on an arguments object');
});
test("arrays: intersection", function() {
test("intersection", function() {
var stooges = ['moe', 'curly', 'larry'], leaders = ['moe', 'groucho'];
equal(_.intersection(stooges, leaders).join(''), 'moe', 'can take the set intersection of two arrays');
equal(_(stooges).intersection(leaders).join(''), 'moe', 'can perform an OO-style intersection');
@@ -103,7 +103,7 @@ $(document).ready(function() {
equal(result.join(''), 'moe', 'works on an arguments object');
});
test("arrays: union", function() {
test("union", function() {
var result = _.union([1, 2, 3], [2, 30, 1], [1, 40]);
equal(result.join(' '), '1 2 3 30 40', 'takes the union of a list of arrays');
@@ -111,7 +111,7 @@ $(document).ready(function() {
equal(result.join(' '), '1 2 3 30 40 1', 'takes the union of a list of nested arrays');
});
test("arrays: difference", function() {
test("difference", function() {
var result = _.difference([1, 2, 3], [2, 30, 40]);
equal(result.join(' '), '1 3', 'takes the difference of two arrays');
@@ -119,13 +119,13 @@ $(document).ready(function() {
equal(result.join(' '), '3 4', 'takes the difference of three arrays');
});
test('arrays: zip', function() {
test('zip', function() {
var names = ['moe', 'larry', 'curly'], ages = [30, 40, 50], leaders = [true];
var stooges = _.zip(names, ages, leaders);
equal(String(stooges), 'moe,30,true,larry,40,,curly,50,', 'zipped together arrays of different lengths');
});
test('arrays: object', function() {
test('object', function() {
var result = _.object(['moe', 'larry', 'curly'], [30, 40, 50]);
var shouldBe = {moe: 30, larry: 40, curly: 50};
ok(_.isEqual(result, shouldBe), 'two arrays zipped together into an object');
@@ -138,7 +138,7 @@ $(document).ready(function() {
ok(_.isEqual(_.object(_.pairs(stooges)), stooges), 'an object converted to pairs and back to an object');
});
test("arrays: indexOf", function() {
test("indexOf", function() {
var numbers = [1, 2, 3];
numbers.indexOf = null;
equal(_.indexOf(numbers, 2), 1, 'can compute indexOf, even without the native function');
@@ -159,7 +159,7 @@ $(document).ready(function() {
equal(index, 1, '40 is in the list');
});
test("arrays: lastIndexOf", function() {
test("lastIndexOf", function() {
var numbers = [1, 0, 1, 0, 0, 1, 0, 0, 0];
numbers.lastIndexOf = null;
equal(_.lastIndexOf(numbers, 1), 5, 'can compute lastIndexOf, even without the native function');
@@ -169,7 +169,7 @@ $(document).ready(function() {
equal(_.indexOf(null, 2), -1, 'handles nulls properly');
});
test("arrays: range", function() {
test("range", function() {
equal(_.range(0).join(''), '', 'range with 0 as a first argument generates an empty array');
equal(_.range(4).join(' '), '0 1 2 3', 'range with a single positive argument generates an array of elements 0,1,2,...,n-1');
equal(_.range(5, 8).join(' '), '5 6 7', 'range with two arguments a &amp; b, a&lt;b generates an array of elements a,a+1,a+2,...,b-2,b-1');

View File

@@ -2,7 +2,7 @@ $(document).ready(function() {
module("Chaining");
test("chaining: map/flatten/reduce", function() {
test("map/flatten/reduce", function() {
var lyrics = [
"I'm a lumberjack and I'm okay",
"I sleep all night and I work all day",
@@ -20,7 +20,7 @@ $(document).ready(function() {
ok(counts['a'] == 16 && counts['e'] == 10, 'counted all the letters in the song');
});
test("chaining: select/reject/sortBy", function() {
test("select/reject/sortBy", function() {
var numbers = [1,2,3,4,5,6,7,8,9,10];
numbers = _(numbers).chain().select(function(n) {
return n % 2 == 0;
@@ -32,7 +32,7 @@ $(document).ready(function() {
equal(numbers.join(', '), "10, 6, 2", "filtered and reversed the numbers");
});
test("chaining: select/reject/sortBy in functional style", function() {
test("select/reject/sortBy in functional style", function() {
var numbers = [1,2,3,4,5,6,7,8,9,10];
numbers = _.chain(numbers).select(function(n) {
return n % 2 == 0;
@@ -44,7 +44,7 @@ $(document).ready(function() {
equal(numbers.join(', '), "10, 6, 2", "filtered and reversed the numbers");
});
test("chaining: reverse/concat/unshift/pop/map", function() {
test("reverse/concat/unshift/pop/map", function() {
var numbers = [1,2,3,4,5];
numbers = _(numbers).chain()
.reverse()

View File

@@ -2,7 +2,7 @@ $(document).ready(function() {
module("Collections");
test("collections: each", function() {
test("each", function() {
_.each([1, 2, 3], function(num, i) {
equal(num, i + 1, 'each iterators provide value and iteration count');
});
@@ -31,7 +31,7 @@ $(document).ready(function() {
equal(answers, 0, 'handles a null properly');
});
test('collections: map', function() {
test('map', function() {
var doubled = _.map([1, 2, 3], function(num){ return num * 2; });
equal(doubled.join(', '), '2, 4, 6', 'doubled numbers');
@@ -54,7 +54,7 @@ $(document).ready(function() {
ok(_.isArray(ifnull) && ifnull.length === 0, 'handles a null properly');
});
test('collections: reduce', function() {
test('reduce', function() {
var sum = _.reduce([1, 2, 3], function(sum, num){ return sum + num; }, 0);
equal(sum, 6, 'can sum up an array');
@@ -84,7 +84,7 @@ $(document).ready(function() {
raises(function() { _.reduce([], function(){}); }, TypeError, 'throws an error for empty arrays with no initial value');
});
test('collections: reduceRight', function() {
test('reduceRight', function() {
var list = _.reduceRight(["foo", "bar", "baz"], function(memo, str){ return memo + str; }, '');
equal(list, 'bazbarfoo', 'can perform right folds');
@@ -108,18 +108,18 @@ $(document).ready(function() {
raises(function() { _.reduceRight([], function(){}); }, TypeError, 'throws an error for empty arrays with no initial value');
});
test('collections: find', function() {
test('find', function() {
var array = [1, 2, 3, 4];
strictEqual(_.find(array, function(n) { return n > 2; }), 3, 'should return first found `value`');
strictEqual(_.find(array, function() { return false; }), void 0, 'should return `undefined` if `value` is not found');
});
test('collections: detect', function() {
test('detect', function() {
var result = _.detect([1, 2, 3], function(num){ return num * 2 == 4; });
equal(result, 2, 'found the first "2" and broke the loop');
});
test('collections: select', function() {
test('select', function() {
var evens = _.select([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; });
equal(evens.join(', '), '2, 4, 6', 'selected each even number');
@@ -127,12 +127,12 @@ $(document).ready(function() {
equal(evens.join(', '), '2, 4, 6', 'aliased as "filter"');
});
test('collections: reject', function() {
test('reject', function() {
var odds = _.reject([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; });
equal(odds.join(', '), '1, 3, 5', 'rejected each even number');
});
test('collections: all', function() {
test('all', function() {
ok(_.all([], _.identity), 'the empty set');
ok(_.all([true, true, true], _.identity), 'all true values');
ok(!_.all([true, false, true], _.identity), 'one false value');
@@ -144,7 +144,7 @@ $(document).ready(function() {
ok(!_.all([undefined, undefined, undefined], _.identity), 'works with arrays of undefined');
});
test('collections: any', function() {
test('any', function() {
var nativeSome = Array.prototype.some;
Array.prototype.some = null;
ok(!_.any([]), 'the empty set');
@@ -160,21 +160,21 @@ $(document).ready(function() {
Array.prototype.some = nativeSome;
});
test('collections: include', function() {
test('include', function() {
ok(_.include([1,2,3], 2), 'two is in the array');
ok(!_.include([1,3,9], 2), 'two is not in the array');
ok(_.contains({moe:1, larry:3, curly:9}, 3) === true, '_.include on objects checks their values');
ok(_([1,2,3]).include(2), 'OO-style include');
});
test('collections: invoke', function() {
test('invoke', function() {
var list = [[5, 1, 7], [3, 2, 1]];
var result = _.invoke(list, 'sort');
equal(result[0].join(', '), '1, 5, 7', 'first array sorted');
equal(result[1].join(', '), '1, 2, 3', 'second array sorted');
});
test('collections: invoke w/ function reference', function() {
test('invoke w/ function reference', function() {
var list = [[5, 1, 7], [3, 2, 1]];
var result = _.invoke(list, Array.prototype.sort);
equal(result[0].join(', '), '1, 5, 7', 'first array sorted');
@@ -182,7 +182,7 @@ $(document).ready(function() {
});
// Relevant when using ClojureScript
test('collections: invoke when strings have a call method', function() {
test('invoke when strings have a call method', function() {
String.prototype.call = function() {
return 42;
};
@@ -196,12 +196,12 @@ $(document).ready(function() {
equal(s.call, undefined, "call function removed");
});
test('collections: pluck', function() {
test('pluck', function() {
var people = [{name : 'moe', age : 30}, {name : 'curly', age : 50}];
equal(_.pluck(people, 'name').join(', '), 'moe, curly', 'pulls names out of objects');
});
test('collections: max', function() {
test('max', function() {
equal(3, _.max([1, 2, 3]), 'can perform a regular Math.max');
var neg = _.max([1, 2, 3], function(num){ return -num; });
@@ -213,7 +213,7 @@ $(document).ready(function() {
equal(299999, _.max(_.range(1,300000)), "Maximum value of a too-big array");
});
test('collections: min', function() {
test('min', function() {
equal(1, _.min([1, 2, 3]), 'can perform a regular Math.min');
var neg = _.min([1, 2, 3], function(num){ return -num; });
@@ -229,7 +229,7 @@ $(document).ready(function() {
equal(1, _.min(_.range(1,300000)), "Minimum value of a too-big array");
});
test('collections: sortBy', function() {
test('sortBy', function() {
var people = [{name : 'curly', age : 50}, {name : 'moe', age : 30}];
people = _.sortBy(people, function(person){ return person.age; });
equal(_.pluck(people, 'name').join(', '), 'moe, curly', 'stooges sorted by age');
@@ -242,7 +242,7 @@ $(document).ready(function() {
equal(sorted.join(' '), 'one two four five three', 'sorted by length');
});
test('collections: groupBy', function() {
test('groupBy', function() {
var parity = _.groupBy([1, 2, 3, 4, 5, 6], function(num){ return num % 2; });
ok('0' in parity && '1' in parity, 'created a group for each value');
equal(parity[0].join(', '), '2, 4, 6', 'put each even number in the right group');
@@ -254,7 +254,7 @@ $(document).ready(function() {
equal(grouped['5'].join(' '), 'three seven eight');
});
test('collections: countBy', function() {
test('countBy', function() {
var parity = _.countBy([1, 2, 3, 4, 5], function(num){ return num % 2 == 0; });
equal(parity['true'], 2);
equal(parity['false'], 3);
@@ -266,7 +266,7 @@ $(document).ready(function() {
equal(grouped['5'], 3);
});
test('collections: sortedIndex', function() {
test('sortedIndex', function() {
var numbers = [10, 20, 30, 40, 50], num = 35;
var indexForNum = _.sortedIndex(numbers, num);
equal(indexForNum, 3, '35 should be inserted at index 3');
@@ -275,14 +275,14 @@ $(document).ready(function() {
equal(indexFor30, 2, '30 should be inserted at index 2');
});
test('collections: shuffle', function() {
test('shuffle', function() {
var numbers = _.range(10);
var shuffled = _.shuffle(numbers).sort();
notStrictEqual(numbers, shuffled, 'original object is unmodified');
equal(shuffled.join(','), numbers.join(','), 'contains the same members before and after shuffle');
});
test('collections: toArray', function() {
test('toArray', function() {
ok(!_.isArray(arguments), 'arguments object is not an array');
ok(_.isArray(_.toArray(arguments)), 'arguments object converted into array');
var a = [1,2,3];
@@ -301,7 +301,7 @@ $(document).ready(function() {
equal(_.toArray(objectWithToArrayValue).join(', '), '1', 'toArray property ignored if not a function');
});
test('collections: size', function() {
test('size', function() {
equal(_.size({one : 1, two : 2, three : 3}), 3, 'can compute the size of an object');
equal(_.size([1, 2, 3]), 3, 'can compute the size of an array');

View File

@@ -2,7 +2,7 @@ $(document).ready(function() {
module("Functions");
test("functions: bind", function() {
test("bind", function() {
var context = {name : 'moe'};
var func = function(arg) { return "name: " + (this.name || arg); };
var bound = _.bind(func, context);
@@ -38,7 +38,7 @@ $(document).ready(function() {
equal(Boundf().hello, "moe curly", "When called without the new operator, it's OK to be bound to the context");
});
test("functions: bindAll", function() {
test("bindAll", function() {
var curly = {name : 'curly'}, moe = {
name : 'moe',
getName : function() { return 'name: ' + this.name; },
@@ -61,7 +61,7 @@ $(document).ready(function() {
equal(curly.sayHi(), 'hi: moe', 'calling bindAll with no arguments binds all functions to the object');
});
test("functions: memoize", function() {
test("memoize", function() {
var fib = function(n) {
return n < 2 ? n : fib(n - 1) + fib(n - 2);
};
@@ -77,20 +77,20 @@ $(document).ready(function() {
equal(fastO('toString'), 'toString', 'checks hasOwnProperty');
});
asyncTest("functions: delay", 2, function() {
asyncTest("delay", 2, function() {
var delayed = false;
_.delay(function(){ delayed = true; }, 100);
setTimeout(function(){ ok(!delayed, "didn't delay the function quite yet"); }, 50);
setTimeout(function(){ ok(delayed, 'delayed the function'); start(); }, 150);
});
asyncTest("functions: defer", 1, function() {
asyncTest("defer", 1, function() {
var deferred = false;
_.defer(function(bool){ deferred = bool; }, true);
_.delay(function(){ ok(deferred, "deferred the function"); start(); }, 50);
});
asyncTest("functions: throttle", 2, function() {
asyncTest("throttle", 2, function() {
var counter = 0;
var incr = function(){ counter++; };
var throttledIncr = _.throttle(incr, 100);
@@ -105,7 +105,7 @@ $(document).ready(function() {
_.delay(function(){ equal(counter, 4, "incr was throttled"); start(); }, 400);
});
asyncTest("functions: throttle arguments", 2, function() {
asyncTest("throttle arguments", 2, function() {
var value = 0;
var update = function(val){ value = val; };
var throttledUpdate = _.throttle(update, 100);
@@ -117,7 +117,7 @@ $(document).ready(function() {
_.delay(function(){ equal(value, 6, "updated to latest value"); start(); }, 400);
});
asyncTest("functions: throttle once", 2, function() {
asyncTest("throttle once", 2, function() {
var counter = 0;
var incr = function(){ return ++counter; };
var throttledIncr = _.throttle(incr, 100);
@@ -128,7 +128,7 @@ $(document).ready(function() {
}, 220);
});
asyncTest("functions: throttle twice", 1, function() {
asyncTest("throttle twice", 1, function() {
var counter = 0;
var incr = function(){ counter++; };
var throttledIncr = _.throttle(incr, 100);
@@ -136,7 +136,34 @@ $(document).ready(function() {
_.delay(function(){ equal(counter, 2, "incr was called twice"); start(); }, 220);
});
asyncTest("functions: debounce", 1, function() {
asyncTest("throttle repeatedly with results", 9, function() {
var counter = 0;
var incr = function(){ return ++counter; };
var throttledIncr = _.throttle(incr, 100);
var results = [];
var saveResult = function() { results.push(throttledIncr()); }
saveResult(); saveResult(); saveResult();
setTimeout(saveResult, 70);
setTimeout(saveResult, 120);
setTimeout(saveResult, 140);
setTimeout(saveResult, 190);
setTimeout(saveResult, 240);
setTimeout(saveResult, 260);
_.delay(function() {
equal(results[0], 1, "incr was called once");
equal(results[1], 1, "incr was throttled");
equal(results[2], 1, "incr was throttled");
equal(results[3], 1, "incr was throttled");
equal(results[4], 2, "incr was called twice");
equal(results[5], 2, "incr was throttled");
equal(results[6], 2, "incr was throttled");
equal(results[7], 3, "incr was called thrice");
equal(results[8], 3, "incr was throttled");
start();
}, 400);
});
asyncTest("debounce", 1, function() {
var counter = 0;
var incr = function(){ counter++; };
var debouncedIncr = _.debounce(incr, 50);
@@ -149,7 +176,7 @@ $(document).ready(function() {
_.delay(function(){ equal(counter, 1, "incr was debounced"); start(); }, 220);
});
asyncTest("functions: debounce asap", 2, function() {
asyncTest("debounce asap", 2, function() {
var counter = 0;
var incr = function(){ counter++; };
var debouncedIncr = _.debounce(incr, 50, true);
@@ -163,7 +190,7 @@ $(document).ready(function() {
_.delay(function(){ equal(counter, 1, "incr was debounced"); start(); }, 220);
});
asyncTest("functions: debounce asap recursively", 2, function() {
asyncTest("debounce asap recursively", 2, function() {
var counter = 0;
var debouncedIncr = _.debounce(function(){
counter++;
@@ -174,7 +201,7 @@ $(document).ready(function() {
_.delay(function(){ equal(counter, 1, "incr was debounced"); start(); }, 70);
});
test("functions: once", function() {
test("once", function() {
var num = 0;
var increment = _.once(function(){ num++; });
increment();
@@ -182,7 +209,7 @@ $(document).ready(function() {
equal(num, 1);
});
test("functions: wrap", function() {
test("wrap", function() {
var greet = function(name){ return "hi: " + name; };
var backwards = _.wrap(greet, function(func, name){ return func(name) + ' ' + name.split('').reverse().join(''); });
equal(backwards('moe'), 'hi: moe eom', 'wrapped the saluation function');
@@ -198,7 +225,7 @@ $(document).ready(function() {
deepEqual(ret, [noop, ['whats', 'your'], 'vector', 'victor']);
});
test("functions: compose", function() {
test("compose", function() {
var greet = function(name){ return "hi: " + name; };
var exclaim = function(sentence){ return sentence + '!'; };
var composed = _.compose(exclaim, greet);
@@ -208,7 +235,7 @@ $(document).ready(function() {
equal(composed('moe'), 'hi: moe!', 'in this case, the functions are also commutative');
});
test("functions: after", function() {
test("after", function() {
var testAfter = function(afterAmount, timesCalled) {
var afterCalled = 0;
var after = _.after(afterAmount, function() {

View File

@@ -2,7 +2,7 @@ $(document).ready(function() {
module("Objects");
test("objects: keys", function() {
test("keys", function() {
equal(_.keys({one : 1, two : 2}).join(', '), 'one, two', 'can extract the keys from an object');
// the test above is not safe because it relies on for-in enumeration order
var a = []; a[1] = 0;
@@ -14,21 +14,21 @@ $(document).ready(function() {
raises(function() { _.keys(true); }, TypeError, 'throws an error for boolean primitives');
});
test("objects: values", function() {
test("values", function() {
equal(_.values({one : 1, two : 2}).join(', '), '1, 2', 'can extract the values from an object');
});
test("objects: pairs", function() {
test("pairs", function() {
deepEqual(_.pairs({one: 1, two: 2}), [['one', 1], ['two', 2]], 'can convert an object into pairs');
});
test("objects: invert", function() {
test("invert", function() {
var obj = {first: 'Moe', second: 'Larry', third: 'Curly'};
equal(_.keys(_.invert(obj)).join(' '), 'Moe Larry Curly', 'can invert an object');
ok(_.isEqual(_.invert(_.invert(obj)), obj), 'two inverts gets you back where you started');
});
test("objects: functions", function() {
test("functions", function() {
var obj = {a : 'dash', b : _.map, c : (/yo/), d : _.reduce};
ok(_.isEqual(['b', 'd'], _.functions(obj)), 'can grab the function names of any passed-in object');
@@ -37,7 +37,7 @@ $(document).ready(function() {
equal(_.functions(new Animal).join(''), 'run', 'also looks up functions on the prototype');
});
test("objects: extend", function() {
test("extend", function() {
var result;
equal(_.extend({}, {a:'b'}).a, 'b', 'can extend an object with the attributes of another');
equal(_.extend({a:'x'}, {a:'b'}).a, 'b', 'properties in source override destination');
@@ -50,7 +50,7 @@ $(document).ready(function() {
equal(_.keys(result).join(''), 'ab', 'extend does not copy undefined values');
});
test("objects: pick", function() {
test("pick", function() {
var result;
result = _.pick({a:1, b:2, c:3}, 'a', 'c');
ok(_.isEqual(result, {a:1, c:3}), 'can restrict properties to those named');
@@ -64,7 +64,7 @@ $(document).ready(function() {
ok(_.isEqual(_.pick(new Obj, 'a', 'c'), {a:1, c: 3}), 'include prototype props');
});
test("objects: omit", function() {
test("omit", function() {
var result;
result = _.omit({a:1, b:2, c:3}, 'b');
ok(_.isEqual(result, {a:1, c:3}), 'can omit a single named property');
@@ -78,7 +78,7 @@ $(document).ready(function() {
ok(_.isEqual(_.omit(new Obj, 'b'), {a:1, c: 3}), 'include prototype props');
});
test("objects: defaults", function() {
test("defaults", function() {
var result;
var options = {zero: 0, one: 1, empty: "", nan: NaN, string: "string"};
@@ -93,7 +93,7 @@ $(document).ready(function() {
equal(options.word, "word", 'new value is added, first one wins');
});
test("objects: clone", function() {
test("clone", function() {
var moe = {name : 'moe', lucky : [13, 27, 34]};
var clone = _.clone(moe);
equal(clone.name, 'moe', 'the clone as the attributes of the original');
@@ -109,7 +109,7 @@ $(document).ready(function() {
equal(_.clone(null), null, 'non objects should not be changed by clone');
});
test("objects: isEqual", function() {
test("isEqual", function() {
function First() {
this.value = 1;
}
@@ -392,7 +392,7 @@ $(document).ready(function() {
ok(_.isEqual(date, date_json), 'date matches serialized date');
});
test("objects: isEmpty", function() {
test("isEmpty", function() {
ok(!_([1]).isEmpty(), '[1] is not empty');
ok(_.isEmpty([]), '[] is empty');
ok(!_.isEmpty({one : 1}), '{one : 1} is not empty');
@@ -430,13 +430,13 @@ $(document).ready(function() {
);
iDoc.close();
test("objects: isElement", function() {
test("isElement", function() {
ok(!_.isElement('div'), 'strings are not dom elements');
ok(_.isElement($('html')[0]), 'the html tag is a DOM element');
ok(_.isElement(iElement), 'even from another frame');
});
test("objects: isArguments", function() {
test("isArguments", function() {
var args = (function(){ return arguments; })(1, 2, 3);
ok(!_.isArguments('string'), 'a string is not an arguments object');
ok(!_.isArguments(_.isArguments), 'a function is not an arguments object');
@@ -446,7 +446,7 @@ $(document).ready(function() {
ok(_.isArguments(iArguments), 'even from another frame');
});
test("objects: isObject", function() {
test("isObject", function() {
ok(_.isObject(arguments), 'the arguments object is object');
ok(_.isObject([1, 2, 3]), 'and arrays');
ok(_.isObject($('html')[0]), 'and DOM element');
@@ -461,19 +461,19 @@ $(document).ready(function() {
ok(_.isObject(new String('string')), 'but new String()');
});
test("objects: isArray", function() {
test("isArray", function() {
ok(!_.isArray(arguments), 'the arguments object is not an array');
ok(_.isArray([1, 2, 3]), 'but arrays are');
ok(_.isArray(iArray), 'even from another frame');
});
test("objects: isString", function() {
test("isString", function() {
ok(!_.isString(document.body), 'the document body is not a string');
ok(_.isString([1, 2, 3].join(', ')), 'but strings are');
ok(_.isString(iString), 'even from another frame');
});
test("objects: isNumber", function() {
test("isNumber", function() {
ok(!_.isNumber('string'), 'a string is not a number');
ok(!_.isNumber(arguments), 'the arguments object is not a number');
ok(!_.isNumber(undefined), 'undefined is not a number');
@@ -484,7 +484,7 @@ $(document).ready(function() {
ok(!_.isNumber('1'), 'numeric strings are not numbers');
});
test("objects: isBoolean", function() {
test("isBoolean", function() {
ok(!_.isBoolean(2), 'a number is not a boolean');
ok(!_.isBoolean("string"), 'a string is not a boolean');
ok(!_.isBoolean("false"), 'the string "false" is not a boolean');
@@ -498,27 +498,27 @@ $(document).ready(function() {
ok(_.isBoolean(iBoolean), 'even from another frame');
});
test("objects: isFunction", function() {
test("isFunction", function() {
ok(!_.isFunction([1, 2, 3]), 'arrays are not functions');
ok(!_.isFunction('moe'), 'strings are not functions');
ok(_.isFunction(_.isFunction), 'but functions are');
ok(_.isFunction(iFunction), 'even from another frame');
});
test("objects: isDate", function() {
test("isDate", function() {
ok(!_.isDate(100), 'numbers are not dates');
ok(!_.isDate({}), 'objects are not dates');
ok(_.isDate(new Date()), 'but dates are');
ok(_.isDate(iDate), 'even from another frame');
});
test("objects: isRegExp", function() {
test("isRegExp", function() {
ok(!_.isRegExp(_.identity), 'functions are not RegExps');
ok(_.isRegExp(/identity/), 'but RegExps are');
ok(_.isRegExp(iRegExp), 'even from another frame');
});
test("objects: isFinite", function() {
test("isFinite", function() {
ok(!_.isFinite(undefined), 'undefined is not Finite');
ok(!_.isFinite(null), 'null is not Finite');
ok(!_.isFinite(NaN), 'NaN is not Finite');
@@ -532,7 +532,7 @@ $(document).ready(function() {
ok(_.isFinite(-12.44), 'Floats are Finite');
});
test("objects: isNaN", function() {
test("isNaN", function() {
ok(!_.isNaN(undefined), 'undefined is not NaN');
ok(!_.isNaN(null), 'null is not NaN');
ok(!_.isNaN(0), '0 is not NaN');
@@ -540,14 +540,14 @@ $(document).ready(function() {
ok(_.isNaN(iNaN), 'even from another frame');
});
test("objects: isNull", function() {
test("isNull", function() {
ok(!_.isNull(undefined), 'undefined is not null');
ok(!_.isNull(NaN), 'NaN is not null');
ok(_.isNull(null), 'but null is');
ok(_.isNull(iNull), 'even from another frame');
});
test("objects: isUndefined", function() {
test("isUndefined", function() {
ok(!_.isUndefined(1), 'numbers are defined');
ok(!_.isUndefined(null), 'null is defined');
ok(!_.isUndefined(false), 'false is defined');
@@ -558,7 +558,7 @@ $(document).ready(function() {
});
if (window.ActiveXObject) {
test("objects: IE host objects", function() {
test("IE host objects", function() {
var xml = new ActiveXObject("Msxml2.DOMDocument.3.0");
ok(!_.isNumber(xml));
ok(!_.isBoolean(xml));
@@ -569,7 +569,7 @@ $(document).ready(function() {
});
}
test("objects: tap", function() {
test("tap", function() {
var intercepted = null;
var interceptor = function(obj) { intercepted = obj; };
var returned = _.tap(1, interceptor);

View File

@@ -20,18 +20,18 @@ $(document).ready(function() {
ok(new _(instance) === instance);
});
test("utility: identity", function() {
test("identity", function() {
var moe = {name : 'moe'};
equal(_.identity(moe), moe, 'moe is the same as his identity');
});
test("utility: uniqueId", function() {
test("uniqueId", function() {
var ids = [], i = 0;
while(i++ < 100) ids.push(_.uniqueId());
equal(_.uniq(ids).length, ids.length, 'can generate a globally-unique stream of ids');
});
test("utility: times", function() {
test("times", function() {
var vals = [];
_.times(3, function (i) { vals.push(i); });
ok(_.isEqual(vals, [0,1,2]), "is 0 indexed");
@@ -41,7 +41,7 @@ $(document).ready(function() {
ok(_.isEqual(vals, [0,1,2]), "works as a wrapper");
});
test("utility: mixin", function() {
test("mixin", function() {
_.mixin({
myReverse: function(string) {
return string.split('').reverse().join('');
@@ -51,13 +51,13 @@ $(document).ready(function() {
equal(_('champ').myReverse(), 'pmahc', 'mixed in a function to the OOP wrapper');
});
test("utility: _.escape", function() {
test("_.escape", function() {
equal(_.escape("Curly & Moe"), "Curly &amp; Moe");
equal(_.escape("Curly &amp; Moe"), "Curly &amp;amp; Moe");
equal(_.escape(null), '');
});
test("utility: _.unescape", function() {
test("_.unescape", function() {
var string = "Curly & Moe";
equal(_.unescape("Curly &amp; Moe"), string);
equal(_.unescape("Curly &amp;amp; Moe"), "Curly &amp; Moe");
@@ -65,7 +65,7 @@ $(document).ready(function() {
equal(_.unescape(_.escape(string)), string);
});
test("utility: template", function() {
test("template", function() {
var basicTemplate = _.template("<%= thing %> is gettin' on my noives!");
var result = basicTemplate({thing : 'This'});
equal(result, "This is gettin' on my noives!", 'can do basic attribute interpolation');
@@ -171,7 +171,7 @@ $(document).ready(function() {
equal(templateWithNull({planet : "world"}), "a null undefined world", "can handle missing escape and evaluate settings");
});
test('utility: _.template provides the generated function source, when a SyntaxError occurs', function() {
test('_.template provides the generated function source, when a SyntaxError occurs', function() {
try {
_.template('<b><%= if %></b>');
} catch (e) {

View File

@@ -18,7 +18,7 @@ a):r(a,c,d):d.push(a)});return d};b.flatten=function(a,b){return r(a,b,[])};b.wi
a)>=0})})};b.difference=function(a){var c=r(h.call(arguments,1),true,[]);return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=h.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e<c;e++)d[e]=b.pluck(a,""+e);return d};b.object=function(a,b){for(var d={},e=0,f=a.length;e<f;e++)b?d[a[e]]=b[e]:d[a[e][0]]=a[e][1];return d};b.indexOf=function(a,c,d){if(a==null)return-1;var e;if(d){d=b.sortedIndex(a,c);return a[d]===c?d:-1}if(q&&a.indexOf===q)return a.indexOf(c);d=
0;for(e=a.length;d<e;d++)if(a[d]===c)return d;return-1};b.lastIndexOf=function(a,b){if(a==null)return-1;if(F&&a.lastIndexOf===F)return a.lastIndexOf(b);for(var d=a.length;d--;)if(a[d]===b)return d;return-1};b.range=function(a,b,d){if(arguments.length<=1){b=a||0;a=0}for(var d=arguments[2]||1,e=Math.max(Math.ceil((b-a)/d),0),f=0,g=Array(e);f<e;){g[f++]=a;a=a+d}return g};var J=function(){};b.bind=function(a,c){var d,e;if(a.bind===t&&t)return t.apply(a,h.call(arguments,1));if(!b.isFunction(a))throw new TypeError;
e=h.call(arguments,2);return d=function(){if(!(this instanceof d))return a.apply(c,e.concat(h.call(arguments)));J.prototype=a.prototype;var b=new J,g=a.apply(b,e.concat(h.call(arguments)));return Object(g)===g?g:b}};b.bindAll=function(a){var c=h.call(arguments,1);c.length==0&&(c=b.functions(a));j(c,function(c){a[c]=b.bind(a[c],a)});return a};b.memoize=function(a,c){var d={};c||(c=b.identity);return function(){var e=c.apply(this,arguments);return b.has(d,e)?d[e]:d[e]=a.apply(this,arguments)}};b.delay=
function(a,b){var d=h.call(arguments,2);return setTimeout(function(){return a.apply(null,d)},b)};b.defer=function(a){return b.delay.apply(b,[a,1].concat(h.call(arguments,1)))};b.throttle=function(a,c){var d,e,f,g,i,h,j=b.debounce(function(){i=g=false},c);return function(){d=this;e=arguments;f||(f=setTimeout(function(){f=null;i&&a.apply(d,e);j()},c));if(g)i=true;else{g=true;h=a.apply(d,e)}j();return h}};b.debounce=function(a,b,d){var e;return function(){var f=this,g=arguments,i=d&&!e;clearTimeout(e);
function(a,b){var d=h.call(arguments,2);return setTimeout(function(){return a.apply(null,d)},b)};b.defer=function(a){return b.delay.apply(b,[a,1].concat(h.call(arguments,1)))};b.throttle=function(a,c){var d,e,f,g,i,h,j=b.debounce(function(){i=g=false},c);return function(){d=this;e=arguments;f||(f=setTimeout(function(){f=null;i&&(h=a.apply(d,e));j()},c));if(g)i=true;else{g=true;h=a.apply(d,e)}j();return h}};b.debounce=function(a,b,d){var e;return function(){var f=this,g=arguments,i=d&&!e;clearTimeout(e);
e=setTimeout(function(){e=null;d||a.apply(f,g)},b);i&&a.apply(f,g)}};b.once=function(a){var b=false,d;return function(){if(b)return d;b=true;d=a.apply(this,arguments);a=null;return d}};b.wrap=function(a,b){return function(){var d=[a].concat(h.call(arguments,0));return b.apply(this,d)}};b.compose=function(){var a=arguments;return function(){for(var b=arguments,d=a.length-1;d>=0;d--)b=[a[d].apply(this,b)];return b[0]}};b.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}};
b.keys=N||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var c=[],d;for(d in a)b.has(a,d)&&(c[c.length]=d);return c};b.values=function(a){return b.map(a,b.identity)};b.pairs=function(a){return b.map(a,function(a,b){return[b,a]})};b.invert=function(a){return b.reduce(a,function(a,b,e){a[b]=e;return a},{})};b.functions=b.methods=function(a){var c=[],d;for(d in a)b.isFunction(a[d])&&c.push(d);return c.sort()};b.extend=function(a){j(h.call(arguments,1),function(b){for(var d in b)a[d]=
b[d]});return a};b.pick=function(a){var c={},d=b.flatten(h.call(arguments,1));j(d,function(b){b in a&&(c[b]=a[b])});return c};b.omit=function(a){var c={},d=b.flatten(h.call(arguments,1)),e;for(e in a)b.include(d,e)||(c[e]=a[e]);return c};b.defaults=function(a){j(h.call(arguments,1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return!b.isObject(a)?a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};var u=function(a,c,d){if(a===c)return a!==

View File

@@ -591,7 +591,9 @@
context = this; args = arguments;
var later = function() {
timeout = null;
if (more) func.apply(context, args);
if (more) {
result = func.apply(context, args);
}
whenDone();
};
if (!timeout) timeout = setTimeout(later, wait);