PluginProbe
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor / 2.0.11
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor v2.0.11
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 / text-highlight / frontend.js

frontend.js in Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor 2.0.11, at blocks/text-highlight/frontend.js

74 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function () {
2 'use strict';
3
4 function reducedMotion() {
5 return window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
6 }
7
8 function revealMarks(marks) {
9 marks.forEach(function (mark, i) {
10 // Delay staggered by index using CSS-custom-property delay set inline
11 var delay = parseFloat(mark.dataset.bkthI || 0) * parseFloat(getComputedStyle(mark.closest('[data-threshold]') || document.documentElement).getPropertyValue('--bkth-hl-delay') || 80);
12 setTimeout(function () {
13 mark.classList.add('bkth-revealed');
14 }, delay);
15 });
16 }
17
18 function hideMarks(marks) {
19 marks.forEach(function (mark) {
20 mark.classList.remove('bkth-revealed');
21 });
22 }
23
24 function initBlock(wrap) {
25 if (wrap.dataset.animate !== '1') {
26 // Static: reveal immediately
27 wrap.querySelectorAll('.bkth-hl.bkth-animate').forEach(function (m) {
28 m.classList.add('bkth-revealed');
29 });
30 return;
31 }
32
33 var marks = Array.prototype.slice.call(wrap.querySelectorAll('.bkth-hl.bkth-animate'));
34 if (!marks.length) return;
35
36 if (reducedMotion()) {
37 marks.forEach(function (m) { m.classList.add('bkth-revealed'); });
38 return;
39 }
40
41 var threshold = parseFloat(wrap.dataset.threshold) || 0.2;
42 var repeat = wrap.dataset.repeat === '1';
43
44 var observer = new IntersectionObserver(function (entries) {
45 entries.forEach(function (entry) {
46 if (entry.isIntersecting) {
47 revealMarks(marks);
48 if (!repeat) observer.unobserve(wrap);
49 } else if (repeat) {
50 hideMarks(marks);
51 }
52 });
53 }, { threshold: threshold });
54
55 observer.observe(wrap);
56 }
57
58 function init() {
59 document.querySelectorAll('.bkth-wrap').forEach(initBlock);
60 }
61
62 if (typeof IntersectionObserver === 'undefined') {
63 document.querySelectorAll('.bkth-hl').forEach(function (m) { m.classList.add('bkth-revealed'); });
64 return;
65 }
66
67 if (document.readyState === 'loading') {
68 document.addEventListener('DOMContentLoaded', init);
69 } else {
70 init();
71 }
72
73 }());
74