-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
33 lines (27 loc) · 874 Bytes
/
index.js
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
import { fetchFromCache, scopeIDs } from "./utils.js"
/**
* @name InlineSVG
* @description A custom element that inlines SVG artwork
* into the page for DOM manipulation and CSS inheritance.
* Automatically makes IDs unique to prevent collisions with
* other inline SVGs or HTML elements on the same page.
*/
export default class InlineSVG extends HTMLElement {
constructor() {
super()
}
connectedCallback() {
const scopedIDs = Boolean(this.attributes["scoped"])
this.setAttribute("data-loading", true)
fetchFromCache(this.attributes.src.value).then((data) => {
// store this in case we need to re-render with different options
this.rawData = data
if (scopedIDs) {
data = scopeIDs(data)
}
// add svg to HTML
this.innerHTML = data
this.setAttribute("data-loading", false)
})
}
}