Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added the ability to refer to $el when writing unobtrusive bindings

  • Loading branch information...
commit 7c5303ca969ba1cfe6fd200e7c02fd18fcc31d3f 1 parent b13664a
politician authored
Showing with 25 additions and 2 deletions.
  1. +1 −1  outback.js
  2. +24 −1 spec/outback.spec.js
2  outback.js
View
@@ -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));
25 spec/outback.spec.js
View
@@ -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();
+ });
});
});
@@ -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});
Please sign in to comment.
Something went wrong with that request. Please try again.