-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
115 lines (109 loc) · 3.05 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="https://unpkg.com/mvp.css" />
<title>Universal Element Accept</title>
</head>
<body>
<style>
main {
max-width: 500px;
margin: 0 auto;
text-align: center;
}
section {
display: block;
}
select {
display: inline;
font-size: 0.85em;
}
</style>
<header>
<h1>Universal Element Accept</h1>
<p>Universal way to accept HTML Elements</p>
<a href="https://github.com/CompactJS/uea">Github</a>
</header>
<main>
<section>
<h2>Example HTML:</h2>
<code id="code_1"></code>
<br />
<h2>Function call:</h2>
accept(
<select id="input"></select>
);
</section>
<h2>Returns:</h2>
<p>
<code id="code_2"></code>
</p>
</main>
<div style="display: none">
<button class="class-select">Test1</button>
<button class="class-select">Test2</button>
<button id="test1">Test3</button>
</div>
<script type="module">
import { accept } from './dist/index.module.js';
const options = [
{
text: "document.getElementById('test1')",
fun: () => document.getElementById('test1'),
},
{
text: "'.class-select'",
fun: () => '.class-select',
},
{
text: "document.querySelectorAll('.class-select')",
fun: () => document.querySelectorAll('.class-select'),
},
{
text: "document.querySelector('#test1')",
fun: () => document.querySelector('#test1'),
},
{
text: 'button:first-child',
fun: () => 'button:first-child',
},
{
text: "'*'",
fun: () => '*',
},
{
text: "document.getElementsByTagName('button')",
fun: () => document.getElementsByTagName('button'),
},
{
text: "[document.body, document.getElementById('test1')]",
fun: () => [document.body, document.getElementById('test1')],
},
];
document.getElementById(
'code_1'
).innerText = `<button class="class-select">Test1</button>
<button class="class-select">Test2</button>
<button id="test1">Test3</button>`;
const output = document.getElementById('code_2');
const input = document.getElementById('input');
options.forEach((o, i) => {
const option = document.createElement('option');
option.value = i;
option.innerHTML = o.text;
input.appendChild(option);
});
const test = (fun) => {
const res = accept(fun());
output.innerHTML = `[ ${res} ]`;
console.log(res);
};
input.addEventListener('change', function onChange(e) {
test(options[e.target.value].fun);
});
test(options[0].fun);
</script>
</body>
</html>