-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.html
executable file
·193 lines (168 loc) · 7.92 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
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="styles/isibheqe.css">
<script type="text/javascript" src="lib/jquery-2.1.4.js" ></script>
<script type="text/javascript" src="lib/isibheqe-glyphs.js" ></script>
<script type="text/javascript" src="lib/isibheqe-rendering.js" ></script>
<script type="text/javascript" src="lib/key-mappings.js" ></script>
<script type="text/javascript">
var UNIT = 3;
var canvasWidth = 800;
var canvasHeight = 400;
var EXPORT_SCALE = 4;
$(function() {
var screenContext = new Context(UNIT, canvasWidth, canvasHeight);
var refresh = function(context) {
$("#isibheqe-frame").children().replaceWith(context.render());
$("#isibheqe-serialization").val(context.serialize());
};
$(document).keypress(function(event){
if($("#isibheqe-serialization").is(":focus")){
return;
}
var key;
if(event.ctrlKey && event.which === 26) {
screenContext.undo();
refresh(screenContext);
event.preventDefault();
return;
}
if (event.which === 13) {
key = "enter";
}
else if (event.which === 32) {
key = "space";
event.preventDefault();
} else {
var input = String.fromCharCode(event.charCode);
if (keyMapping[input] !== undefined) {
key = keyMapping[input];
} else {
return;
}
}
screenContext.addLetter(key);
refresh(screenContext);
});
$("#isibheqe-sync").click(function(event){
screenContext.deserialize($("#isibheqe-serialization").val());
refresh(screenContext);
});
$("#isibheqe-undo").click(function(event){
screenContext.undo();
refresh(screenContext);
});
// http://stackoverflow.com/questions/12796513/html5-canvas-to-png-file
$("#isibheqe-export").click(function(event){
var link = document.createElement("a");
var exportContext = new Context(UNIT * EXPORT_SCALE, canvasWidth * EXPORT_SCALE, canvasHeight * EXPORT_SCALE);
exportContext.deserialize($("#isibheqe-serialization").val());
exportContext.lineWidth = exportContext.lineWidth * 1.0;
var image = exportContext.render();
var dt = image.toDataURL('image/png');
/* Change MIME type to trick the browser to downlaod the file instead of displaying it */
dt = dt.replace(/^data:image\/[^;]*/, 'data:application/octet-stream');
link.href = dt;
link.innerHTML = "Download";
link.download = "canvas.png";
$("#isibheqe-download-placeholder").html(link);
});
var factory = new GlyphFactory(3);
/* Generate keyboard dynamicaly
var vowelKeyboard = $("#isibheqe-vowels");
for (var i = 0; i < VOWELS.length; i++) {
var vowel = VOWELS[i];
var key = document.createElement("div");
key.className = "isibheqe-letter";
$(key).attr("x-data-isibheqe", vowel);
vowelKeyboard.append(key);
}
var consonantKeyboard = $("#isibheqe-consonants");
for (var i = 0; i < CONSONANTS.length; i++) {
var consonant = CONSONANTS[i];
var key = document.createElement("div");
key.className = "isibheqe-letter";
$(key).attr("x-data-isibheqe", consonant);
consonantKeyboard.append(key);
}
var syllabicConsonantsKeyboard = $("#isibheqe-syllabic-consonants");
for (var i = 0; i < SYLLABIC_CONSONANTS.length; i++) {
var consonant = SYLLABIC_CONSONANTS[i];
var key = document.createElement("div");
key.className = "isibheqe-letter";
$(key).attr("x-data-isibheqe", consonant);
vowelKeyboard.append(key);
}
*/
$("div.isibheqe-letter").each(function(index, button){
var canvas = document.createElement("canvas");
canvas.width = 48;
canvas.height = 80;
var context = canvas.getContext("2d");
var keyTarget = makeTarget(context);
var letter = $(button).attr("x-data-isibheqe");
if(VOWELS.indexOf(letter) >= 0) {
var glyph = factory.newVowel(letter, new Point(0,0));
glyph.renderOn(keyTarget);
button.appendChild(canvas);
} else if (CONSONANTS.indexOf(letter) >= 0) {
var glyph = factory.newVowel("i", new Point(0,0));
if (letter === "l̩") {
glyph.addConsonant("l");
}
if (letter === "r̩") {
glyph.addConsonant("r");
}
glyph.addConsonant(letter);
glyph.renderOn(keyTarget);
button.appendChild(canvas);
} else if (SYLLABIC_CONSONANTS.indexOf(letter) >= 0) {
var glyph = factory.newSyllabicConsonant(letter, new Point(0,0));
glyph.renderOn(keyTarget);
button.appendChild(canvas);
}
});
$("div.isibheqe-letter").click(function(event){
var div = $(event.currentTarget);
var thisKey = div.attr("x-data-isibheqe");
screenContext.addLetter(thisKey);
refresh(screenContext);
});
});
</script>
</head>
</body>
<div class="isibheqe-display">
<div id="isibheqe-frame" class="isibheqe-frame">
<canvas id="isibheqe-canvas" width="800" height="400"></canvas>
</div>
<div id="isibheqe-text-frame">
<p>
<textarea id="isibheqe-serialization" width="240"></textarea>
<button id="isibheqe-sync"> << Sync </button>
</p>
<p>
<button id="isibheqe-export"> Export hi-res </button>
<div id="isibheqe-download-placeholder"></div>
</p>
<p>
<button id="isibheqe-undo"> Undo </button>
</p>
</div>
<div>
<div class="new-line" ></div>
<div class="isibheqe-input">
<div class="isibheqe-keyboard-container">
<div id="isibheqe-vowels" class="isibheqe-keyboard">
<div class="isibheqe-letter" x-data-isibheqe="i"></div><div class="isibheqe-letter" x-data-isibheqe="a"></div><div class="isibheqe-letter" x-data-isibheqe="u"></div><div class="isibheqe-letter" x-data-isibheqe="e"></div><div class="isibheqe-letter" x-data-isibheqe="o"></div><div class="isibheqe-letter" x-data-isibheqe="ɔ"></div><div class="isibheqe-letter" x-data-isibheqe="ɛ"></div><div class="isibheqe-letter" x-data-isibheqe="m̩"></div><div class="isibheqe-letter" x-data-isibheqe="n̩"></div><div class="isibheqe-letter" x-data-isibheqe="ŋ̩"></div></div>
<div class="new-line"></div>
<div id="isibheqe-consonants" class="isibheqe-keyboard">
<div class="isibheqe-letter" x-data-isibheqe="-"></div><div class="isibheqe-letter" x-data-isibheqe="•"></div><div class="isibheqe-letter" x-data-isibheqe="°"></div><div class="isibheqe-letter" x-data-isibheqe="~"></div><div class="isibheqe-letter" x-data-isibheqe="t"></div><div class="isibheqe-letter" x-data-isibheqe="p"></div><div class="isibheqe-letter" x-data-isibheqe="t̪"></div><div class="isibheqe-letter" x-data-isibheqe="c"></div><div class="isibheqe-letter" x-data-isibheqe="k"></div><div class="isibheqe-letter" x-data-isibheqe="ɸ"></div><div class="isibheqe-letter" x-data-isibheqe="f"></div><div class="isibheqe-letter" x-data-isibheqe="s"></div><div class="isibheqe-letter" x-data-isibheqe="ʃ"></div><div class="isibheqe-letter" x-data-isibheqe="ȿ"></div><div class="isibheqe-letter" x-data-isibheqe="x"></div><div class="isibheqe-letter" x-data-isibheqe="h"></div><div class="isibheqe-letter" x-data-isibheqe="ɬ"></div><div class="isibheqe-letter" x-data-isibheqe="w"></div><div class="isibheqe-letter" x-data-isibheqe="j"></div><div class="isibheqe-letter" x-data-isibheqe="l"></div><div class="isibheqe-letter" x-data-isibheqe="r"></div><div class="isibheqe-letter" x-data-isibheqe="ɽ"></div><div class="isibheqe-letter" x-data-isibheqe="|"></div><div class="isibheqe-letter" x-data-isibheqe="!"></div><div class="isibheqe-letter" x-data-isibheqe="||"></div><div class="isibheqe-letter" x-data-isibheqe="n̪"></div><div class="isibheqe-letter" x-data-isibheqe="n"></div><div class="isibheqe-letter" x-data-isibheqe="ɲ"></div><div class="isibheqe-letter" x-data-isibheqe="ŋ"></div><div class="isibheqe-letter" x-data-isibheqe="l̩"></div><div class="isibheqe-letter" x-data-isibheqe="r̩"></div></div>
<div class="new-line"></div>
<div id="isibheqe-syllabic-consonants" class="isibheqe-keyboard">
</div>
</div>
</div>
</body>
</html>