19a28a7f by Michael Richards

Merge branch 'fix-unbind'

2 parents a7963f51 3ae30db0
......@@ -15,6 +15,7 @@
<script type="text/javascript" src="matchers.js"></script>
<script type="text/javascript" src="mock.data.js"></script>
<script type="text/javascript" src="rivets/binding.js"></script>
<script type="text/javascript" src="rivets/binders.js"></script>
<script type="text/javascript" src="rivets/routines.js"></script>
<script type="text/javascript" src="rivets/functional.js"></script>
......
describe("Rives.binders", function() {
var context;
beforeEach(function() {
context = {
publish: function() {}
}
});
describe("value", function() {
var el;
beforeEach(function() {
el = document.createElement('input');
});
it("unbinds the same bound function", function() {
var boundFn;
spyOn(el, 'addEventListener').andCallFake(function(event, fn) {
boundFn = fn;
});
rivets.binders.value.bind.call(context, el);
spyOn(el, 'removeEventListener').andCallFake(function(event, fn) {
expect(fn).toBe(boundFn);
});
rivets.binders.value.unbind.call(context, el);
});
});
});
\ No newline at end of file
......@@ -243,9 +243,9 @@ Rivets.binders =
checked:
publishes: true
bind: (el) ->
bindEvent el, 'change', @publish
@currentListener = bindEvent el, 'change', @publish
unbind: (el) ->
unbindEvent el, 'change', @publish
unbindEvent el, 'change', @currentListener
routine: (el, value) ->
if el.type is 'radio'
el.checked = el.value is value
......@@ -255,9 +255,9 @@ Rivets.binders =
unchecked:
publishes: true
bind: (el) ->
bindEvent el, 'change', @publish
@currentListener = bindEvent el, 'change', @publish
unbind: (el) ->
unbindEvent el, 'change', @publish
unbindEvent el, 'change', @currentListener
routine: (el, value) ->
if el.type is 'radio'
el.checked = el.value isnt value
......@@ -276,9 +276,9 @@ Rivets.binders =
value:
publishes: true
bind: (el) ->
bindEvent el, 'change', @publish
@currentListener = bindEvent el, 'change', @publish
unbind: (el) ->
unbindEvent el, 'change', @publish
unbindEvent el, 'change', @currentListener
routine: (el, value) ->
if el.type is 'select-multiple'
o.selected = o.value in value for o in el if value?
......