Skip to content
This repository has been archived by the owner on Sep 14, 2019. It is now read-only.

Commit

Permalink
added the ability to refer to $el when writing unobtrusive bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
dzrw committed Feb 13, 2012
1 parent b13664a commit 7c5303c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion outback.js
Expand Up @@ -168,7 +168,7 @@
if(!hop(view[viewAttr], selector)) return;

var element, directives;
element = view.$(selector);
element = selector === '' ? view.$el : view.$(selector);

if(element.size() !== 0) {
directives = rj.revive(value, makeUnobtrusiveBindingDeclReviver(model));
Expand Down
25 changes: 24 additions & 1 deletion spec/outback.spec.js
Expand Up @@ -223,6 +223,29 @@ describe('outback.js declarative bindings for backbone.js', function() {

expect(Backbone.outback.bindingHandlers.nop.update.callCount).toBe(1);
});

it('should be possible to refer to the root of the view using the unobtrusive style', function() {
var view, model;
model = new AModel({ isActive: true });
view = new TypicalView({model: model});
_.extend(view, {
modelBindings: {
'': {
css: { 'ui-active': Backbone.outback.modelRef('isActive') }
}
}
});

view.render();

expect(view.$el.hasClass('ui-active')).toBeTruthy();

model.set({isActive: false});

expect(view.$el.hasClass('ui-active')).toBeFalsy();

view.remove();
});
});
});

Expand Down Expand Up @@ -281,7 +304,7 @@ describe('outback.js declarative bindings for backbone.js', function() {
});
});

describe("supports multiple bindings contexts", function() {
describe("supports multiple binding contexts", function() {

beforeEach(function(){
this.model = new Backbone.Model({x: false});
Expand Down

0 comments on commit 7c5303c

Please sign in to comment.