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 / announcement-strip / frontend.js

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

66 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* ====================================================
2 Announcement Strip — frontend.js
3 Handles: dismissal (localStorage) + countdown timer
4 ==================================================== */
5 (function () {
6 'use strict';
7
8 document.querySelectorAll('.bkbg-anst-wrap[data-close-id]').forEach(function (bar) {
9 var closeId = bar.dataset.closeId;
10 var closeDays = parseInt(bar.dataset.closeDays || '7', 10);
11 var storageKey = 'bkbg-anst-dismissed-' + closeId;
12
13 /* Check if already dismissed and still within expiry */
14 try {
15 var expiry = localStorage.getItem(storageKey);
16 if (expiry && Date.now() < parseInt(expiry, 10)) {
17 bar.style.display = 'none';
18 return; /* skip this bar entirely */
19 }
20 } catch(e) { /* localStorage might be blocked */ }
21
22 /* Wire close button */
23 var closeBtn = bar.querySelector('.bkbg-anst-close');
24 if (closeBtn) {
25 closeBtn.addEventListener('click', function () {
26 bar.style.display = 'none';
27 try {
28 var expireAt = closeDays > 0
29 ? Date.now() + closeDays * 86400000
30 : Date.now() + 9999 * 86400000; /* "forever" */
31 localStorage.setItem(storageKey, String(expireAt));
32 } catch(e) { /* ignore */ }
33 });
34 }
35
36 /* Countdown timer */
37 var cdWrap = bar.querySelector('.bkbg-anst-countdown');
38 if (cdWrap) {
39 var endDateStr = cdWrap.dataset.countdown;
40 if (!endDateStr) return;
41 var endDate = new Date(endDateStr).getTime();
42 var timerEl = cdWrap.querySelector('.bkbg-anst-cd-timer');
43 if (!timerEl || isNaN(endDate)) return;
44
45 function formatCountdown() {
46 var diff = endDate - Date.now();
47 if (diff <= 0) {
48 timerEl.textContent = 'Expired';
49 return;
50 }
51 var d = Math.floor(diff / 86400000);
52 var h = Math.floor(diff % 86400000 / 3600000);
53 var m = Math.floor(diff % 3600000 / 60000);
54 var s = Math.floor(diff % 60000 / 1000);
55 var hStr = String(h).padStart(2, '0');
56 var mStr = String(m).padStart(2, '0');
57 var sStr = String(s).padStart(2, '0');
58 timerEl.textContent = (d ? d + 'd ' : '') + hStr + ':' + mStr + ':' + sStr;
59 }
60
61 formatCountdown(); /* immediate render */
62 setInterval(formatCountdown, 1000);
63 }
64 });
65 })();
66