Tale

Used to provide access to passages.  This is analogous to the TiddlyWiki class in the core TiddlyWiki code.

Summary
Used to provide access to passages.
An associative array of Passage objects in the story.
Initializes a new Tale object with the contents of the DOM element with the id storeArea, constructing new Passages as it traverses the tree.
Checks whether the tale has a passage with either the title passed (if the key parameter is a string) or an id (if a number is passed instead).
A getter function that returns a certain Passage object belonging to the tale.
Searches the Tale for all passages matching a certain criteria.
Calls the Passage.reset method on all Passages in the tale, restoring the story to its initial state.

Properties

passages

An associative array of Passage objects in the story.  The key for this array is the title of the passage.

Functions

Tale

function Tale()

Initializes a new Tale object with the contents of the DOM element with the id storeArea, constructing new Passages as it traverses the tree.

Parameters

none

has

Tale.prototype.has = function (key)

Checks whether the tale has a passage with either the title passed (if the key parameter is a string) or an id (if a number is passed instead).

Parameters

keythe title or id of the passage to search for

Returns

boolean

get

Tale.prototype.get = function (key)

A getter function that returns a certain Passage object belonging to the tale.  You may either retrieve a passage by its title or id.

Parameters

keythe title or id of the passage to retrieve

Returns

A Passage object.  If no passage exists matching the passed key, a null value is returned.

See also

Tale.lookup

lookup

Tale.prototype.lookup = function(field,
value,
sortField)

Searches the Tale for all passages matching a certain criteria.  You may optionally specify a secondary field to sort the results on.

Parameters

fieldthe name of the Passage property to search on
valuethe value to match
sortFieldthe name of the Passage property to sort matches on.  This always sorts in descending order.  If you need ascending order, use the Array class’s reverse() method.

Returns

An array of Passages.  If no passages met the search criteria, an empty array is returned.

See also

Tale.get

reset

Tale.prototype.reset = function()

Calls the Passage.reset method on all Passages in the tale, restoring the story to its initial state.

Parameters

none

Returns

nothing

This class represents an individual passage.
function Tale()
Initializes a new Tale object with the contents of the DOM element with the id storeArea, constructing new Passages as it traverses the tree.
Tale.prototype.has = function (key)
Checks whether the tale has a passage with either the title passed (if the key parameter is a string) or an id (if a number is passed instead).
Tale.prototype.get = function (key)
A getter function that returns a certain Passage object belonging to the tale.
Tale.prototype.lookup = function(field,
value,
sortField)
Searches the Tale for all passages matching a certain criteria.
Tale.prototype.reset = function()
Calls the Passage.reset method on all Passages in the tale, restoring the story to its initial state.
Passage.prototype.reset = function()
Resets the passage’s text property to its initialText property.