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

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

47 lines 1.7 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 // Flash notification element
5 var flash = null;
6 function showFlash(hex) {
7 if (!flash) {
8 flash = document.createElement('div');
9 flash.className = 'bkbg-ct-copied-flash';
10 document.body.appendChild(flash);
11 }
12 flash.textContent = 'Copied ' + hex;
13 flash.classList.add('show');
14 clearTimeout(flash._timer);
15 flash._timer = setTimeout(function () { flash.classList.remove('show'); }, 1600);
16 }
17
18 function init() {
19 document.querySelectorAll('.bkbg-ct-wrap').forEach(function (wrap) {
20 if (wrap.dataset.ctReady) return;
21 wrap.dataset.ctReady = '1';
22
23 wrap.querySelectorAll('.bkbg-ct-color-block').forEach(function (block) {
24 var hex = block.dataset.hex;
25 if (!hex) return;
26 block.addEventListener('click', function () {
27 if (navigator.clipboard) {
28 navigator.clipboard.writeText(hex).then(function () { showFlash(hex); });
29 } else {
30 var ta = document.createElement('textarea');
31 ta.value = hex;
32 ta.style.position = 'fixed';
33 ta.style.opacity = '0';
34 document.body.appendChild(ta);
35 ta.select();
36 document.execCommand('copy');
37 document.body.removeChild(ta);
38 showFlash(hex);
39 }
40 });
41 });
42 });
43 }
44
45 if (document.readyState !== 'loading') { init(); } else { document.addEventListener('DOMContentLoaded', init); }
46 })();
47