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 / text-case-converter / frontend.js

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

168 lines 6.8 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 toTitleCase(s) {
5 return s.replace(/\w\S*/g, function(w){ return w.charAt(0).toUpperCase() + w.substr(1).toLowerCase(); });
6 }
7 function toSentenceCase(s) {
8 return s.toLowerCase().replace(/(^\s*\w|[.!?]\s*\w)/g, function(c){ return c.toUpperCase(); });
9 }
10 function toCamelCase(s) {
11 return s.replace(/[^a-zA-Z0-9]+(.)/g, function(_, c){ return c.toUpperCase(); })
12 .replace(/^[A-Z]/, function(c){ return c.toLowerCase(); });
13 }
14 function toPascalCase(s) {
15 var c = toCamelCase(s);
16 return c.charAt(0).toUpperCase() + c.slice(1);
17 }
18 function toSnakeCase(s) {
19 return s.replace(/\s+/g, '_').replace(/[^a-zA-Z0-9_]/g, '').replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase();
20 }
21 function toKebabCase(s) {
22 return s.replace(/\s+/g, '-').replace(/[^a-zA-Z0-9-]/g, '').replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
23 }
24
25 var CASES = [
26 { key: 'showUppercase', label: 'UPPERCASE', fn: function(s){ return s.toUpperCase(); } },
27 { key: 'showLowercase', label: 'lowercase', fn: function(s){ return s.toLowerCase(); } },
28 { key: 'showTitleCase', label: 'Title Case', fn: toTitleCase },
29 { key: 'showSentenceCase', label: 'Sentence case', fn: toSentenceCase },
30 { key: 'showCamelCase', label: 'camelCase', fn: toCamelCase },
31 { key: 'showPascalCase', label: 'PascalCase', fn: toPascalCase },
32 { key: 'showSnakeCase', label: 'snake_case', fn: toSnakeCase },
33 { key: 'showKebabCase', label: 'kebab-case', fn: toKebabCase }
34 ];
35
36 function init(app) {
37 var a;
38 try { a = JSON.parse(app.getAttribute('data-opts')); } catch(e) { return; }
39
40 var accent = a.accentColor || '#6c3fb5';
41 var activeRows = CASES.filter(function(c){ return a[c.key]; });
42
43 // Apply section styles
44 app.style.paddingTop = (a.paddingTop || 60) + 'px';
45 app.style.paddingBottom = (a.paddingBottom || 60) + 'px';
46 if (a.sectionBg) app.style.background = a.sectionBg;
47 app.innerHTML = '';
48
49 // Wrap
50 var wrap = document.createElement('div');
51 wrap.className = 'bkbg-tcc-wrap';
52 wrap.style.maxWidth = (a.maxWidth || 640) + 'px';
53 wrap.style.borderRadius = (a.cardRadius || 16) + 'px';
54 wrap.style.background = a.cardBg || '#fff';
55 app.appendChild(wrap);
56
57 // Header
58 if (a.showTitle || a.showSubtitle) {
59 var header = document.createElement('div');
60 header.className = 'bkbg-tcc-header';
61 if (a.showTitle && a.title) {
62 var title = document.createElement('div');
63 title.className = 'bkbg-tcc-title';
64 title.textContent = a.title;
65 if (a.titleColor) title.style.color = a.titleColor;
66 header.appendChild(title);
67 }
68 if (a.showSubtitle && a.subtitle) {
69 var sub = document.createElement('div');
70 sub.className = 'bkbg-tcc-subtitle';
71 sub.textContent = a.subtitle;
72 if (a.subtitleColor) sub.style.color = a.subtitleColor;
73 header.appendChild(sub);
74 }
75 wrap.appendChild(header);
76 }
77
78 // Textarea
79 var textarea = document.createElement('textarea');
80 textarea.className = 'bkbg-tcc-textarea';
81 textarea.placeholder = a.placeholder || 'Paste or type your text here…';
82 textarea.rows = 4;
83 textarea.style.borderRadius = (a.rowRadius || 10) + 'px';
84 textarea.style.border = '1.5px solid ' + (a.inputBorder || '#e5e7eb');
85 textarea.style.background = a.inputBg || '#f9fafb';
86 wrap.appendChild(textarea);
87
88 // Rows container
89 var rowsContainer = document.createElement('div');
90 rowsContainer.className = 'bkbg-tcc-rows';
91 wrap.appendChild(rowsContainer);
92
93 // Build rows
94 var valueEls = {};
95 var copyBtns = {};
96
97 activeRows.forEach(function(c) {
98 var row = document.createElement('div');
99 row.className = 'bkbg-tcc-row';
100 row.style.background = a.rowBg || '#f9fafb';
101 row.style.borderColor = a.rowBorder || '#e5e7eb';
102 row.style.borderRadius = (a.rowRadius || 10) + 'px';
103
104 var lbl = document.createElement('div');
105 lbl.className = 'bkbg-tcc-row-label';
106 lbl.textContent = c.label;
107 if (a.rowLabelColor) lbl.style.color = a.rowLabelColor;
108
109 var val = document.createElement('div');
110 val.className = 'bkbg-tcc-row-value empty';
111 val.textContent = 'No text entered';
112 if (a.rowValueColor) val.style.color = a.rowValueColor;
113 valueEls[c.key] = val;
114
115 row.appendChild(lbl);
116 row.appendChild(val);
117
118 if (a.showCopyButtons) {
119 var btn = document.createElement('button');
120 btn.className = 'bkbg-tcc-copy-btn';
121 btn.textContent = 'Copy';
122 btn.style.background = a.copyBg || accent;
123 btn.style.color = a.copyColor || '#fff';
124 copyBtns[c.key] = btn;
125 btn.addEventListener('click', function() {
126 var result = val.textContent;
127 if (!result || val.classList.contains('empty')) return;
128 navigator.clipboard.writeText(result).then(function() {
129 btn.textContent = '✓ Copied';
130 btn.classList.add('copied');
131 btn.style.background = '#10b981';
132 setTimeout(function() {
133 btn.textContent = 'Copy';
134 btn.classList.remove('copied');
135 btn.style.background = a.copyBg || accent;
136 }, 1500);
137 }).catch(function() {});
138 });
139 row.appendChild(btn);
140 }
141
142 rowsContainer.appendChild(row);
143 });
144
145 function update() {
146 var text = textarea.value;
147 activeRows.forEach(function(c) {
148 var el = valueEls[c.key];
149 if (!el) return;
150 if (!text.trim()) {
151 el.textContent = 'No text entered';
152 el.classList.add('empty');
153 if (a.rowValueColor) el.style.color = '#d1d5db';
154 } else {
155 el.textContent = c.fn(text);
156 el.classList.remove('empty');
157 if (a.rowValueColor) el.style.color = a.rowValueColor;
158 }
159 });
160 }
161
162 textarea.addEventListener('input', update);
163 update();
164 }
165
166 document.querySelectorAll('.bkbg-tcc-app').forEach(init);
167 })();
168