Update of multiple frontend libs.
This commit is contained in:
parent
de261dbde5
commit
a9c6ddc03b
276 changed files with 41257 additions and 19300 deletions
|
@ -394,6 +394,7 @@
|
|||
var Model = Backbone.Model = function(attributes, options) {
|
||||
var attrs = attributes || {};
|
||||
options || (options = {});
|
||||
this.preinitialize.apply(this, arguments);
|
||||
this.cid = _.uniqueId(this.cidPrefix);
|
||||
this.attributes = {};
|
||||
if (options.collection) this.collection = options.collection;
|
||||
|
@ -422,6 +423,10 @@
|
|||
// You may want to override this if you're experiencing name clashes with model ids.
|
||||
cidPrefix: 'c',
|
||||
|
||||
// preinitialize is an empty function by default. You can override it with a function
|
||||
// or object. preinitialize will run before any instantiation logic is run in the Model.
|
||||
preinitialize: function(){},
|
||||
|
||||
// Initialize is an empty function by default. Override it with your own
|
||||
// initialization logic.
|
||||
initialize: function(){},
|
||||
|
@ -562,12 +567,14 @@
|
|||
if (!diff) return this.hasChanged() ? _.clone(this.changed) : false;
|
||||
var old = this._changing ? this._previousAttributes : this.attributes;
|
||||
var changed = {};
|
||||
var hasChanged;
|
||||
for (var attr in diff) {
|
||||
var val = diff[attr];
|
||||
if (_.isEqual(old[attr], val)) continue;
|
||||
changed[attr] = val;
|
||||
hasChanged = true;
|
||||
}
|
||||
return _.size(changed) ? changed : false;
|
||||
return hasChanged ? changed : false;
|
||||
},
|
||||
|
||||
// Get the previous value of an attribute, recorded at the time the last
|
||||
|
@ -754,6 +761,7 @@
|
|||
// its models in sort order, as they're added and removed.
|
||||
var Collection = Backbone.Collection = function(models, options) {
|
||||
options || (options = {});
|
||||
this.preinitialize.apply(this, arguments);
|
||||
if (options.model) this.model = options.model;
|
||||
if (options.comparator !== void 0) this.comparator = options.comparator;
|
||||
this._reset();
|
||||
|
@ -783,6 +791,11 @@
|
|||
// This should be overridden in most cases.
|
||||
model: Model,
|
||||
|
||||
|
||||
// preinitialize is an empty function by default. You can override it with a function
|
||||
// or object. preinitialize will run before any instantiation logic is run in the Collection.
|
||||
preinitialize: function(){},
|
||||
|
||||
// Initialize is an empty function by default. Override it with your own
|
||||
// initialization logic.
|
||||
initialize: function(){},
|
||||
|
@ -1219,6 +1232,7 @@
|
|||
// if an existing element is not provided...
|
||||
var View = Backbone.View = function(options) {
|
||||
this.cid = _.uniqueId('view');
|
||||
this.preinitialize.apply(this, arguments);
|
||||
_.extend(this, _.pick(options, viewOptions));
|
||||
this._ensureElement();
|
||||
this.initialize.apply(this, arguments);
|
||||
|
@ -1242,6 +1256,10 @@
|
|||
return this.$el.find(selector);
|
||||
},
|
||||
|
||||
// preinitialize is an empty function by default. You can override it with a function
|
||||
// or object. preinitialize will run before any instantiation logic is run in the View
|
||||
preinitialize: function(){},
|
||||
|
||||
// Initialize is an empty function by default. Override it with your own
|
||||
// initialization logic.
|
||||
initialize: function(){},
|
||||
|
@ -1467,6 +1485,7 @@
|
|||
// matched. Creating a new one sets its `routes` hash, if not set statically.
|
||||
var Router = Backbone.Router = function(options) {
|
||||
options || (options = {});
|
||||
this.preinitialize.apply(this, arguments);
|
||||
if (options.routes) this.routes = options.routes;
|
||||
this._bindRoutes();
|
||||
this.initialize.apply(this, arguments);
|
||||
|
@ -1482,6 +1501,10 @@
|
|||
// Set up all inheritable **Backbone.Router** properties and methods.
|
||||
_.extend(Router.prototype, Events, {
|
||||
|
||||
// preinitialize is an empty function by default. You can override it with a function
|
||||
// or object. preinitialize will run before any instantiation logic is run in the Router.
|
||||
preinitialize: function(){},
|
||||
|
||||
// Initialize is an empty function by default. Override it with your own
|
||||
// initialization logic.
|
||||
initialize: function(){},
|
||||
|
@ -1812,11 +1835,14 @@
|
|||
}
|
||||
var url = rootPath + fragment;
|
||||
|
||||
// Strip the hash and decode for matching.
|
||||
fragment = this.decodeFragment(fragment.replace(pathStripper, ''));
|
||||
// Strip the fragment of the query and hash for matching.
|
||||
fragment = fragment.replace(pathStripper, '');
|
||||
|
||||
if (this.fragment === fragment) return;
|
||||
this.fragment = fragment;
|
||||
// Decode for matching.
|
||||
var decodedFragment = this.decodeFragment(fragment);
|
||||
|
||||
if (this.fragment === decodedFragment) return;
|
||||
this.fragment = decodedFragment;
|
||||
|
||||
// If pushState is available, we use it to set the fragment as a real URL.
|
||||
if (this._usePushState) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
(function() {
|
||||
(function(QUnit) {
|
||||
|
||||
var a, b, c, d, e, col, otherCol;
|
||||
|
||||
|
@ -593,7 +593,7 @@
|
|||
assert.equal(error, 'fail');
|
||||
assert.equal(options.validationError, 'fail');
|
||||
});
|
||||
assert.equal(collection.create({'foo': 'bar'}, {validate: true}), false);
|
||||
assert.equal(collection.create({foo: 'bar'}, {validate: true}), false);
|
||||
});
|
||||
|
||||
QUnit.test('create will pass extra options to success callback', function(assert) {
|
||||
|
@ -661,6 +661,31 @@
|
|||
assert.equal(coll.one, 1);
|
||||
});
|
||||
|
||||
QUnit.test('preinitialize', function(assert) {
|
||||
assert.expect(1);
|
||||
var Collection = Backbone.Collection.extend({
|
||||
preinitialize: function() {
|
||||
this.one = 1;
|
||||
}
|
||||
});
|
||||
var coll = new Collection;
|
||||
assert.equal(coll.one, 1);
|
||||
});
|
||||
|
||||
QUnit.test('preinitialize occurs before the collection is set up', function(assert) {
|
||||
assert.expect(2);
|
||||
var Collection = Backbone.Collection.extend({
|
||||
preinitialize: function() {
|
||||
assert.notEqual(this.model, FooModel);
|
||||
}
|
||||
});
|
||||
var FooModel = Backbone.Model.extend({id: 'foo'});
|
||||
var coll = new Collection({}, {
|
||||
model: FooModel
|
||||
});
|
||||
assert.equal(coll.model, FooModel);
|
||||
});
|
||||
|
||||
QUnit.test('toJSON', function(assert) {
|
||||
assert.expect(1);
|
||||
assert.equal(JSON.stringify(col), '[{"id":3,"label":"a"},{"id":2,"label":"b"},{"id":1,"label":"c"},{"id":0,"label":"d"}]');
|
||||
|
@ -1724,10 +1749,10 @@
|
|||
return new M(attrs);
|
||||
}
|
||||
});
|
||||
var c2 = new C2({'_id': 1});
|
||||
var c2 = new C2({_id: 1});
|
||||
assert.equal(c2.get(1), void 0);
|
||||
assert.equal(c2.modelId(c2.at(0).attributes), void 0);
|
||||
var m = new M({'_id': 2});
|
||||
var m = new M({_id: 2});
|
||||
c2.add(m);
|
||||
assert.equal(c2.get(2), void 0);
|
||||
assert.equal(c2.modelId(m.attributes), void 0);
|
||||
|
@ -1995,4 +2020,4 @@
|
|||
assert.equal(fired, false);
|
||||
});
|
||||
|
||||
})();
|
||||
})(QUnit);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
(function() {
|
||||
(function(QUnit) {
|
||||
|
||||
QUnit.module('Backbone.Events');
|
||||
|
||||
|
@ -703,4 +703,4 @@
|
|||
two.trigger('y', 2);
|
||||
});
|
||||
|
||||
})();
|
||||
})(QUnit);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
(function() {
|
||||
(function(QUnit) {
|
||||
|
||||
var ProxyModel = Backbone.Model.extend();
|
||||
var Klass = Backbone.Collection.extend({
|
||||
|
@ -63,6 +63,36 @@
|
|||
assert.equal(model.get('value'), 2);
|
||||
});
|
||||
|
||||
|
||||
QUnit.test('preinitialize', function(assert) {
|
||||
assert.expect(2);
|
||||
var Model = Backbone.Model.extend({
|
||||
|
||||
preinitialize: function() {
|
||||
this.one = 1;
|
||||
}
|
||||
});
|
||||
var model = new Model({}, {collection: collection});
|
||||
assert.equal(model.one, 1);
|
||||
assert.equal(model.collection, collection);
|
||||
});
|
||||
|
||||
QUnit.test('preinitialize occurs before the model is set up', function(assert) {
|
||||
assert.expect(6);
|
||||
var Model = Backbone.Model.extend({
|
||||
|
||||
preinitialize: function() {
|
||||
assert.equal(this.collection, undefined);
|
||||
assert.equal(this.cid, undefined);
|
||||
assert.equal(this.id, undefined);
|
||||
}
|
||||
});
|
||||
var model = new Model({id: 'foo'}, {collection: collection});
|
||||
assert.equal(model.collection, collection);
|
||||
assert.equal(model.id, 'foo');
|
||||
assert.notEqual(model.cid, undefined);
|
||||
});
|
||||
|
||||
QUnit.test('parse can return null', function(assert) {
|
||||
assert.expect(1);
|
||||
var Model = Backbone.Model.extend({
|
||||
|
@ -1415,4 +1445,4 @@
|
|||
assert.equal(model.id, 3);
|
||||
});
|
||||
|
||||
})();
|
||||
})(QUnit);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
(function() {
|
||||
(function(QUnit) {
|
||||
|
||||
QUnit.module('Backbone.noConflict');
|
||||
|
||||
|
@ -10,4 +10,4 @@
|
|||
assert.equal(window.Backbone, noconflictBackbone, 'Backbone is still pointing to the original Backbone');
|
||||
});
|
||||
|
||||
})();
|
||||
})(QUnit);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
(function() {
|
||||
(function(QUnit) {
|
||||
|
||||
var router = null;
|
||||
var location = null;
|
||||
|
@ -28,7 +28,8 @@
|
|||
'fragment',
|
||||
'pathname',
|
||||
'protocol'
|
||||
));
|
||||
));
|
||||
|
||||
// In IE, anchor.pathname does not contain a leading slash though
|
||||
// window.location.pathname does.
|
||||
if (!/^\//.test(this.pathname)) this.pathname = '/' + this.pathname;
|
||||
|
@ -42,7 +43,7 @@
|
|||
|
||||
QUnit.module('Backbone.Router', {
|
||||
|
||||
setup: function() {
|
||||
beforeEach: function() {
|
||||
location = new Location('http://example.com');
|
||||
Backbone.history = _.extend(new Backbone.History, {location: location});
|
||||
router = new Router({testing: 101});
|
||||
|
@ -53,7 +54,7 @@
|
|||
Backbone.history.on('route', onRoute);
|
||||
},
|
||||
|
||||
teardown: function() {
|
||||
afterEach: function() {
|
||||
Backbone.history.stop();
|
||||
Backbone.history.off('route', onRoute);
|
||||
}
|
||||
|
@ -95,6 +96,10 @@
|
|||
'*anything': 'anything'
|
||||
},
|
||||
|
||||
preinitialize: function(options) {
|
||||
this.testpreinit = 'foo';
|
||||
},
|
||||
|
||||
initialize: function(options) {
|
||||
this.testing = options.testing;
|
||||
this.route('implicit', 'implicit');
|
||||
|
@ -121,19 +126,19 @@
|
|||
this.charType = 'escaped';
|
||||
},
|
||||
|
||||
contacts: function(){
|
||||
contacts: function() {
|
||||
this.contact = 'index';
|
||||
},
|
||||
|
||||
newContact: function(){
|
||||
newContact: function() {
|
||||
this.contact = 'new';
|
||||
},
|
||||
|
||||
loadContact: function(){
|
||||
loadContact: function() {
|
||||
this.contact = 'load';
|
||||
},
|
||||
|
||||
optionalItem: function(arg){
|
||||
optionalItem: function(arg) {
|
||||
this.arg = arg !== void 0 ? arg : null;
|
||||
},
|
||||
|
||||
|
@ -181,6 +186,11 @@
|
|||
assert.equal(router.testing, 101);
|
||||
});
|
||||
|
||||
QUnit.test('preinitialize', function(assert) {
|
||||
assert.expect(1);
|
||||
assert.equal(router.testpreinit, 'foo');
|
||||
});
|
||||
|
||||
QUnit.test('routes (simple)', function(assert) {
|
||||
assert.expect(4);
|
||||
location.replace('http://example.com#search/news');
|
||||
|
@ -234,10 +244,11 @@
|
|||
assert.ok(Backbone.history.navigate('search/manhattan/p20', true));
|
||||
});
|
||||
|
||||
QUnit.test('route precedence via navigate', function(assert){
|
||||
QUnit.test('route precedence via navigate', function(assert) {
|
||||
assert.expect(6);
|
||||
// check both 0.9.x and backwards-compatibility options
|
||||
_.each([{trigger: true}, true], function( options ){
|
||||
|
||||
// Check both 0.9.x and backwards-compatibility options
|
||||
_.each([{trigger: true}, true], function(options) {
|
||||
Backbone.history.navigate('contacts', options);
|
||||
assert.equal(router.contact, 'index');
|
||||
Backbone.history.navigate('contacts/new', options);
|
||||
|
@ -249,7 +260,7 @@
|
|||
|
||||
QUnit.test('loadUrl is not called for identical routes.', function(assert) {
|
||||
assert.expect(0);
|
||||
Backbone.history.loadUrl = function(){ assert.ok(false); };
|
||||
Backbone.history.loadUrl = function() { assert.ok(false); };
|
||||
location.replace('http://example.com#route');
|
||||
Backbone.history.navigate('route');
|
||||
Backbone.history.navigate('/route');
|
||||
|
@ -345,9 +356,9 @@
|
|||
assert.strictEqual(router.path, 'c/d/e');
|
||||
});
|
||||
|
||||
QUnit.test("fires event when router doesn't have callback on it", function(assert) {
|
||||
QUnit.test('fires event when router doesn\'t have callback on it', function(assert) {
|
||||
assert.expect(1);
|
||||
router.on('route:noCallback', function(){ assert.ok(true); });
|
||||
router.on('route:noCallback', function() { assert.ok(true); });
|
||||
location.replace('http://example.com#noCallback');
|
||||
Backbone.history.checkUrl();
|
||||
});
|
||||
|
@ -536,8 +547,8 @@
|
|||
Backbone.history = _.extend(new Backbone.History, {
|
||||
location: location,
|
||||
history: {
|
||||
pushState: function(){},
|
||||
replaceState: function(){}
|
||||
pushState: function() {},
|
||||
replaceState: function() {}
|
||||
}
|
||||
});
|
||||
Backbone.history.start({root: 'root'});
|
||||
|
@ -551,8 +562,8 @@
|
|||
Backbone.history = _.extend(new Backbone.History, {
|
||||
location: location,
|
||||
history: {
|
||||
pushState: function(){},
|
||||
replaceState: function(state, title, url){
|
||||
pushState: function() {},
|
||||
replaceState: function(state, title, url) {
|
||||
assert.strictEqual(url, '/root/x/y');
|
||||
}
|
||||
}
|
||||
|
@ -570,8 +581,8 @@
|
|||
Backbone.history = _.extend(new Backbone.History, {
|
||||
location: location,
|
||||
history: {
|
||||
pushState: function(){},
|
||||
replaceState: function(){}
|
||||
pushState: function() {},
|
||||
replaceState: function() {}
|
||||
}
|
||||
});
|
||||
Backbone.history.start({root: ''});
|
||||
|
@ -625,8 +636,8 @@
|
|||
Backbone.history = _.extend(new Backbone.History, {
|
||||
location: location,
|
||||
history: {
|
||||
pushState: function(){},
|
||||
replaceState: function(state, title, url){
|
||||
pushState: function() {},
|
||||
replaceState: function(state, title, url) {
|
||||
assert.strictEqual(url, '/root/x/y?a=b');
|
||||
}
|
||||
}
|
||||
|
@ -641,8 +652,8 @@
|
|||
assert.expect(1);
|
||||
var MyRouter = Backbone.Router.extend({
|
||||
routes: {'': 'empty'},
|
||||
empty: function(){},
|
||||
route: function(route){
|
||||
empty: function() {},
|
||||
route: function(route) {
|
||||
assert.strictEqual(route, '');
|
||||
}
|
||||
});
|
||||
|
@ -655,7 +666,8 @@
|
|||
assert.strictEqual(history.getFragment('fragment '), 'fragment');
|
||||
});
|
||||
|
||||
QUnit.test('#1820 - Leading slash and trailing space.', 1, function(assert) {
|
||||
QUnit.test('#1820 - Leading slash and trailing space.', function(assert) {
|
||||
assert.expect(1);
|
||||
var history = new Backbone.History;
|
||||
assert.strictEqual(history.getFragment('/fragment '), 'fragment');
|
||||
});
|
||||
|
@ -670,7 +682,7 @@
|
|||
assert.strictEqual(router.z, '123');
|
||||
});
|
||||
|
||||
QUnit.test("#2062 - Trigger 'route' event on router instance.", function(assert) {
|
||||
QUnit.test('#2062 - Trigger "route" event on router instance.', function(assert) {
|
||||
assert.expect(2);
|
||||
router.on('route', function(name, args) {
|
||||
assert.strictEqual(name, 'routeEvent');
|
||||
|
@ -709,8 +721,8 @@
|
|||
Backbone.history = _.extend(new Backbone.History, {
|
||||
location: location,
|
||||
history: {
|
||||
pushState: function(){},
|
||||
replaceState: function(){ assert.ok(false); }
|
||||
pushState: function() {},
|
||||
replaceState: function() { assert.ok(false); }
|
||||
}
|
||||
});
|
||||
Backbone.history.start({
|
||||
|
@ -726,8 +738,8 @@
|
|||
Backbone.history = _.extend(new Backbone.History, {
|
||||
location: location,
|
||||
history: {
|
||||
pushState: function(){},
|
||||
replaceState: function(){}
|
||||
pushState: function() {},
|
||||
replaceState: function() {}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -753,7 +765,7 @@
|
|||
Backbone.history = _.extend(new Backbone.History, {
|
||||
location: location,
|
||||
history: {
|
||||
pushState: function(state, title, url){
|
||||
pushState: function(state, title, url) {
|
||||
assert.strictEqual(url, '/root');
|
||||
}
|
||||
}
|
||||
|
@ -785,7 +797,7 @@
|
|||
Backbone.history = _.extend(new Backbone.History, {
|
||||
location: location,
|
||||
history: {
|
||||
pushState: function(state, title, url){
|
||||
pushState: function(state, title, url) {
|
||||
assert.strictEqual(url, '/root?x=1');
|
||||
}
|
||||
}
|
||||
|
@ -823,7 +835,7 @@
|
|||
assert.expect(1);
|
||||
var MyRouter = Backbone.Router.extend({
|
||||
routes: {
|
||||
path: function(params){
|
||||
path: function(params) {
|
||||
assert.strictEqual(params, 'x=y%3Fz');
|
||||
}
|
||||
}
|
||||
|
@ -921,7 +933,7 @@
|
|||
Backbone.history = _.extend(new Backbone.History, {location: location});
|
||||
var MyRouter = Backbone.Router.extend({
|
||||
routes: {'foo/:id/bar': 'foo'},
|
||||
foo: function(){},
|
||||
foo: function() {},
|
||||
execute: function(callback, args, name) {
|
||||
assert.strictEqual(callback, this.foo);
|
||||
assert.deepEqual(args, ['123', 'x=y']);
|
||||
|
@ -953,8 +965,8 @@
|
|||
Backbone.history = _.extend(new Backbone.History, {
|
||||
location: location,
|
||||
history: {
|
||||
pushState: function(){ assert.ok(false); },
|
||||
replaceState: function(){ assert.ok(false); }
|
||||
pushState: function() { assert.ok(false); },
|
||||
replaceState: function() { assert.ok(false); }
|
||||
}
|
||||
});
|
||||
Backbone.history.start({pushState: true});
|
||||
|
@ -991,14 +1003,14 @@
|
|||
Backbone.history.start({root: '/root', pushState: true});
|
||||
});
|
||||
|
||||
QUnit.test("Paths that don't match the root should not match no root", function(assert) {
|
||||
QUnit.test('Paths that don\'t match the root should not match no root', function(assert) {
|
||||
assert.expect(0);
|
||||
location.replace('http://example.com/foo');
|
||||
Backbone.history.stop();
|
||||
Backbone.history = _.extend(new Backbone.History, {location: location});
|
||||
var MyRouter = Backbone.Router.extend({
|
||||
routes: {
|
||||
foo: function(){
|
||||
foo: function() {
|
||||
assert.ok(false, 'should not match unless root matches');
|
||||
}
|
||||
}
|
||||
|
@ -1007,14 +1019,14 @@
|
|||
Backbone.history.start({root: 'root', pushState: true});
|
||||
});
|
||||
|
||||
QUnit.test("Paths that don't match the root should not match roots of the same length", function(assert) {
|
||||
QUnit.test('Paths that don\'t match the root should not match roots of the same length', function(assert) {
|
||||
assert.expect(0);
|
||||
location.replace('http://example.com/xxxx/foo');
|
||||
Backbone.history.stop();
|
||||
Backbone.history = _.extend(new Backbone.History, {location: location});
|
||||
var MyRouter = Backbone.Router.extend({
|
||||
routes: {
|
||||
foo: function(){
|
||||
foo: function() {
|
||||
assert.ok(false, 'should not match unless root matches');
|
||||
}
|
||||
}
|
||||
|
@ -1029,7 +1041,7 @@
|
|||
Backbone.history.stop();
|
||||
Backbone.history = _.extend(new Backbone.History, {location: location});
|
||||
var MyRouter = Backbone.Router.extend({
|
||||
routes: {foo: function(){ assert.ok(true); }}
|
||||
routes: {foo: function() { assert.ok(true); }}
|
||||
});
|
||||
var myRouter = new MyRouter;
|
||||
Backbone.history.start({root: 'x+y.z', pushState: true});
|
||||
|
@ -1041,7 +1053,7 @@
|
|||
Backbone.history.stop();
|
||||
Backbone.history = _.extend(new Backbone.History, {location: location});
|
||||
var MyRouter = Backbone.Router.extend({
|
||||
routes: {foo: function(){ assert.ok(true); }}
|
||||
routes: {foo: function() { assert.ok(true); }}
|
||||
});
|
||||
var myRouter = new MyRouter;
|
||||
Backbone.history.start({root: '®ooτ', pushState: true});
|
||||
|
@ -1053,10 +1065,17 @@
|
|||
Backbone.history.stop();
|
||||
Backbone.history = _.extend(new Backbone.History, {location: location});
|
||||
var MyRouter = Backbone.Router.extend({
|
||||
routes: {'': function(){ assert.ok(true); }}
|
||||
routes: {'': function() { assert.ok(true); }}
|
||||
});
|
||||
var myRouter = new MyRouter;
|
||||
Backbone.history.start({root: '®ooτ', pushState: true});
|
||||
});
|
||||
|
||||
})();
|
||||
QUnit.test('#4025 - navigate updates URL hash as is', function(assert) {
|
||||
assert.expect(1);
|
||||
var route = 'search/has%20space';
|
||||
Backbone.history.navigate(route);
|
||||
assert.strictEqual(location.hash, '#' + route);
|
||||
});
|
||||
|
||||
})(QUnit);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
(function() {
|
||||
(function(QUnit) {
|
||||
|
||||
var sync = Backbone.sync;
|
||||
var ajax = Backbone.ajax;
|
||||
|
@ -14,7 +14,7 @@
|
|||
var env = QUnit.config.current.testEnvironment;
|
||||
|
||||
// We never want to actually call these during tests.
|
||||
history.pushState = history.replaceState = function(){};
|
||||
history.pushState = history.replaceState = function() {};
|
||||
|
||||
// Capture ajax settings for comparison.
|
||||
Backbone.ajax = function(settings) {
|
||||
|
@ -42,4 +42,4 @@
|
|||
history.replaceState = replaceState;
|
||||
});
|
||||
|
||||
})();
|
||||
})(QUnit);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
(function() {
|
||||
(function(QUnit) {
|
||||
|
||||
var Library = Backbone.Collection.extend({
|
||||
url: function() { return '/library'; }
|
||||
|
@ -158,7 +158,7 @@
|
|||
|
||||
QUnit.test('Backbone.ajax', function(assert) {
|
||||
assert.expect(1);
|
||||
Backbone.ajax = function(settings){
|
||||
Backbone.ajax = function(settings) {
|
||||
assert.strictEqual(settings.url, '/test');
|
||||
};
|
||||
var model = new Backbone.Model();
|
||||
|
@ -236,4 +236,4 @@
|
|||
this.ajaxSettings.error({}, 'textStatus', 'errorThrown');
|
||||
});
|
||||
|
||||
})();
|
||||
})(QUnit);
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
(function() {
|
||||
(function(QUnit) {
|
||||
|
||||
var view;
|
||||
|
||||
QUnit.module('Backbone.View', {
|
||||
|
||||
beforeEach: function(assert) {
|
||||
beforeEach: function() {
|
||||
$('#qunit-fixture').append(
|
||||
'<div id="testElement"><h1>Test</h1></div>'
|
||||
);
|
||||
);
|
||||
|
||||
view = new Backbone.View({
|
||||
id: 'test-view',
|
||||
|
@ -61,6 +61,28 @@
|
|||
assert.strictEqual(new View().one, 1);
|
||||
});
|
||||
|
||||
QUnit.test('preinitialize', function(assert) {
|
||||
assert.expect(1);
|
||||
var View = Backbone.View.extend({
|
||||
preinitialize: function() {
|
||||
this.one = 1;
|
||||
}
|
||||
});
|
||||
|
||||
assert.strictEqual(new View().one, 1);
|
||||
});
|
||||
|
||||
QUnit.test('preinitialize occurs before the view is set up', function(assert) {
|
||||
assert.expect(2);
|
||||
var View = Backbone.View.extend({
|
||||
preinitialize: function() {
|
||||
assert.equal(this.el, undefined);
|
||||
}
|
||||
});
|
||||
var _view = new View({});
|
||||
assert.notEqual(_view.el, undefined);
|
||||
});
|
||||
|
||||
QUnit.test('render', function(assert) {
|
||||
assert.expect(1);
|
||||
var myView = new Backbone.View;
|
||||
|
@ -72,8 +94,8 @@
|
|||
var counter1 = 0, counter2 = 0;
|
||||
|
||||
var myView = new Backbone.View({el: '#testElement'});
|
||||
myView.increment = function(){ counter1++; };
|
||||
myView.$el.on('click', function(){ counter2++; });
|
||||
myView.increment = function() { counter1++; };
|
||||
myView.$el.on('click', function() { counter2++; });
|
||||
|
||||
var events = {'click h1': 'increment'};
|
||||
|
||||
|
@ -129,11 +151,10 @@
|
|||
assert.equal(myView.counter, 3);
|
||||
});
|
||||
|
||||
|
||||
QUnit.test('delegateEvents ignore undefined methods', function(assert) {
|
||||
assert.expect(0);
|
||||
var myView = new Backbone.View({el: '<p></p>'});
|
||||
myView.delegateEvents({'click': 'undefinedMethod'});
|
||||
myView.delegateEvents({click: 'undefinedMethod'});
|
||||
myView.$el.trigger('click');
|
||||
});
|
||||
|
||||
|
@ -142,8 +163,8 @@
|
|||
var counter1 = 0, counter2 = 0;
|
||||
|
||||
var myView = new Backbone.View({el: '#testElement'});
|
||||
myView.increment = function(){ counter1++; };
|
||||
myView.$el.on('click', function(){ counter2++; });
|
||||
myView.increment = function() { counter1++; };
|
||||
myView.$el.on('click', function() { counter2++; });
|
||||
|
||||
var events = {'click h1': 'increment'};
|
||||
|
||||
|
@ -203,7 +224,7 @@
|
|||
assert.expect(2);
|
||||
var myView = new Backbone.View({el: '#testElement'});
|
||||
myView.delegate('click', function() { assert.ok(true); });
|
||||
var handler = function(){ assert.ok(false); };
|
||||
var handler = function() { assert.ok(false); };
|
||||
myView.delegate('click', 'h1', handler);
|
||||
myView.undelegate('click', 'h1', handler);
|
||||
myView.$('h1').trigger('click');
|
||||
|
@ -405,8 +426,8 @@
|
|||
assert.expect(0);
|
||||
var View = Backbone.View.extend({
|
||||
initialize: function() {
|
||||
this.listenTo(this.model, 'all x', function(){ assert.ok(false); });
|
||||
this.listenTo(this.collection, 'all x', function(){ assert.ok(false); });
|
||||
this.listenTo(this.model, 'all x', function() { assert.ok(false); });
|
||||
this.listenTo(this.collection, 'all x', function() { assert.ok(false); });
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -492,4 +513,4 @@
|
|||
assert.notEqual($oldEl, myView.$el);
|
||||
});
|
||||
|
||||
})();
|
||||
})(QUnit);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue