PluginProbe
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor / 2.0.7
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor v2.0.7
2.0.13 2.0.12 2.0.11 2.0.10 2.0.9 trunk 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8
blockenberg / blocks / typing-effect / frontend.js

frontend.js in Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor 2.0.7, at blocks/typing-effect/frontend.js

57 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 ( function () {
2 function initTyping(wrap) {
3 var typed = wrap.querySelector('.bkte-typed');
4 var cursor = wrap.querySelector('.bkte-cursor');
5 if (!typed) return;
6
7 var phrasesRaw = wrap.dataset.phrases || '';
8 var typeSpeed = parseInt(wrap.dataset.typeSpeed, 10) || 80;
9 var deleteSpeed = parseInt(wrap.dataset.deleteSpeed, 10) || 40;
10 var pause = parseInt(wrap.dataset.pause, 10) || 1800;
11 var loop = wrap.dataset.loop !== '0';
12 var cursorBlink = wrap.dataset.cursorBlink !== '0';
13
14 if (cursorBlink && cursor) cursor.style.animation = 'bkteCursorBlink 0.75s step-end infinite';
15
16 var phrases = phrasesRaw.split(',').map(function(s){ return s.trim(); }).filter(Boolean);
17 if (!phrases.length) return;
18
19 var idx = 0;
20 var charIdx = 0;
21 var deleting = false;
22
23 function tick() {
24 var current = phrases[idx];
25 if (!deleting) {
26 charIdx++;
27 typed.textContent = current.slice(0, charIdx);
28 if (charIdx >= current.length) {
29 deleting = true;
30 setTimeout(tick, pause);
31 return;
32 }
33 setTimeout(tick, typeSpeed);
34 } else {
35 charIdx--;
36 typed.textContent = current.slice(0, charIdx);
37 if (charIdx === 0) {
38 deleting = false;
39 idx++;
40 if (idx >= phrases.length) {
41 if (!loop) return;
42 idx = 0;
43 }
44 }
45 setTimeout(tick, deleting ? deleteSpeed : typeSpeed + 20);
46 }
47 }
48
49 // Start typing after a short delay
50 setTimeout(tick, 600);
51 }
52
53 document.addEventListener('DOMContentLoaded', function () {
54 document.querySelectorAll('.bkte-wrap[data-phrases]').forEach(initTyping);
55 });
56 }() );
57