-
Notifications
You must be signed in to change notification settings - Fork 0
/
embed.html
115 lines (115 loc) · 5.34 KB
/
embed.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HDLwave embeddable</title>
<link href="wavedraw/wavedraw.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@300&display=swap" rel="stylesheet">
<style>
:root {
--text-color: #eee;
--bg-color: #222;
}
[colorTheme="light"] {
--text-color: #000;
--bg-color: #ddd;
}
p {
font-family: 'Open Sans';
font-size: 16px;
color: var(--text-color);
}
body {
background: var(--bg-color);
}
#editor {
width: 100%;
height: 40vh;
margin-bottom: 10px;
border: 1px solid #999;
}
#render {
background: transparent;
border-radius: 5px;
border: 1px solid #bbb;
width: 5vw;
height: 4vh;
color: var(--text-color);
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.11/ace.js"></script>
</head>
<body>
<div id="editor"></div>
<div style="display: flex; flex-direction: row; justify-content: space-evenly; width: 75%; height: max-content">
<button id="render" onclick="eval(window.editor.getValue())">Render</button>
<input type='text' name='q4_a'>
<input type='text' name='q4_b'>
<input type='text' name='q4_c'>
<input type='text' name='q4_d'>
</div>
<div style="width: 100%; margin-top: 10px; border-top: 1px solid #999; height: 5vh;"></div>
<div id="wavedraw1"></div>
<div id="wavedraw2"></div>
</body>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="wavedraw/wavedraw.js"></script>
<script>
function toggleTheme (opt=-1) {
if (opt == -1)
document.documentElement.setAttribute ('colorTheme', document.documentElement.getAttribute ('colorTheme') == 'dark' ? 'light' : 'dark')
else if (opt == 0)
document.documentElement.setAttribute ('colorTheme', 'dark')
else if (opt == 1)
document.documentElement.setAttribute ('colorTheme', 'light')
editor.setTheme(document.documentElement.getAttribute ("colorTheme") == "dark" ? "ace/theme/chaos" : "ace/theme/chrome");
}
window.onload = () => {
document.documentElement.setAttribute ("colorTheme", "dark") // well... it's just an demo thing
setTimeout (() => {document.body.style.opacity = '1'}, 200)
window.editor = ace.edit("editor");
editor.setTheme(document.documentElement.getAttribute ("colorTheme") == "dark" ? "ace/theme/chaos" : "ace/theme/chrome");
editor.setShowPrintMargin(false);
editor.session.setMode("ace/mode/javascript");
editor.setValue (
"var waveform1 = new WaveDraw (document.getElementById ('wavedraw1'), {\n" +
" // 'resolution': 20,\n" +
" 'fixed': {'a': '01101001zzzxx101010', 'b': '1110101010xxx101010'}, // keys are signals, values are bitstreams\n" +
" 'editable': {'c': '[name=\"q4_a\"]', 'd': '[name=\"q4_b\"]'}, // keys are signals, values are names of field elements into which bitstream will be written upon bit toggling\n" +
" 'timescale': '5ns', // specify the timescale of the waveform - mostly cosmetic\n" +
" 'allowXValues': true, //prevents user from toggling X values\n" +
" 'allowZValues': true, //prevents user from toggling Z values\n" +
" 'modifyLength': false, // this will prevent users from changing the time of the waveform\n" +
" 'disabled': false // prevents modifying the waveforms regardless of type of wave\n" +
"});\n\n" +
"var waveform2 = new WaveDraw (document.getElementById ('wavedraw2'), {\n" +
" // 'resolution': 20,\n" +
" 'fixed': {'a': 'zzz1011111xx0000', 'b': 'ddd101xx1zzz0110'}, // keys are signals, values are bitstreams\n" +
" 'editable': {'c': '[name=\"q4_c\"]', 'd': '[name=\"q4_d\"]'}, // keys are signals, values are names of field elements into which bitstream will be written upon bit toggling\n" +
" 'timescale': '5ns', // specify the timescale of the waveform - mostly cosmetic\n" +
" 'allowXValues': true, //prevents user from toggling X values\n" +
" 'allowZValues': true, //prevents user from toggling Z values\n" +
" 'modifyLength': false, // this will prevent users from changing the time of the waveform\n" +
" 'disabled': false // prevents modifying the waveforms regardless of type of wave\n" +
"});\n", -1
)
$(document).on ('keydown', 'body', (e) => {
if (e.ctrlKey && e.key.match (/^s$/i)) {
e.preventDefault()
eval(window.editor.getValue())
}
else if (e.ctrlKey && e.key.match (/^t$/i)) {
e.preventDefault()
toggleTheme()
}
})
$(document).on ('touchstart', 'body', (e) => {
console.log ('touchstart')
})
$(document).on ('touchmove', 'body', (e) => {
console.log ('touchmove')
})
}
</script>
</html>