@@ -424,29 +424,27 @@ function onPjaxPopstate(event) {
424
424
425
425
var previousState = pjax . state
426
426
var state = event . state
427
+ var direction
427
428
428
429
if ( state && state . container ) {
429
430
// When coming forward from a separate history session, will get an
430
431
// initial pop with a state we are already at. Skip reloading the current
431
432
// page.
432
433
if ( initialPop && initialURL == state . url ) return
433
434
434
- var direction , containerSelector = state . container
435
-
436
435
if ( previousState ) {
437
436
// If popping back to the same state, just skip.
438
437
// Could be clicking back from hashchange rather than a pushState.
439
438
if ( previousState . id === state . id ) return
440
439
441
440
// Since state IDs always increase, we can deduce the navigation direction
442
441
direction = previousState . id < state . id ? 'forward' : 'back'
443
- if ( direction == 'back' ) containerSelector = previousState . container
444
442
}
445
443
446
- var container = $ ( containerSelector )
447
- if ( container . length ) {
448
- var contents = cacheMapping [ state . id ]
444
+ var cache = cacheMapping [ state . id ] || [ ]
445
+ var container = $ ( cache [ 0 ] || state . container ) , contents = cache [ 1 ]
449
446
447
+ if ( container . length ) {
450
448
if ( previousState ) {
451
449
// Cache current container before replacement and inform the
452
450
// cache which direction the history shifted.
@@ -564,7 +562,7 @@ function cloneContents(container) {
564
562
cloned . find ( 'script' ) . each ( function ( ) {
565
563
if ( ! this . src ) jQuery . _data ( this , 'globalEval' , false )
566
564
} )
567
- return cloned . contents ( )
565
+ return [ container . selector , cloned . contents ( ) ]
568
566
}
569
567
570
568
// Internal: Strips named query param from url
0 commit comments