Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions jquery.pjax.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ function handleClick(event, container, options) {
if (link.href === location.href + '#')
return

// Ignore event with default prevented
if (event.isDefaultPrevented())
return

var defaults = {
url: link.href,
container: $(link).attr('data-pjax'),
Expand Down
19 changes: 19 additions & 0 deletions test/unit/fn_pjax.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,25 @@ if ($.support.pjax) {
start()
})

asyncTest("ignores event with prevented default", function() {
var frame = this.frame
var eventIgnored = true

frame.$("#main").pjax("a").on("pjax:click", function() {
eventIgnored = false
})
frame.$("a[href='/dinosaurs.html']").on("click", function(event) {
event.preventDefault()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test should be unpaused here after a timeout, to allow potential async stuff to happen (even though we don't expect it).

So, instead of a start() at the end of the test, you shoud add something like setTimeout(start, 10) here in the click handler. This way we can be sure that the click actually happened.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, @marcandre, this will be good to go as soon as you improve this test in the manner that I described. Let me know if you won't have a chance to do it. Thanks!

setTimeout(function() {
ok(eventIgnored, "Event with prevented default ignored")
start()
}, 10)
})

frame.$("a[href='/dinosaurs.html']").click()
})


asyncTest("scrolls to anchor after load", function() {
var frame = this.frame

Expand Down