Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pjax:clicked event #345

Merged
merged 2 commits into from Jan 29, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions jquery.pjax.js
Expand Up @@ -95,6 +95,9 @@ function handleClick(event, container, options) {
if (!clickEvent.isDefaultPrevented()) {
pjax(opts)
event.preventDefault()

clickEvent = $.Event('pjax:clicked')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doesn't this leak a global. You can pass 'pjax:clicked' string directly to trigger

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It uses an another defined var.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Realizing I don't need to make the event, cause I don't care about seeing if its canceled.

$(link).trigger(clickEvent, [opts])
}
}

Expand Down
13 changes: 13 additions & 0 deletions test/unit/fn_pjax.js
Expand Up @@ -217,4 +217,17 @@ if ($.support.pjax) {

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

asyncTest("triggers pjax:clicked event from link", function() {
var frame = this.frame

frame.$("#main").pjax("a").on("pjax:clicked", function(event, options) {
ok(event)
ok(options.container.is('#main'))
ok(options.url.match("/dinosaurs.html"))
start()
})

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