-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrnbw-blog.js
313 lines (293 loc) · 8.96 KB
/
rnbw-blog.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
const rnbwBlog = `
<div
class="box align-center radius-s padding-l border"
id="blog-wrapper"
>
<div style="position: absolute; left: 24px; top: 24px; right: 24px"
>
<article style="opacity:0; transition: opacity 0.5s; transition-delay: 0.5s;" id="anim-5">
<h2>Blog Post Title</h2>
<p>Posted on April 30, 2023 by Author Name</p>
<h2>👋</h2>
<p>
This is the first paragraph of the blog post. It should be
engaging and give readers an idea of what to expect in the rest
of the article.
</p>
<h3>Subheading 1</h3>
<p>
This paragraph is part of the first section, which has a
subheading to help organize the content.
</p>
<h3>Subheading 2</h3>
<p>
This paragraph is part of the second section, which also has a
subheading for organization purposes.
</p>
</article>
</div>
<div
class="row shadow radius-s box-s border"
style="z-index: 999"
id="anim-6"
>
<div class="gap-m border-bottom padding-m justify-stretch box-l">
<div class="gap-s column">
<div class="justify-start gap-s padding-s">
<div>
<span class="text-l opacity-m" id="anim-1" data-type="create a blog post layout">
Do something...
</span>
</div>
</div>
</div>
</div>
<div class="column align-stretch box-l padding-m">
<div class="column align-stretch" id="anim-4">
<div class="padding-m gap-s">
<span class="text-s opacity-m">Generate</span>
</div>
<div
class="justify-stretch padding-s background-secondary radius-xs"
>
<div class="gap-s align-center">
<div class="padding-xs">
<svg-icon
src="https://raincons.rnbw.dev/icons/repeat-x.svg"
></svg-icon>
</div>
<span class="text-m">Continue</span>
</div>
</div>
<div class="justify-stretch padding-s radius-xs">
<div class="gap-s align-center">
<div class="padding-xs">
<svg-icon
src="https://raincons.rnbw.dev/icons/bullet.svg"
></svg-icon>
</div>
<span class="text-m">Create</span>
</div>
</div>
<div class="justify-stretch padding-s radius-xs">
<div class="gap-s align-center">
<div class="padding-xs">
<svg-icon
src="https://raincons.rnbw.dev/icons/help.svg"
></svg-icon>
</div>
<span class="text-m">Explain</span>
</div>
</div>
<div class="justify-stretch padding-s radius-xs">
<div class="gap-s align-center">
<div class="padding-xs">
<svg-icon
src="https://raincons.rnbw.dev/icons/events.svg"
></svg-icon>
</div>
<span class="text-m">Brainstorm </span>
</div>
</div>
<div class="padding-m gap-s">
<span class="text-s opacity-m">Edit</span>
</div>
<div class="justify-stretch padding-s radius-xs">
<div class="gap-s align-center">
<div class="padding-xs">
<svg-icon
src="https://raincons.rnbw.dev/icons/bubble.svg"
></svg-icon>
</div>
<span class="text-m">Change tone</span>
</div>
</div>
<div class="justify-stretch padding-s radius-xs">
<div class="gap-s align-center">
<div class="padding-xs">
<svg-icon
src="https://raincons.rnbw.dev/icons/edit.svg"
></svg-icon>
</div>
<span class="text-m">Improve Writing </span>
</div>
</div>
<div class="justify-stretch padding-s radius-xs">
<div class="gap-s align-center">
<div class="padding-xs">
<svg-icon
src="https://raincons.rnbw.dev/icons/location.svg"
></svg-icon>
</div>
<span class="text-m">Simplify </span>
</div>
</div>
<div class="padding-m gap-s" id="anim-2">
<span class="text-s opacity-m" >Recent</span>
</div>
<div class="justify-stretch padding-s radius-xs" id="anim-3">
<div class="gap-s align-center">
<div class="padding-xs">
<svg-icon
src="https://raincons.rnbw.dev/icons/bullet-outlined.svg"
></svg-icon>
</div>
<span class="text-m">Create a blog post layout</span>
</div>
</div>
<div class="justify-stretch padding-s radius-xs">
<div class="gap-s align-center">
<div class="padding-xs">
<svg-icon
src="https://raincons.rnbw.dev/icons/bullet-outlined.svg"
></svg-icon>
</div>
<span class="text-m"
>Create a pricing section with the active components
libraries</span
>
</div>
</div>
</div>
</div>
<div class="box-l row align-stretch"></div>
</div>
</div>
`;
class RnbwBlog extends HTMLElement {
constructor() {
super();
this.innerHTML = rnbwBlog;
}
}
customElements.define("rnbw-blog", RnbwBlog);
const rules = `
.fade-in {
opacity: 0;
transition: opacity 0.5s ease-in-out;
}
.fade-in.show {
opacity: 1;
}
#blog-wrapper {
min-height: 610px;
position: relative;
}
@media (max-width: 768px) {
#blog-wrapper {
min-height: 850px;
}
}
@media (max-width: 350px) {
#blog-wrapper {
min-height: 1000px;
}
}
`;
if (!!style) style.innerHTML = style.innerHTML + rules;
document.addEventListener("DOMContentLoaded", function () {
const rnbwBlogElement = document.querySelector("rnbw-blog");
function getAnimationElements() {
return {
anim1: rnbwBlogElement.querySelector("#anim-1"),
anim3: rnbwBlogElement.querySelector("#anim-3"),
anim4: rnbwBlogElement.querySelector("#anim-4"),
anim5: rnbwBlogElement.querySelector("#anim-5"),
anim6: rnbwBlogElement.querySelector("#anim-6"),
};
}
const { anim1 } = getAnimationElements();
let delay = 250;
const options = {
root: null,
rootMargin: "0px",
threshold: 0.1,
};
const observer = new IntersectionObserver(animateOnIntersect, options);
observer.observe(anim1);
function makeAnim5ChildrenInvisible() {
const { anim5 } = getAnimationElements();
let anim5DivChildren = Array.from(anim5.children);
anim5.style.opacity = 0;
anim5DivChildren.forEach((child) => {
child.style.opacity = 0;
//add transition
child.style.transition = "opacity 0.5s ease-in-out";
});
}
function animateOnIntersect(entries, observer) {
setTimeout(() => {
makeAnim5ChildrenInvisible();
type();
}, 1000);
observer.unobserve(entries[0].target);
}
const span = document.querySelector("rnbw-blog #anim-1");
let i = 0;
const text = span.dataset.type;
function type() {
if (i < text.length) {
if (i == 0) {
span.textContent = "";
}
if (i === 1) {
filterAndSelectDiv();
}
span.textContent += text.charAt(i);
i++;
delay += 50;
setTimeout(type, 200); // adjust the delay time as needed
}
}
function filterAndSelectDiv() {
const { anim3, anim4, anim5, anim6 } = getAnimationElements();
let anim4DivChildren = anim4.children;
for (let i = 0; i < anim4DivChildren.length; i++) {
if (
anim4DivChildren[i].id == "anim-2" ||
anim4DivChildren[i].id == "anim-3"
) {
continue;
}
anim4DivChildren[i].style.display = "none";
delay += 10;
if (i === anim4DivChildren.length - 1) {
delay += 1500;
anim4DivChildren[1].classList.remove("background-secondary");
anim3.classList.add("background-secondary");
setTimeout(() => {
anim5.style.opacity = "1";
anim6.style.opacity = "0";
let anim5DivChildren = Array.from(anim5.children);
let timer = 500;
anim5DivChildren.forEach((child) => {
setTimeout(() => {
child.style.opacity = 1;
}, timer);
timer += 150;
});
setTimeout(() => {
resetAnimation();
}, timer + 1000);
}, delay);
}
}
}
function resetAnimation() {
const { anim3, anim4, anim6 } = getAnimationElements();
let anim4DivChildren = anim4.children;
makeAnim5ChildrenInvisible();
anim3.classList.remove("background-secondary");
for (let i = 0; i < anim4DivChildren.length; i++) {
anim4DivChildren[i].style.display = "flex";
}
setTimeout(() => {
anim6.style.opacity = "1";
delay = 250;
i = 0;
const span = document.querySelector("rnbw-blog #anim-1");
span.textContent = "Do something...";
observer.observe(anim1);
}, 500);
}
});