Skip to content

Commit

Permalink
[Closes assaf#188] jQuery.live(click) works with pressButton.
Browse files Browse the repository at this point in the history
  • Loading branch information
assaf committed May 28, 2012
1 parent b574601 commit d15a08f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/zombie/browser.coffee
Expand Up @@ -685,9 +685,9 @@ class Browser extends EventEmitter
button: (selector)->
if button = @querySelector(selector)
return button if button.tagName == "BUTTON" || button.tagName == "INPUT"
for button in @querySelectorAll("form button")
for button in @querySelectorAll("button")
return button if button.textContent.trim() == selector
inputs = @querySelectorAll("form :submit, form :reset, form :button")
inputs = @querySelectorAll(":submit, :reset, :button")
for input in inputs
return input if input.name == selector
for input in inputs
Expand Down
22 changes: 22 additions & 0 deletions test/jquery_compat_test.coffee
Expand Up @@ -29,6 +29,10 @@ test = (version)->
<input id="edit-subject" value="subject">
<textarea id="edit-note">note</textarea>
<form action="/zombie/dead-end">
<button class="some-class">Click Me</button>
</form>
</body>
<script>
Expand Down Expand Up @@ -98,6 +102,24 @@ test = (version)->
assert !@browser.query("textarea#edit-note").textContent


# Using new event delegation introduced in 1.7
if version > "1.7"

describe "event handling", ->
it "should catch live event handler", (done)->
@browser.window.$(@browser.document).live "click", ".some-class", (event)->
done()
@browser.pressButton "Click Me"

it "should respect preventDefault in event delegation", (done)->
@browser.window.$(@browser.document).on "click", ".some-class", (event)->
event.preventDefault()
return
@browser.pressButton "Click Me", =>
assert @browser.location.pathname != "/zombie/dead-end"
done()


describe "Compatibility with jQuery", ->

for version in JQUERY_VERSIONS
Expand Down

0 comments on commit d15a08f

Please sign in to comment.