-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
132 lines (100 loc) · 3.47 KB
/
index.html
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<html>
<script type="text/javascript" src="dist/aw-parser.amd.js"></script>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<textarea id="config" class="config"></textarea>
<textarea id="editor" class="editor">
Title: Test Script
Author: John Doe
INT. TEST - DAY
Action test. Action test. Action test. Action test. Action test. Action test. Action test. Action test. Action test.
HERO 1
Hello --
Hello!
HERO 2
Hello
</textarea>
<p id="results" class="results"></p>
<script type="text/javascript">
function getEditor() {
return document.getElementById('editor');
}
function getConfig() {
return document.getElementById('config');
}
function getResults() {
return document.getElementById('results');
}
function tokenToString(token) {
var text;
text = token.text.length > 20 ? (token.text.substr(0, 17) + '...') : token.text;
return token.type + ' [' + token.start + ':' + token.end + '] ' + text;
}
function parserResultToHTML(parserResult) {
var titleHTML, pagesHTML;
titleHTML = parserResult.title_page.map(tokenToString).join('<br />');
pagesHTML = parserResult.tokens.map(tokenToString).join('<br />');
return '<b>Title:</b><br/><br/>' + titleHTML + '<br/><br/><b>Pages:</b><br/><br/>' + pagesHTML;
}
window.onload = function() {
presenter.loadDefaults();
presenter.init();
};
var presenter = {
getConfig: function() {
try {
var defaultConfig = window.localStorage.getItem('config');
defaultConfig = JSON.parse(defaultConfig);
if (!defaultConfig) {
throw new Error();
}
} catch (e) {
defaultConfig = {
print_headers: true,
print_actions: true,
print_dialogues: true,
print_notes: true,
print_sections: true,
print_synopsis: true,
each_scene_on_new_page: true,
double_space_between_scenes: true,
use_dual_dialogue: true,
merge_multiple_empty_lines: true
};
}
return defaultConfig;
},
getLastEditor: function() {
return window.localStorage.getItem('text');
},
loadDefaults: function() {
getConfig().value = JSON.stringify(this.getConfig(), null, 2);
var defaultText = this.getLastEditor();
if (defaultText) {
getEditor().value = defaultText;
}
},
init: function() {
getEditor().onkeyup = this.parse.bind(this);
getConfig().onkeyup = this.parse.bind(this);
this.parse();
},
parse: function() {
var script, result;
script = getEditor().value;
try {
config = JSON.parse(getConfig().value);
result = awParser.parser.parse(script, config);
getResults().innerHTML = parserResultToHTML(result);
getConfig().classList.remove('invalid');
window.localStorage.setItem('text', getEditor().value);
window.localStorage.setItem('config', getConfig().value);
} catch (e) {
getConfig().classList.add('invalid');
}
}
}
</script>
</body>
</html>