-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
353 lines (268 loc) · 12.8 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
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="description" content="Angles: a community-built XML editor" />
<meta name="keywords" content="XML, editor, open source, TEI" />
<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="shortcut icon" type="images/x-icon" href="favicon.ico" />
<script type="text/javascript" src=
"./jquery/js/jquery-1.4.4.min.js">
</script>
<script type="text/javascript" src=
"./jquery/js/jquery-ui-1.8.7.custom.min.js">
</script>
<script type="text/javascript" src="./getPath.js">
</script>
<script type="text/javascript" src="./rangy-core.js">
</script>
<script type="text/javascript" src="./selectionsaverestore.js">
</script>
<script type="text/javascript" src="./textSelection.js">
</script>
<script type="text/javascript" src="./contextHelp.js">
</script>
<script type="text/javascript" src="./underscore-min.js">
</script>
<script type="text/javascript" src="./AutoSuggest.js">
</script>
<script type="text/javascript" src="./fixMarkup.js">
</script>
<script type="text/javascript" src="./xmlcheck.js">
</script>
<style type="text/css">
.tag {
color: blue;
}
.hidden {
display: block;
}
#autoSuggest {
overflow: auto;
height: 100px;
width: 200px;
font-size: small;
border: thin solid red;
display: none;
list-style: none;
padding: 3px;
background-color:#666;
}
.autoSugList {
list-style: none;
padding: 0;
margin: 0;
}
.autoSugList.li {
left: 0px;
}
.SelectedAutoSuggestItem {
background-color: cyan;
}
#contentWrapper{
border: thin solid black;
width: 700px;
height: 510px;
overflow: auto;
}
</style>
<script type="text/javascript">
mode = "plain";
tagMode = false;
typingTagName = false;
typingAttr = false;
function textPasted(){
// The contents of div#texted have just changed
// due to a paste action. Auto format.
curContents = $("#texted").html();
//fixMarkup should only modify areas that dont correctly wrap spans around tags and change < and > to html entities
curContents = fixMarkup(curContents);
$("#texted").html(curContents);
}
$(document).ready(function(){
// texteles = _.uniq(contextHelp.text.elements);
var texteles = ['TEI'];
asug = new AutoSuggest();
ts = new TextSelector();
$("body").keypress(function(e){
// $("#quack").html(e.charCode + " / " + e.keyCode);
if (asug.menuOpen) {
switch (e.keyCode) {
case 27:
asug.hideSuggest();
break;
case 40:
asug.menuDown();
e.preventDefault();
break;
case 38:
// up cursor
asug.menuUp();
e.preventDefault();
break;
case 13:
var txt = asug.getCurrent().substring(asug.typed.length);
// asug.typed = asug.getCurrent();
mypos = rangy.getSelection();
newPos = rangy.createRange();
if (mypos.focusNode.nodeType == 3) {
fon = mypos.focusNode.parentNode;
oldText = $(fon).html();
newText = oldText.toString() + txt;
asug.hideSuggest();
$(fon).html(newText);
newPos = rangy.createRange();
newPos.selectNodeContents(fon);
mypos = rangy.getSelection();
mypos.setSingleRange(newPos);
mypos.collapseToEnd();
}
else {
txt = "<span class='tag'>"+txt+"</span>";
//^ remove this once convert
document.execCommand("insertHTML", false, txt);
// invoke convert text at this point
}
e.preventDefault();
break;
}
}
if (mode == "plain") {
switch (e.charCode) {
case 60:
// <
XMLCheck.parseElementContentsToCursor("#texted");
document.execCommand("insertHTML", false, "<span id='activeTag' class='tag'><<\/span>");
mode = "typingTagName";
if (XMLCheck.current.length == 0) {
asug.setPossible(['TEI']);
}
else {
var curTag = XMLCheck.current.toString();
//alert(contextHelp['TEI'].elements);
//alert(curTag+" : "+contextHelp[curTag].elements);
possTags = _.uniq(contextHelp[curTag].elements);
if (contextHelp[""+XMLCheck.current]) {
asug.setPossible(possTags);
asug.typed="";
}
}
// asug.setPossible(texteles);
list = asug.narrowPossible();
asug.showSuggest(list, "activeTag");
e.preventDefault();
break;
}
}
else {
// Within a tag
if (mode == "typingTagName") {
if (e.keyCode == 8) {
// delete
asug.typed = asug.typed.substring(0, asug.typed.length - 1);
asug.backPossible();
}
else {
if (e.charCode == 32) {
mode = "typingAttr";
atts = _.uniq(contextHelp.text.attributes);
asug.setPossible(atts);
list = asug.narrowPossible();
asug.showSuggest(list, "activeTag");
}
else {
if (e.charCode > 0) {
asug.typed = asug.typed + String.fromCharCode(e.charCode);
asug.showSuggest(asug.narrowPossible(), "activeTag");
}
}
//asug.showSuggest(asug.narrowPossible(), "activeTag");
}
}
else
if (mode == "typingAttr") {
}
if (e.charCode == 62) {
// >
mode = "plain";
mypos = rangy.getSelection();
newPos = rangy.createRange();
fon = mypos.focusNode;
if (fon.nodeType == 3) {
fon = fon.parentNode;
}
newText = $(fon).html() + ">";
$(fon).html(newText);
newPos.selectNode(fon);
mypos = rangy.getSelection();
mypos.setSingleRange(newPos);
mypos.collapseToEnd();
asug.typed="";
tagName = newText.substring(4,newText.length-4);
if (tagName.indexOf(" ")>0){
tagName = tagName.substring(0,tagName.indexOf(" "));
}
tagName = "</"+tagName+">"
asug.setPossible([""+tagName]);
list = asug.narrowPossible();
asug.showSuggest(list, "activeTag");
$("#activeTag").attr("id", "");
// asug.hideSuggest();
e.preventDefault();
}
}
});
$("#cool").mousedown(function(e){
textPasted();
});
});
function showMessage(data){
// $("#Messages").html(data);
}
</script>
</head>
<body>
<div id="wrapper">
<h1>Angles</h1>
<h2>A Community-Built XML Editor</h2>
<p>Edit the XML below.</p>
<div id="editor">
<div id="toolbar">
<a href="#">File</a> | <a href="#">Edit</a> | <a href="#">Help</a>
</div>
<div id="editor-guts">
<div id="contentWrapper">
<div id="texted" contenteditable="true" width="500" height="500">
<span class="tag"><TEI
xmlns="http://www.tei-c.org/ns/1.0"></span><br>
<span class="tag"><teiHeader></span><br>
<span class="tag"><fileDesc></span> <br>
<span class="tag"><titleStmt></span><br>
<span class="tag"><title></span>
Title<span class="tag"></title></span><br>
<span class="tag"></titleStmt></span><br>
<span class="tag"><publicationStmt></span><br>
<span class="tag"><p></span>Publication
Information<span class="tag"></p></span><br>
<span class="tag"></publicationStmt></span><br>
<span class="tag"><sourceDesc></span> <br>
<span class="tag"><p></span>Information about the source<span class="tag"></p></span><br>
<span class="tag"></sourceDesc></span><br>
<span class="tag"></fileDesc></span><br>
<span class="tag"></teiHeader></span><br>
<span class="tag"><text></span><br>
<span class="tag"><body></span><br>
<span class="tag"><p></span>So<span id="activeTag" class="tag"></span>me text here.<span class="tag"></p></span><br>
<span class="tag"></body></span><br>
<span class="tag"></text></span><br>
<span class="tag"></TEI></span>
</div>
</div>
<div id="autoSuggest">
</div>
</div>
</div>
</div>
</body>
</html>