-
Notifications
You must be signed in to change notification settings - Fork 4
/
websocket_text_custom_resources.html
107 lines (92 loc) · 3.13 KB
/
websocket_text_custom_resources.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="mobile-web-app-capable" content="yes" />
<meta name="HandheldFriendly" content="true" />
<title>Custom pre-loaded resources</title>
<link rel="stylesheet" href="../assets/style/reset.css" />
<link rel="stylesheet" href="../assets/style/components.css" />
<link rel="stylesheet" href="../assets/style/examples.css" />
<script type="text/javascript" src="../../dist/iink.min.js"></script>
<style>
#editor {
height: calc(100vh - 166px);
}
@media only screen and (max-width: 608px) {
#editor {
height: calc(100vh - 123px);
}
}
@media only screen and (max-width: 504px) {
#editor {
height: calc(100vh - 140px);
}
}
</style>
</head>
<body>
<nav class="flex-container wrap gap between">
<div class="flex-container wrap gap">
<button id="undo" class="nav-btn btn-fab-mini btn-lightBlue" disabled>
<img src="../assets/img/undo.svg" />
</button>
<button id="redo" class="nav-btn btn-fab-mini btn-lightBlue" disabled>
<img src="../assets/img/redo.svg" />
</button>
</div>
<p>Custom pre-loaded resources: <b>Dinosaurs</b>. Try to write some dinosaurs name!</p>
</nav>
<div id="editor" touch-action="none"></div>
<script>
const editorElement = document.getElementById("editor");
const undoElement = document.getElementById("undo");
const redoElement = document.getElementById("redo");
let editor;
async function loadEditor() {
const res = await fetch("../server-configuration.json");
const conf = await res.json();
const options = {
configuration: {
server: {
...conf,
protocol: "WEBSOCKET"
},
recognition: {
text: {
addLKText: true,
customResources: ["dinosaur"]
}
}
}
};
/**
* Instanciate editor
* @param {Element} The DOM element to attach the ink paper
* @param {Object} The Editor parameters
*/
editor = new iink.Editor(editorElement, options);
/**
* async initialize editor behaviors
*/
await editor.initialize();
editorElement.addEventListener("changed", (event) => {
undoElement.disabled = !event.detail.canUndo;
redoElement.disabled = !event.detail.canRedo;
});
undoElement.addEventListener("click", () => {
editorElement.editor.undo();
});
redoElement.addEventListener("click", () => {
editorElement.editor.redo();
});
window.addEventListener("resize", () => {
editorElement.editor.resize();
});
};
loadEditor().catch(error => console.error(error));
</script>
</body>
</html>