Skip to content

Commit

Permalink
Fix bug when removing a css class
Browse files Browse the repository at this point in the history
  • Loading branch information
John Lynch committed Mar 17, 2012
1 parent 8bdb947 commit 6ddebae
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/batman.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4991,7 +4991,7 @@ class Batman.DOM.AddClassBinding extends Batman.DOM.AbstractAttributeBinding
if !!value is !@invert
@node.className = "#{currentName} #{name}" if !includesClassName
else
@node.className = currentName.replace(pattern, '') if includesClassName
@node.className = currentName.replace(pattern, ' ') if includesClassName
true

class Batman.DOM.EventBinding extends Batman.DOM.AbstractAttributeBinding
Expand Down
6 changes: 4 additions & 2 deletions tests/batman/view/class_binding_test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,21 @@ asyncTest 'it should allow multiple class names to be bound and updated', ->
equal node[0].className, 'bar baz'


asyncTest 'it should allow an already present class to be removed', 4, ->
source = '<div data-removeclass-two="bar" class="zero two"></div>'
asyncTest 'it should allow an already present class to be removed', 6, ->
source = '<div data-removeclass-two="bar" class="zero two three"></div>'
context = Batman
foo: true
bar: false
helpers.render source, context, (node) ->
ok node.hasClass('zero')
ok node.hasClass('two')
ok node.hasClass('three')

context.set 'bar', true
delay ->
ok node.hasClass('zero')
ok !node.hasClass('two')
ok node.hasClass('three')

asyncTest 'it should not remove an already present similar class name', 6, ->
source = '<div data-removeclass-foobar="bar" class="zero bar"></div>'
Expand Down

0 comments on commit 6ddebae

Please sign in to comment.