History

A class used to manage the state of the story -- displaying new passages and rewinding to the past.

Summary
A class used to manage the state of the story -- displaying new passages and rewinding to the past.
An array representing the state of the story.
Initializes a History object.
This first attempts to restore the state of the story via the restore method.
This removes a passage from display onscreen.
Displays a passage on the page.
Restarts the story from the beginning.
Returns a hash to append to the page’s URL that will be later read by the restore method.
Attempts to restore the state of the story as saved by save.
Rewinds the state of the story to a particular Passage.

Properties

History

An array representing the state of the story. history[0] is the current state, history[1] is the state just before the present, and so on.  Each entry in the history is an object with two properties: passage, which corresponds to the Passage just displayed, and variables.  Variables is in itself an object.  Each property is a variable set by the story via the <<set>> macro.

Functions

History

function History()

Initializes a History object.

Parameters

none

init

History.prototype.init = function()

This first attempts to restore the state of the story via the restore method.  If that fails, it then either displays the passages linked in the StartPassages passage, or gives up and tries to display a passage named Start.

Parameters

none

Returns

nothing

close

History.prototype.close = function (passage)

This removes a passage from display onscreen.  This does not animate its disappearance.

Parameters

passagethe Passage to remove

Returns

nothing

display

History.prototype.display = function (title,
link,
render)

Displays a passage on the page.  If a passage has previously been displayed, the browser window is scrolled so it is in view.

Parameters

titlethe title of the passage to display.
linkthe DOM element corresponding to the link that was clicked to view the passage.  The new passage is displayed immediately below the passage enclosed by the link.  This parameter is optional.  If it is omitted, the passage is displayed at the bottom of the page.
rendermay be either “quietly” or “offscreen”.  If a “quietly” value is passed, the passage’s appearance is not animated.  “offscreen” asks that the passage be rendered, but not displayed at all.  This parameter is optional.  If it is omitted, then the passage’s appearance is animated.

Returns

The DOM element containing the passage on the page.

restart

History.prototype.restart = function()

Restarts the story from the beginning.  This actually forces the browser to refresh the page.

Parameters

none

Returns

none

save

History.prototype.save = function (passage)

Returns a hash to append to the page’s URL that will be later read by the restore method.  How this is generated is not guaranteed to remain constant in future releases -- but it is guaranteed to be understood by restore.

Parameters

passagea Passage whose point in the history to save.  This parameter is optional -- if omitted, then the entire story’s history is saved.

Returns

A hash to append to the page’s URL.

restore

History.prototype.restore = function ()

Attempts to restore the state of the story as saved by save.

Parameters

none

Returns

Whether this method actually restored anything.

rewindTo

History.prototype.rewindTo = function (passage)

Rewinds the state of the story to a particular Passage.

Parameters

passagea Passage to rewind to.

Returns

nothing

function History()
Initializes a History object.
History.prototype.init = function()
This first attempts to restore the state of the story via the restore method.
History.prototype.restore = function ()
Attempts to restore the state of the story as saved by save.
History.prototype.close = function (passage)
This removes a passage from display onscreen.
History.prototype.display = function (title,
link,
render)
Displays a passage on the page.
History.prototype.restart = function()
Restarts the story from the beginning.
History.prototype.save = function (passage)
Returns a hash to append to the page’s URL that will be later read by the restore method.
History.prototype.rewindTo = function (passage)
Rewinds the state of the story to a particular Passage.
This class represents an individual passage.