-
Notifications
You must be signed in to change notification settings - Fork 3
/
init.js
84 lines (63 loc) · 1.68 KB
/
init.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//
// Initialization
//
var version =
{
major: 2, minor: 0, revision: 0,
date: new Date('July 30, 2007'),
extensions: {}
};
// passage storage and story history
var tale, state;
// Macros
var macros = {};
//
// Function: main
//
// Loads the story from the storage div, initializes macros and
// custom stylesheets, and displays the first passages of the story.
//
// Returns:
// nothing
//
function main()
{
tale = new Tale();
// process title, subtitle, author passages
setPageElement('storyMenu', 'StoryMenu', '');
setPageElement('storyTitle', 'StoryTitle', 'Untitled Story');
setPageElement('storySubtitle', 'StorySubtitle', '');
setPageElement('storyAuthor', 'StoryAuthor', '');
if (tale.has('StoryTitle'))
{
document.title = tale.get('StoryTitle').text;
if (tale.has('StorySubtitle'))
document.title += ': ' + tale.get('StorySubtitle').text;
};
// initialize macros
for (macro in macros)
if (typeof macro.init == 'function')
macro.init();
// process passages tagged 'stylesheet'
var styles = tale.lookup('tags', 'stylesheet');
for (var i = 0; i < styles.length; i++)
addStyle(styles[i].text);
// process passages tagged 'script'
var scripts = tale.lookup('tags', 'script');
for (var i = 0; i < scripts.length; i++)
try
{
eval(scripts[i].text);
}
catch (e)
{
alert('There is a technical problem with this story (' +
scripts[i].title + ': ' + e.message + '). You may be able ' +
'to continue reading, but all parts of the story may not ' +
'work properly.');
};
// initialize history and display initial passages
state = new History();
state.init();
console.log('init complete', tale, state);
}