-
Notifications
You must be signed in to change notification settings - Fork 0
/
enlighted-link.html
38 lines (37 loc) · 1.13 KB
/
enlighted-link.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
<!-- enlighted-link @version: 0.0.1 @license: MIT -->
<script>
customElements.define('enlighted-link', class extends HTMLElement{
static get observedAttributes(){
return [
// content attrs
'href',
'rel',
'media',
'hreflang',
'type',
'sizes',
'title'
]
}
connectedCallback(){
const link = this.link = this.link || document.createElement('link');
for(let attrNo = 0, len = this.attributes.length; attrNo < len; attrNo++){
link.setAttribute(this.attributes[attrNo].name, this.attributes[attrNo].value);
}
document.head.appendChild(link);
// IDEA(tomalec): attach mutation observer on links parent, to detach this in case link is detached.
}
disconnectedCallback(){
this.link.remove();
}
attributeChangedCallback(name, oldVal, newVal){
if(this.link){
if(newVal !== null){
this.link.setAttribute(name, newVal);
} else {
this.link.removeAttribute(name);
}
}
}
});
</script>