forked from DeutscheSoft/aux-widgets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
examples.html
260 lines (226 loc) · 7.14 KB
/
examples.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>AUX Examples</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script type=module src="src/index.js"></script>
<script type=module>
const examples = [
"Bitstring",
"Button",
"Buttons",
"Chart",
"Clock",
"ColorPicker",
"ColorPickerDialog",
"ComboBox",
"Compressor",
"ConfirmButton",
"Crossover",
"Dialog",
"Dynamics",
"Equalizer",
"Expander",
"Fader",
"FileSelect",
"FrequencyResponse",
"Gate",
"Gauge",
"Knob",
"LevelMeter",
"Limiter",
"Marquee",
"Meter",
"MultiMeter",
"Navigation",
"Pager",
"Pages",
"Panorama",
"PhaseMeter",
"ProgressBar",
"Reverb",
"Scale",
"Scroller",
"Select",
"Slider",
"Spread",
"State",
"Toggle",
"Value",
"ValueButton",
"ValueKnob",
];
import { HTML } from './src/utils/dom.js';
function isint(v) {
return typeof v !== "undefined" && parseInt(v).toString() === v.toString();
}
async function loadExample(widget) {
var file = widget + ".html";
const header = document.createElement("h3");
header.innerHTML = widget;
const cont = document.createElement('aux-container');
const res = await window.fetch('examples/' + file);
cont.appendChild(HTML(await res.text()));
const scripts = cont.querySelectorAll('script');
return (root) => {
root.appendChild(header);
root.appendChild(cont);
scripts.forEach((script) => {
eval(script.innerText);
});
window.dispatchEvent(new UIEvent('resize'));
};
}
function decodeHash()
{
const atoms = window.location.hash.substr(1).split(",");
let widgets = [];
let scroll = 0;
let all = false;
for (var i = 0; i < atoms.length; i++) {
var a = atoms[i];
if (a === "*") {
widgets = examples;
all = true;
}
else if (!all && examples.indexOf(a) >= 0)
widgets.push(a);
else if (isint(a))
scroll = parseInt(a);
}
return [ all, scroll, widgets ];
}
function updateHashSilent(hash)
{
window.location.hash = hash;
}
function updateScroll()
{
const [ all, scroll, widgets ] = decodeHash();
const root = document.querySelector('aux-root');
let s = parseInt(root.scrollTop);
var h = "#" + s + ",";
if (all)
h += "*";
else
h += widgets.join(",");
updateHashSilent(h);
}
function buildListEntry (item, name, is_active) {
var li = document.createElement("li");
li.innerHTML = name ? name : item;
li.addEventListener("click", function (e) {
window.location.hash = item;
});
if (is_active)
{
const toggle_active = (current) => {
const v = is_active(current);
li.classList.toggle('active', v);
if (v)
li.scrollIntoView({ block: "nearest" });
};
current_subscribers.push(toggle_active);
}
return li;
}
const current_subscribers = [];
function cmp(name)
{
return function(v) { return name === v; };
}
function buildNavigation (list) {
var ul = document.createElement("ul");
ul.setAttribute("id", "navigation");
const home = buildListEntry("", "Home", current => current === void(0));
ul.appendChild(home);
ul.appendChild(buildListEntry("*", "All", current => current === null));
for (var i = 0; i < list.length; i++) {
const li = buildListEntry(list[i], "", cmp(list[i]))
ul.appendChild(li);
}
return ul;
}
let last_info = null;
function loadExamples()
{
const root = document.querySelector('aux-root');
const [ all, scroll, widgets ] = decodeHash();
if (last_info)
{
if (last_info[0] == all &&
JSON.stringify(last_info[2]) == JSON.stringify(widgets))
return;
}
last_info = [ all, scroll, widgets ];
const introduction = root.querySelector('#introduction');
while (introduction.nextSibling)
introduction.nextSibling.remove();
introduction.style.display = widgets.length ? 'none' : null;
const tasks = widgets.map(loadExample);
Promise.all(tasks).then((cbs) => {
cbs.forEach((cb) => cb(root));
setTimeout(function () {
root.scrollTo(0, scroll);
root.addEventListener("scroll", function () {
updateScroll(root.scrollTop);
});
document.querySelectorAll('.aux-widget').forEach((node) => {
if (!node.tagName.startsWith('AUX')) return;
node.addEventListener('dblclick', (ev) => {
console.log(node.tagName);
node.constructor.observedAttributes.forEach((name) => {
if (!node.hasAttribute(name)) return;
const widget = node.auxWidget;
console.log('%s %o %o', name, node.getAttribute(name), widget.get(name));
});
ev.stopPropagation();
});
});
}, 100);
});
const current = widgets.length === examples.length ? null : widgets[0];
current_subscribers.forEach((cb) => cb(current));
}
window.addEventListener('hashchange', function() {
loadExamples();
});
window.addEventListener('load', function() {
const ul = buildNavigation(examples);
document.body.appendChild(ul);
loadExamples();
});
</script>
<link rel="stylesheet" id=stylesheet href="styles/default.css" />
<link rel="stylesheet" id=stylesheet href="examples/styles.css" />
<style>
</style>
</head>
<body>
<aux-root>
<div id=introduction>
<h1>AUX Examples</h1>
<img src="aux_logo_4c.svg" id=logo>
<p>
This is a collection of AUX widgets in different configurations
for development, demonstration and guideline purposes. to get
an insight into structure and relation, browsers with developer
tools (try <code>F12</code>) are recommended.
</p>
<p>
Select a single widget from the menu to the right or click "All"
to see all examples on one page (might slow down your computer).
</p>
<p>
The full documentation can be found online at
<a href="http://docs.deuso.de/AUX">docs.deuso.de/AUX</a>.
</p>
<p>
AUX AudioWidgets is a product of
<a href="https://deuso.de">DeusO GmbH</a>.
</p>
</div>
</aux-root>
</body>
</html>