Skip to content

Commit 6feb0cc

Browse files
keithamuskoddsson
andauthored
Move polyfill code to bottom of page, clean up to run data-exports instead of data-code
Co-authored-by: Kristján Oddsson <[email protected]>
1 parent 9bf803f commit 6feb0cc

File tree

1 file changed

+43
-35
lines changed

1 file changed

+43
-35
lines changed

docs/index.html

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -46,41 +46,6 @@
4646
background-color: grey;
4747
}
4848
</style>
49-
<script type="module" defer>
50-
import {isSupported, isPolyfilled, baseSupport, apply, polyfills} from '../lib/index.js'
51-
// import {isSupported, isPolyfilled, apply, poyfills} from 'https://unpkg.com/@github/browser-support@latest/lib/index.js'
52-
for(const el of document.querySelectorAll('[data-code]')) {
53-
let supported = false
54-
const code = el.getAttribute('data-code')
55-
try {
56-
if (code === "isSupported()") {
57-
supported = isSupported()
58-
} else if (code === "baseSupport") {
59-
supported = baseSupport
60-
} else if (code === "isPolyfilled()") {
61-
supported = isPolyfilled()
62-
} else {
63-
supported = eval(`${code}`)
64-
}
65-
} catch (e) {
66-
67-
}
68-
Promise.resolve(supported).then((value) => {
69-
el.setAttribute('data-supported', Boolean(value))
70-
if (!value && el.hasAttribute('data-transpiled')) {
71-
if (!value) el.textContent = '**'
72-
}
73-
})
74-
}
75-
for(const el of document.querySelectorAll('[data-polyfill]')) {
76-
const name = el.getAttribute('data-polyfill') || ''
77-
if (!(name in polyfills)) continue
78-
Promise.resolve(polyfills[name].isSupported()).then((value) => {
79-
el.setAttribute('data-supported', Boolean(value))
80-
if (!value) el.textContent = '*'
81-
})
82-
}
83-
</script>
8449
</head>
8550
<body>
8651
<table>
@@ -679,6 +644,49 @@
679644
el.setAttribute('data-supported', Boolean(value))
680645
if (!value && el.hasAttribute('data-transpiled')) {
681646
if (!value) el.textContent = '**'
647+
} else if (!value && el.hasAttribute('data-polyfilled')) {
648+
if (!value) el.textContent = '*'
649+
}
650+
})
651+
}
652+
</script>
653+
<script type="module">
654+
import * as support from '../lib/index.js'
655+
// import * as support from 'https://unpkg.com/@github/browser-support@latest/lib/index.js'
656+
const polyfills = support.polyfills
657+
for(const el of document.querySelectorAll('[data-export]')) {
658+
let supported = false
659+
const key = el.getAttribute('data-export')
660+
if (key in support && typeof support[key] === 'function') {
661+
supported = Boolean(support[key]())
662+
} else if (key in support) {
663+
supported = Boolean(support[key])
664+
} else {
665+
supported = false
666+
}
667+
Promise.resolve(supported).then((value) => {
668+
el.setAttribute('data-supported', Boolean(value))
669+
if (!value && el.hasAttribute('data-transpiled')) {
670+
if (!value) el.textContent = '**'
671+
} else if (!value && el.hasAttribute('data-polyfilled')) {
672+
if (!value) el.textContent = '*'
673+
}
674+
})
675+
}
676+
for(const el of document.querySelectorAll('[data-polyfill]')) {
677+
let supported = false
678+
const name = el.getAttribute('data-polyfill') || ''
679+
if (name in polyfills) {
680+
supported = polyfills[name].isSupported()
681+
} else {
682+
supported = false
683+
}
684+
Promise.resolve(supported).then((value) => {
685+
el.setAttribute('data-supported', Boolean(value))
686+
if (!value && el.hasAttribute('data-transpiled')) {
687+
if (!value) el.textContent = '**'
688+
} else if (!value && el.hasAttribute('data-polyfilled')) {
689+
if (!value) el.textContent = '*'
682690
}
683691
})
684692
}

0 commit comments

Comments
 (0)