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 / dynamic-date / frontend.js

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

44 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 ( function () {
2 var FORMAT_MAP = {
3 'long-date': { opts: { weekday:'long', year:'numeric', month:'long', day:'numeric' } },
4 'short-date': { opts: { year:'numeric', month:'short', day:'numeric' } },
5 'numeric-date': { opts: { year:'numeric', month:'2-digit', day:'2-digit' } },
6 'year-only': null,
7 'time-12': { opts: { hour:'numeric', minute:'2-digit', hour12: true } },
8 'time-24': { opts: { hour:'2-digit', minute:'2-digit', hour12: false } },
9 'datetime': { opts: { year:'numeric', month:'short', day:'numeric', hour:'numeric', minute:'2-digit' } }
10 };
11
12 function formatDate( format, tz ) {
13 var now = new Date();
14 if ( format === 'year-only' ) return String( now.getFullYear() );
15 var entry = FORMAT_MAP[ format ];
16 if ( !entry ) return now.toLocaleDateString();
17 try {
18 var opts = Object.assign( {}, entry.opts );
19 if ( tz && tz !== 'site' && tz !== 'utc' ) opts.timeZone = tz;
20 if ( tz === 'utc' ) opts.timeZone = 'UTC';
21 return now.toLocaleString( navigator.language || 'en', opts );
22 } catch (e) {
23 return now.toLocaleString();
24 }
25 }
26
27 document.querySelectorAll( '.bkdd-wrap' ).forEach( function ( wrap ) {
28 var format = wrap.dataset.format || 'long-date';
29 var tz = wrap.dataset.tz || 'site';
30 var live = wrap.dataset.live === '1';
31 var dateEl = wrap.querySelector( '.bkdd-date' );
32 if ( !dateEl ) return;
33
34 function update() {
35 dateEl.textContent = formatDate( format, tz );
36 }
37 update();
38
39 if ( live ) {
40 setInterval( update, 1000 );
41 }
42 } );
43 } )();
44