Skip to content

Commit 0681cb2

Browse files
committed
Better fake fetch for demo
1 parent c1c8cc2 commit 0681cb2

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

examples/index.html

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,46 @@
33
<head>
44
<meta charset="utf-8">
55
<title>remote-input demo</title>
6+
<style>
7+
marquee, textarea, input { width: 20rem; }
8+
remote-input, textarea { display: block; }
9+
</style>
10+
<script>
11+
function fakeFetch(url) {
12+
const urlObj = new URL(url)
13+
let html = ''
14+
if (url.pathname === '/results') {
15+
const doc = document.createElement('div')
16+
doc.innerHTML = `<li>Hubot</li><li>BB-8</li><li>Wall-E</li><li>Bender</li>`
17+
const q = url.searchParams.get('q')
18+
for (const el of doc.querySelectorAll('li')) {
19+
if (q !== '' && !el.textContent.toLowerCase().match(q.toLowerCase())) el.remove()
20+
}
21+
html = doc.innerHTML
22+
} else if (url.pathname === '/marquee') {
23+
html = `<marquee>${url.searchParams.get('q') || 'blank'}</marquee>`
24+
}
25+
const promiseHTML = new Promise(resolve => resolve(html))
26+
return new Promise(resolve => resolve({text: () => promiseHTML}))
27+
}
28+
window.fetch = fakeFetch
29+
</script>
630
</head>
731
<body>
8-
<remote-input aria-owns="results" src="/examples/results.html">
9-
<label>Search robots <input type="text"></label>
32+
<remote-input aria-owns="marquee-preview" src="/marquee">
33+
<label>Marquee preview <textarea autofocus>🐈🐈🐈🐈🐈</textarea></label>
1034
</remote-input>
11-
<ol id="results"></ol>
35+
<div id="marquee-preview"></div>
36+
37+
<remote-input aria-owns="results" src="/results">
38+
<label>Search robots<br><input type="text"></label>
39+
</remote-input>
40+
<ul id="results"></ul>
1241

1342
<!-- GitHub Pages development script, uncomment when running example locally and comment out the production one -->
1443
<!-- <script src="../dist/index.umd.js"></script> -->
1544

1645
<!-- GitHub Pages demo script -->
17-
<script src="https://unpkg.com/@github/remote-input-element@latest/dist/index.umd.js"></script></body>
46+
<script src="https://unpkg.com/@github/remote-input-element@latest/dist/index.umd.js"></script>
47+
</body>
1848
</html>

examples/markdown.html

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/results.html

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)