Skip to content

Commit

Permalink
Add popstate event
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Apr 30, 2012
1 parent 226989c commit 2743a44
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions jquery.pjax.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -583,6 +583,12 @@ $(window).bind('popstate', function(event){
containerCache[direction](pjax.state.id, container.clone(true, true).contents()) containerCache[direction](pjax.state.id, container.clone(true, true).contents())
} }


var popstateEvent = $.Event('pjax:popstate', {
state: state,
direction: direction
})
container.trigger(popstateEvent)

var options = { var options = {
id: state.id, id: state.id,
url: state.url, url: state.url,
Expand Down
24 changes: 24 additions & 0 deletions test/unit/pjax.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -680,6 +680,30 @@ if ($.support.pjax) {
}) })
}) })


asyncTest("popstate going back to page triggers pjax:popstate event", function() {
var frame = this.frame

equal(frame.location.pathname, "/home.html")

frame.$('#main').on('pjax:popstate', function(event) {
equal(frame.location.pathname, "/home.html")
equal(event.state.container, '#main')
equal(event.direction, 'back')
start()
})

frame.$.pjax({
url: "hello.html",
container: "#main",
complete: function() {
equal(frame.location.pathname, "/hello.html")

ok(frame.history.length > 1)
goBack(frame, function() {})
}
})
})

asyncTest("popstate preserves GET data", function() { asyncTest("popstate preserves GET data", function() {
var frame = this.frame var frame = this.frame


Expand Down

0 comments on commit 2743a44

Please sign in to comment.