Skip to content

Commit

Permalink
Visit#hasSnapshot returns false if the snapshot doesn't contain the a…
Browse files Browse the repository at this point in the history
…nchor we're visiting
  • Loading branch information
packagethief committed Sep 23, 2015
1 parent 46d64d1 commit 3fa127b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/turbolinks/controller.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,14 @@ class Turbolinks.Controller
@cache.put(@lastRenderedLocation, snapshot)

restoreSnapshotForLocation: (location) ->
if snapshot = @cache.get(location)
if snapshot = @getSnapshotForLocation(location)
@view.loadSnapshot(snapshot)
@notifyApplicationAfterSnapshotLoad()
true

getSnapshotForLocation: (location) ->
@cache.get(location)

# Scrolling

scrollToAnchor: (anchor) ->
Expand Down
3 changes: 3 additions & 0 deletions src/turbolinks/snapshot.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class Turbolinks.Snapshot
@head = head
@body = body

hasAnchor: (anchor) ->
@body.querySelector(anchor)?

hasSameTrackedHeadElementsAsSnapshot: (snapshot) ->
@getTrackedHeadElementSet().isEqualTo(snapshot.getTrackedHeadElementSet())

Expand Down
6 changes: 5 additions & 1 deletion src/turbolinks/visit.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ class Turbolinks.Visit
@request.send()

hasSnapshot: ->
@controller.hasSnapshotForLocation(@location)
if snapshot = @controller.getSnapshotForLocation(location)
if @location.anchor?
snapshot.hasAnchor(@location.anchor)
else
true

restoreSnapshot: ->
if @hasSnapshot() and not @snapshotRestored
Expand Down

0 comments on commit 3fa127b

Please sign in to comment.