Skip to content

Commit 97bccf9

Browse files
committed
Merge pull request #379 from marcandre/ignore_prevented_default
Ignore events with prevented defaults
2 parents 17a6082 + a552721 commit 97bccf9

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

jquery.pjax.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ function handleClick(event, container, options) {
8282
if (link.href === location.href + '#')
8383
return
8484

85+
// Ignore event with default prevented
86+
if (event.isDefaultPrevented())
87+
return
88+
8589
var defaults = {
8690
url: link.href,
8791
container: $(link).attr('data-pjax'),

test/unit/fn_pjax.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,25 @@ if ($.support.pjax) {
191191
start()
192192
})
193193

194+
asyncTest("ignores event with prevented default", function() {
195+
var frame = this.frame
196+
var eventIgnored = true
197+
198+
frame.$("#main").pjax("a").on("pjax:click", function() {
199+
eventIgnored = false
200+
})
201+
frame.$("a[href='/dinosaurs.html']").on("click", function(event) {
202+
event.preventDefault()
203+
setTimeout(function() {
204+
ok(eventIgnored, "Event with prevented default ignored")
205+
start()
206+
}, 10)
207+
})
208+
209+
frame.$("a[href='/dinosaurs.html']").click()
210+
})
211+
212+
194213
asyncTest("scrolls to anchor after load", function() {
195214
var frame = this.frame
196215

0 commit comments

Comments
 (0)