-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspacer-gif.js
57 lines (49 loc) · 1.17 KB
/
spacer-gif.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const template = document.createElement('template');
template.innerHTML = `
<style>
:host {
display: inline-block;
}
</style>
`;
class SpacerGif extends HTMLElement {
constructor() {
super();
this._shadowRoot = this.attachShadow({ 'mode': 'open' });
this._shadowRoot.appendChild(template.content.cloneNode(true));
}
connectedCallback() {
if(!this.hasAttribute('height')) {
this.style.height = "1px";
}
else {
this.style.height = this._height;
}
if(!this.hasAttribute('width')) {
this.style.width = "1px";
}
else {
this.style.width = this._width;
}
if(this.hasAttribute('bgcolor')) {
this.style.backgroundColor = this._bgcolor;
}
}
static get observedAttributes() {
return ['height', 'width', 'bgcolor'];
}
attributeChangedCallback(name, oldValue, newValue) {
switch(name){
case 'height':
this._height = newValue + "px";
break;
case 'width':
this._width = newValue + "px";
break;
case 'bgcolor':
this._bgcolor = newValue;
break;
}
}
}
window.customElements.define('spacer-gif', SpacerGif);