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

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

134 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function () {
2
3 function hexLuma(hex) {
4 if (!hex) return 0;
5 var c = hex.replace('#','');
6 if (c.length === 3) c = c[0]+c[0]+c[1]+c[1]+c[2]+c[2];
7 var r = parseInt(c.substr(0,2),16), g = parseInt(c.substr(2,2),16), b = parseInt(c.substr(4,2),16);
8 return 0.299*r + 0.587*g + 0.114*b;
9 }
10
11 function buildAwardCard(aw, opts) {
12 var card = document.createElement('div');
13 card.className = 'bkbg-aw-card';
14
15 if (aw.url) {
16 card.style.cursor = 'pointer';
17 card.addEventListener('click', function () { window.open(aw.url, '_blank', 'noopener'); });
18 }
19
20 /* Icon */
21 var iconWrap = document.createElement('div');
22 iconWrap.className = 'bkbg-aw-icon-wrap';
23 iconWrap.style.background = aw.color || '';
24 var iconTextColor = hexLuma(aw.color || '#6c3fb5') > 140 ? '#333' : '#fff';
25 iconWrap.style.color = iconTextColor;
26
27 if (aw.imageUrl) {
28 var img = document.createElement('img');
29 img.src = aw.imageUrl; img.alt = aw.title;
30 iconWrap.appendChild(img);
31 } else {
32 var iconSpan = document.createElement('span');
33 var _IP = window.bkbgIconPicker;
34 var _iType = aw.iconType || 'custom-char';
35 if (_IP && _iType !== 'custom-char') {
36 var _in = _IP.buildFrontendIcon(_iType, aw.icon, aw.iconDashicon, aw.iconImageUrl, aw.iconDashiconColor);
37 if (_in) iconSpan.appendChild(_in);
38 else iconSpan.textContent = aw.icon || '🏆';
39 } else {
40 iconSpan.textContent = aw.icon || '🏆';
41 }
42 iconWrap.appendChild(iconSpan);
43 }
44 card.appendChild(iconWrap);
45
46 /* Content */
47 var content = document.createElement('div');
48 content.className = 'bkbg-aw-content';
49
50 var titleRow = document.createElement('div');
51 titleRow.className = 'bkbg-aw-title-row';
52
53 var awardTitle = document.createElement('p');
54 awardTitle.className = 'bkbg-aw-award-title';
55 awardTitle.textContent = aw.title;
56 titleRow.appendChild(awardTitle);
57
58 if (opts.showYear && aw.year) {
59 var year = document.createElement('span');
60 year.className = 'bkbg-aw-year';
61 year.textContent = aw.year;
62 titleRow.appendChild(year);
63 }
64 content.appendChild(titleRow);
65
66 if (opts.showIssuer && aw.issuer) {
67 var issuer = document.createElement('p');
68 issuer.className = 'bkbg-aw-issuer';
69 issuer.textContent = aw.issuer;
70 content.appendChild(issuer);
71 }
72
73 if (opts.showDesc && aw.description) {
74 var desc = document.createElement('p');
75 desc.className = 'bkbg-aw-desc';
76 desc.textContent = aw.description;
77 content.appendChild(desc);
78 }
79
80 card.appendChild(content);
81 return card;
82 }
83
84 function initAwards(wrapper) {
85 if (wrapper.dataset.initialized) return;
86 wrapper.dataset.initialized = '1';
87
88 var gridEl = wrapper.querySelector('.bkbg-aw-grid');
89 if (!gridEl) return;
90
91 var awards = [];
92 try { awards = JSON.parse(gridEl.getAttribute('data-awards') || '[]'); } catch (e) {}
93
94 var opts = {
95 layout: gridEl.getAttribute('data-layout') || 'grid',
96 showYear: gridEl.getAttribute('data-show-year') === '1',
97 showIssuer: gridEl.getAttribute('data-show-issuer') === '1',
98 showDesc: gridEl.getAttribute('data-show-desc') === '1',
99 };
100
101 if (opts.layout === 'list') {
102 gridEl.classList.remove('bkbg-aw-grid');
103 gridEl.classList.add('bkbg-aw-list');
104 }
105
106 awards.forEach(function (aw) {
107 gridEl.appendChild(buildAwardCard(aw, opts));
108 });
109
110 /* Staggered entrance animation */
111 var cards = gridEl.querySelectorAll('.bkbg-aw-card');
112 if ('IntersectionObserver' in window) {
113 var obs = new IntersectionObserver(function (entries) {
114 entries.forEach(function (e) {
115 if (e.isIntersecting) {
116 var idx = Array.prototype.indexOf.call(cards, e.target);
117 setTimeout(function () { e.target.classList.add('is-visible'); }, idx * 80);
118 obs.unobserve(e.target);
119 }
120 });
121 }, { threshold: 0.1 });
122 cards.forEach(function (c) { obs.observe(c); });
123 } else {
124 cards.forEach(function (c) { c.classList.add('is-visible'); });
125 }
126 }
127
128 function init() {
129 document.querySelectorAll('.bkbg-aw-wrapper').forEach(initAwards);
130 }
131
132 if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); }
133 }());
134