astro-async-loader 0.0.0 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/AsyncIframe.astro +43 -40
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-async-loader",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.1",
|
|
4
4
|
"description": "Astro components for elements, that load asynchronously, and should have loading indicators.",
|
|
5
5
|
"repository": "https://github.com/jonasfroeller/astro.async.loader",
|
|
6
6
|
"license": "MIT",
|
package/src/AsyncIframe.astro
CHANGED
|
@@ -1,93 +1,96 @@
|
|
|
1
|
-
<div class="async-
|
|
2
|
-
<div class="
|
|
3
|
-
<div class="
|
|
1
|
+
<div class="async-iframe__wrapper">
|
|
2
|
+
<div class="async-iframe__loader-container">
|
|
3
|
+
<div class="async-iframe__loader"></div>
|
|
4
4
|
</div>
|
|
5
5
|
|
|
6
|
-
<div class="
|
|
6
|
+
<div class="async-iframe__container">
|
|
7
7
|
<slot />
|
|
8
8
|
</div>
|
|
9
9
|
</div>
|
|
10
10
|
|
|
11
11
|
<script>
|
|
12
|
-
function
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
12
|
+
function setupIframes() {
|
|
13
|
+
const wrappers = document.getElementsByClassName('async-iframe__wrapper');
|
|
14
|
+
|
|
15
|
+
for (let i = 0; i < wrappers.length; i++) {
|
|
16
|
+
const wrapper = wrappers[i];
|
|
17
|
+
const loaderContainer = wrapper.getElementsByClassName('async-iframe__loader-container')[0];
|
|
18
|
+
const iframe = wrapper.getElementsByTagName('iframe')[0];
|
|
19
|
+
|
|
20
|
+
if (iframe && loaderContainer) {
|
|
21
|
+
const handleLoad = () => {
|
|
22
|
+
loaderContainer.classList.add('async-iframe__hidden');
|
|
23
|
+
iframe.removeEventListener('load', handleLoad);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
iframe.addEventListener('load', handleLoad);
|
|
27
|
+
}
|
|
24
28
|
}
|
|
25
29
|
}
|
|
26
30
|
|
|
27
31
|
if (document.readyState === 'loading') {
|
|
28
32
|
const handleDOMContentLoaded = () => {
|
|
29
|
-
|
|
33
|
+
setupIframes();
|
|
30
34
|
document.removeEventListener('DOMContentLoaded', handleDOMContentLoaded);
|
|
31
35
|
};
|
|
32
36
|
|
|
33
37
|
document.addEventListener('DOMContentLoaded', handleDOMContentLoaded);
|
|
34
38
|
} else {
|
|
35
|
-
|
|
39
|
+
setupIframes();
|
|
36
40
|
}
|
|
37
41
|
</script>
|
|
38
42
|
|
|
39
43
|
<style>
|
|
40
|
-
.async-
|
|
44
|
+
.async-iframe__wrapper {
|
|
41
45
|
position: relative;
|
|
42
46
|
padding-top: 85%;
|
|
43
47
|
height: 0;
|
|
44
48
|
overflow: hidden;
|
|
45
49
|
}
|
|
46
50
|
|
|
47
|
-
.
|
|
51
|
+
.async-iframe__loader-container {
|
|
48
52
|
position: absolute;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
align-items: center;
|
|
55
|
-
justify-content: center;
|
|
56
|
-
z-index: 10;
|
|
53
|
+
inset: 0;
|
|
54
|
+
display: grid;
|
|
55
|
+
place-items: center;
|
|
56
|
+
z-index: 5;
|
|
57
|
+
background: rgba(255, 255, 255, 0.9);
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
.
|
|
60
|
+
.async-iframe__loader {
|
|
60
61
|
width: 2rem;
|
|
61
62
|
height: 2rem;
|
|
62
63
|
border-radius: 50%;
|
|
63
64
|
border: 0.125rem solid transparent;
|
|
64
65
|
border-top-color: #3b82f6;
|
|
65
|
-
animation:
|
|
66
|
+
animation: async-iframe__spin 1s linear infinite;
|
|
66
67
|
}
|
|
67
68
|
|
|
68
|
-
@keyframes
|
|
69
|
+
@keyframes async-iframe__spin {
|
|
69
70
|
0% { transform: rotate(0deg); }
|
|
70
71
|
100% { transform: rotate(360deg); }
|
|
71
72
|
}
|
|
72
73
|
|
|
73
|
-
.
|
|
74
|
+
.async-iframe__container {
|
|
74
75
|
position: absolute;
|
|
75
|
-
|
|
76
|
-
left: 0px;
|
|
77
|
-
right: 0px;
|
|
78
|
-
bottom: 0px;
|
|
76
|
+
inset: 0;
|
|
79
77
|
}
|
|
80
78
|
|
|
81
79
|
:global(iframe) {
|
|
82
80
|
position: absolute;
|
|
83
|
-
|
|
84
|
-
left: 0px;
|
|
81
|
+
inset: 0;
|
|
85
82
|
width: 100%;
|
|
86
83
|
height: 100%;
|
|
87
|
-
border:
|
|
84
|
+
border: 0;
|
|
85
|
+
opacity: 0;
|
|
86
|
+
transition: opacity 0.3s ease-in-out;
|
|
88
87
|
}
|
|
89
88
|
|
|
90
|
-
.
|
|
89
|
+
.async-iframe__hidden {
|
|
91
90
|
display: none !important;
|
|
92
91
|
}
|
|
92
|
+
|
|
93
|
+
.async-iframe__hidden + .async-iframe__container :global(iframe) {
|
|
94
|
+
opacity: 1;
|
|
95
|
+
}
|
|
93
96
|
</style>
|