Skip to content

Commit 3dcddd1

Browse files
committed
Update test HTML page to iterate through any attribute given in the query string
1 parent f94d5d3 commit 3dcddd1

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

src/web-component.html

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
</body>
1111

1212
<script>
13-
let queryParams = new URLSearchParams(window.location.search)
1413
document.addEventListener('DOMContentLoaded', (e) => {
1514
const webComp = document.createElement('editor-wc')
16-
webComp.setAttribute('code', queryParams.get('code') || '')
17-
const enableSenseHat = queryParams.get('sense_hat_always_enabled')
18-
if (enableSenseHat && enableSenseHat != 'false') {
19-
webComp.setAttribute('sense_hat_always_enabled', true)
20-
}
15+
const queryParams = new URLSearchParams(window.location.search)
16+
17+
// Pre-set the code attribute with an empty string.
18+
webComp.setAttribute('code', '')
19+
// Set any attribute you like in the query string, including class, style, hidden, script, etc.
20+
queryParams.forEach((value, key) => { webComp.setAttribute(key, value) })
2121

2222
// subscribe to the 'codeChanged' custom event which is pushed by the project react component
2323
webComp.addEventListener('codeChanged', function(e) {
@@ -31,7 +31,8 @@
3131
console.log(e.detail)
3232
document.getElementById("results").innerText = JSON.stringify(e.detail)
3333
})
34-
const body = document.getElementsByTagName('body')[0].prepend(webComp)
34+
35+
document.getElementsByTagName('body')[0].prepend(webComp)
3536
});
3637
</script>
3738
</html>

0 commit comments

Comments
 (0)