Testing History API (going back)

This commit is contained in:
Alexander Yakovlev 2016-06-28 15:00:41 +07:00
parent 0d0f2e1f8e
commit ef1ce16aeb
3 changed files with 7 additions and 0 deletions

View file

@ -10,6 +10,10 @@ salet = Salet({
game_version: "1.2"
})
$(document).ready(() ->
window.addEventListener('popstate', (event) ->
salet.goBack()
)
salet.beginGame()
)

View file

@ -82,6 +82,8 @@ class SaletRoom
if system.rooms[f].exit?
system.rooms[f].exit system, @name
history.pushState(@name, @title)
if @enter
@enter system, f

View file

@ -304,6 +304,7 @@ class Salet
# Go back N rooms. It's not an UNDO.
# Also, steps = 1 is the current room
@goBack = (steps = 2) =>
window.history.back()
if @progress.path.length == 1
location = @start
else if @progress.path.length > steps