This repository has been archived by the owner on Nov 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sidebar.html
212 lines (200 loc) · 5.71 KB
/
Sidebar.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
<!-- The CSS package above applies Google styling to buttons and other elements. -->
<style>
.width-100 {
width: 100%;
}
</style>
</head>
<body>
<div class="sidebar">
<form>
<div class="block" id="button-bar">
<button class="blue" id="run-format" type="button">Format</button>
<button class="blue" id="run-export" type="button">To XML</button>
<button class="blue" id="run-import" type="button" disabled>From XML</button>
<!--<button id="debug-dom">Debug DOM</button>-->
</div>
<!--<div class="block">
<h4>Formatting</h4>
<div class="block">
<input type="checkbox" id="apply-format" checked>
<label for="apply-format">Apply formatting</label>
</div>
<div class="block">
<label for="blocks-mode">[if]-blocks and text inside</label>
<select id="blocks-mode">
<option value="none">None</option>
<option value="fill">Highlight</option>
<option value="color">Text color</option>
<option value="color2">Brighter Text color</option>
</select>
</div>
<div class="block">
<input type="checkbox" id="blocks-bold">
<label for="blocks-bold">Bold block tags</label>
</div>
<div class="block">
<label for="buttons-mode">Buttons & actions</label>
<select id="buttons-mode">
<option value="none">None</option>
<option value="fill">Highlight</option>
<option value="mono">Mono font</option>
<option value="boldmono">Bold mono font</option>
</select>
</div>
<div class="block">
<label for="comments-mode">// Comments</label>
<select id="comments-mode">
<option value="none">None</option>
<option value="fill">Highlight</option>
<option value="color">Text color</option>
<option value="italic">Italic font</option>
</select>
</div>
</div>-->
<div class="block form-group">
<label for="converted-text"><b>XML</b></label>
<textarea class="width-100" id="converted-text" rows="10"></textarea>
</div>
<!--<div class="block">
<input type="checkbox" id="save-prefs">
<label for="save-prefs">Use these languages by default</label>
</div>-->
</form>
</div>
<div class="sidebar bottom">
<span class="gray">Lewd Writer's Assistant by aimozg</span>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script>
/**
* On document load, assign click handlers to each button and try to load the
* preferences if previously set.
*/
$(function () {
$('#run-format').click(runFormat);
$('#run-export').click(runExport);
$('#debug-dom').click(debugDom);
google.script.run.withSuccessHandler(loadPreferences)
.withFailureHandler(showError).getPreferences();
});
/**
* Callback function that populates the UI with user preferences from the server.
*/
function loadPreferences(prefs) {
$('#apply-format').prop('checked', prefs.applyFormat);
$('#blocks-bold').prop('checked', prefs.blocksBold);
$('#blocks-mode').val(prefs.blocksMode);
$('#buttons-mode').val(prefs.buttonsMode);
$('#comments-mode').val(prefs.commentsMode);
}
function runFormat() {
this.disabled = true;
$('#error').remove();
google.script.run
.withSuccessHandler(
function (result, element) {
// $('#converted-text').val(result.xml.join('\n'));
element.disabled = false;
})
.withFailureHandler(
function (msg, element) {
showError(msg, $('#button-bar'));
element.disabled = false;
})
.withUserObject(this)
.formatDocument({});
}
function runExport() {
this.disabled = true;
$('#error').remove();
google.script.run
.withSuccessHandler(
function (result, element) {
$('#converted-text').val(result.xml);
element.disabled = false;
})
.withFailureHandler(
function (msg, element) {
showError(msg, $('#button-bar'));
element.disabled = false;
})
.withUserObject(this)
.exportDocument({});
}
function runTranslation() {
this.disabled = true;
$('#error').remove();
google.script.run
.withSuccessHandler(
function (result, element) {
$('#converted-text').val(result.as3.join('\n'));
element.disabled = false;
})
.withFailureHandler(
function (msg, element) {
showError(msg, $('#button-bar'));
element.disabled = false;
})
.withUserObject(this)
.transpile({
applyFormat: $('#apply-format').prop('checked'),
blocksMode: $('#blocks-mode').val(),
blocksBold: $('#blocks-bold').prop('checked'),
commentsMode: $('#comments-mode').val(),
buttonsMode: $('#buttons-mode').val()
});
}
function debugDom() {
this.disabled = true;
$('#error').remove();
google.script.run
.withSuccessHandler(
function (result, element) {
console.log(result.logs);
element.disabled = false;
})
.withFailureHandler(
function (msg, element) {
showError(msg, $('#button-bar'));
element.disabled = false;
})
.withUserObject(this)
.debugDom();
}
/**
* Runs a server-side function to insert the translated text into the document
* at the user's cursor or selection.
*/
/*function insertText() {
this.disabled = true;
$('#error').remove();
google.script.run
.withSuccessHandler(
function(returnSuccess, element) {
element.disabled = false;
})
.withFailureHandler(
function(msg, element) {
showError(msg, $('#button-bar'));
element.disabled = false;
})
.withUserObject(this)
.insertText($('#translated-text').val());
}*/
/**
* Inserts a div that contains an error message after a given element.
*/
function showError(msg, element) {
var div = $('<div id="error" class="error">' + msg + '</div>');
$(element).after(div);
}
</script>
</body>
</html>