Skip to content

Commit 0177750

Browse files
committed
refactor: extracting the small code snippets
that could get adapted this way for dynamic content
1 parent 3d616df commit 0177750

File tree

3 files changed

+29
-25
lines changed

3 files changed

+29
-25
lines changed

demo/index.js

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import loadingAttributePolyfill from '../dist/loading-attribute-polyfill.module.js';
2-
31
// Test for dynamically inserted images and iframes
42
let addDynamicContent = (event) => {
53
let divElement = document.createElement('div'),
@@ -35,26 +33,6 @@ document
3533
.querySelector('button.add-dynamic-content')
3634
.addEventListener('click', addDynamicContent);
3735

38-
// See https://html.spec.whatwg.org/multipage/indices.html#element-interfaces
39-
// for the list of other DOM interfaces.
40-
class LoadingImages extends HTMLImageElement {
41-
constructor() {
42-
super(); // Always call super() first in the constructor.
43-
// Call for preparing the sample image element included the latest
44-
loadingAttributePolyfill.prepareElement(this);
45-
}
46-
}
47-
48-
customElements.define('loading-image', LoadingImages, { extends: 'img' });
49-
50-
// See https://html.spec.whatwg.org/multipage/indices.html#element-interfaces
51-
// for the list of other DOM interfaces.
52-
class LoadingIframes extends HTMLIFrameElement {
53-
constructor() {
54-
super(); // Always call super() first in the constructor.
55-
// Call for preparing the sample iframe element included the latest
56-
loadingAttributePolyfill.prepareElement(this);
57-
}
58-
}
59-
60-
customElements.define('loading-iframe', LoadingIframes, { extends: 'iframe' });
36+
// Importing the two files which show how to register these elements as custom elements builtin extends
37+
import 'loading-attribute-polyfill.custom-builtin-extend.image.js';
38+
import 'loading-attribute-polyfill.custom-builtin-extend.iframe.js';
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import loadingAttributePolyfill from '../dist/loading-attribute-polyfill.module.js';
2+
3+
// See https://html.spec.whatwg.org/multipage/indices.html#element-interfaces
4+
// for the list of other DOM interfaces.
5+
class LoadingIframes extends HTMLIFrameElement {
6+
constructor() {
7+
super(); // Always call super() first in the constructor.
8+
// Call for preparing the sample iframe element included the latest dynamically inserted
9+
loadingAttributePolyfill.prepareElement(this);
10+
}
11+
}
12+
13+
customElements.define('loading-iframe', LoadingIframes, { extends: 'iframe' });
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import loadingAttributePolyfill from '../dist/loading-attribute-polyfill.module.js';
2+
3+
// See https://html.spec.whatwg.org/multipage/indices.html#element-interfaces
4+
// for the list of other DOM interfaces.
5+
class LoadingImages extends HTMLImageElement {
6+
constructor() {
7+
super(); // Always call super() first in the constructor.
8+
// Call for preparing the sample image element included the latest dynamically inserted
9+
loadingAttributePolyfill.prepareElement(this);
10+
}
11+
}
12+
13+
customElements.define('loading-image', LoadingImages, { extends: 'img' });

0 commit comments

Comments
 (0)