-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
91 lines (72 loc) · 2.87 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Alegrify UI</title>
<link id="stylesheet" rel="stylesheet" href="./alegrify-ui.css" />
</head>
<body class="alegrify-body">
<main id="page-content" class="alegrify-main"></main>
<footer class="alegrify-footer">
<label for="theme" class="alegrify-label">Theme:</label>
<select class="alegrify-select alegrify-select--inline" name="theme" id="theme">
<option value="default">Default</option>
<option value="dark">Dark</option>
<option value="article">Article</option>
<option value="article-dark">Article (Dark)</option>
</select>
</footer>
<script src="node_modules/markdown-it/dist/markdown-it.min.js"></script>
<script>
const elements = {
pageContent: document.getElementById('page-content')
}
initIndex();
document.querySelector('#theme').addEventListener('change', handleThemeChange);
function initIndex() {
loadPage(`./docs/index.html`);
}
async function loadPage(path) {
const response = await fetch(path);
const htmlResult = await response.text();
elements.pageContent.innerHTML = htmlResult;
elements.pageContent.querySelectorAll('a').forEach(replaceLink);
runOtherThings();
}
function replaceLink(aTag) {
aTag.addEventListener('click', handleLinkClick);
}
function handleLinkClick(clickEvent) {
const href = clickEvent.target.href.replace(window.location.href, '');
clickEvent.preventDefault();
loadPage(`./docs/${href}`);
}
/* Just for the sake of showing an example */
function runOtherThings() {
const dialogControl = document.querySelector('[aria-controls="dialog__001"]');
// DIALOG
dialogControl && dialogControl.addEventListener('click', function () {
const dialog = document.getElementById('dialog__001');
if (!dialog.hasAttribute('open')) {
dialog.setAttribute('open', 'open');
}
dialog.addEventListener('click', function() {
dialog.removeAttribute('open');
});
});
}
function handleThemeChange(changeEvent) {
var theme = changeEvent.target.value;
var href = theme === 'default' ? 'alegrify-ui.css' : './alegrify-ui--' + theme + '.css';
document.getElementById('stylesheet').setAttribute('href', href);
}
</script>
<style>
code {
font-family: inherit;
}
</style>
</body>
</html>