Permalink
Browse files

Add popstate event

  • Loading branch information...
1 parent 226989c commit 2743a441033b290b078fee6c6fdf3f06dfbaa70a @josh josh committed Apr 30, 2012
Showing with 30 additions and 0 deletions.
  1. +6 −0 jquery.pjax.js
  2. +24 −0 test/unit/pjax.js
View
@@ -583,6 +583,12 @@ $(window).bind('popstate', function(event){
containerCache[direction](pjax.state.id, container.clone(true, true).contents())
}
+ var popstateEvent = $.Event('pjax:popstate', {
+ state: state,
+ direction: direction
+ })
+ container.trigger(popstateEvent)
+
var options = {
id: state.id,
url: state.url,
View
@@ -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() {
var frame = this.frame

0 comments on commit 2743a44

Please sign in to comment.