| 1 |
( function () { |
| 2 |
var el = wp.element.createElement; |
| 3 |
var __ = wp.i18n.__; |
| 4 |
var registerBlockType = wp.blocks.registerBlockType; |
| 5 |
var InspectorControls = wp.blockEditor.InspectorControls; |
| 6 |
var RichText = wp.blockEditor.RichText; |
| 7 |
var MediaUpload = wp.blockEditor.MediaUpload; |
| 8 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 9 |
var PanelColorSettings = wp.blockEditor.PanelColorSettings; |
| 10 |
var PanelBody = wp.components.PanelBody; |
| 11 |
var ToggleControl = wp.components.ToggleControl; |
| 12 |
var RangeControl = wp.components.RangeControl; |
| 13 |
var SelectControl = wp.components.SelectControl; |
| 14 |
var Button = wp.components.Button; |
| 15 |
|
| 16 |
var _tc; function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); } |
| 17 |
var _tv; function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); } |
| 18 |
|
| 19 |
registerBlockType('blockenberg/testimonial-inline', { |
| 20 |
title: __('Testimonial Card', 'blockenberg'), |
| 21 |
icon: 'format-quote', |
| 22 |
category: 'bkbg-marketing', |
| 23 |
|
| 24 |
edit: function (props) { |
| 25 |
var a = props.attributes; |
| 26 |
var set = props.setAttributes; |
| 27 |
|
| 28 |
function wrapStyle(a) { |
| 29 |
var _tvf = getTypoCssVars(); |
| 30 |
var s = { |
| 31 |
'--bkbg-ti-bg': a.bgColor, |
| 32 |
'--bkbg-ti-quote-c': a.quoteColor, |
| 33 |
'--bkbg-ti-name-c': a.nameColor, |
| 34 |
'--bkbg-ti-role-c': a.roleColor, |
| 35 |
'--bkbg-ti-star-c': a.starColor, |
| 36 |
'--bkbg-ti-star-sz': a.starSize + 'px', |
| 37 |
'--bkbg-ti-accent': a.accentColor, |
| 38 |
'--bkbg-ti-border': a.borderColor, |
| 39 |
'--bkbg-ti-qm-c': a.quoteMarkColor, |
| 40 |
'--bkbg-ti-photo-sz': a.photoSize + 'px', |
| 41 |
'--bkbg-ti-r': a.borderRadius + 'px', |
| 42 |
'--bkbg-ti-pad': a.cardPadding + 'px', |
| 43 |
'--bkbg-ti-max-w': a.maxWidth + 'px', |
| 44 |
}; |
| 45 |
if (_tvf) { |
| 46 |
Object.assign(s, _tvf(a.quoteTypo, '--bkti-qt-')); |
| 47 |
Object.assign(s, _tvf(a.nameTypo, '--bkti-nm-')); |
| 48 |
Object.assign(s, _tvf(a.roleTypo, '--bkti-rl-')); |
| 49 |
} |
| 50 |
return s; |
| 51 |
} |
| 52 |
|
| 53 |
var styleOptions = [ |
| 54 |
{ label: __('Card (white)', 'blockenberg'), value: 'card' }, |
| 55 |
{ label: __('Minimal (no bg)', 'blockenberg'), value: 'minimal' }, |
| 56 |
{ label: __('Bubble (speech)', 'blockenberg'), value: 'bubble' }, |
| 57 |
{ label: __('Accent Left Border', 'blockenberg'), value: 'accent' }, |
| 58 |
{ label: __('Dark', 'blockenberg'), value: 'dark' }, |
| 59 |
]; |
| 60 |
|
| 61 |
var alignOptions = [ |
| 62 |
{ label: __('Left', 'blockenberg'), value: 'left' }, |
| 63 |
{ label: __('Center', 'blockenberg'), value: 'center' }, |
| 64 |
{ label: __('Right', 'blockenberg'), value: 'right' }, |
| 65 |
]; |
| 66 |
|
| 67 |
var platformOptions = [ |
| 68 |
{ label: __('None', 'blockenberg'), value: 'none' }, |
| 69 |
{ label: __('Google', 'blockenberg'), value: 'google' }, |
| 70 |
{ label: __('Trustpilot', 'blockenberg'), value: 'trustpilot' }, |
| 71 |
{ label: __('G2', 'blockenberg'), value: 'g2' }, |
| 72 |
{ label: __('Capterra', 'blockenberg'), value: 'capterra' }, |
| 73 |
{ label: __('Yelp', 'blockenberg'), value: 'yelp' }, |
| 74 |
{ label: __('Twitter / X', 'blockenberg'), value: 'twitter' }, |
| 75 |
{ label: __('LinkedIn', 'blockenberg'), value: 'linkedin' }, |
| 76 |
{ label: __('Product Hunt', 'blockenberg'), value: 'producthunt' }, |
| 77 |
]; |
| 78 |
|
| 79 |
var PLATFORM_COLORS = { |
| 80 |
google: '#ea4335', trustpilot: '#00b67a', g2: '#ff492c', |
| 81 |
capterra: '#ff9d28', yelp: '#d32323', twitter: '#1da1f2', |
| 82 |
linkedin: '#0077b5', producthunt: '#da552f' |
| 83 |
}; |
| 84 |
|
| 85 |
var PLATFORM_LABELS = { |
| 86 |
google: 'G', trustpilot: 'TP', g2: 'G2', |
| 87 |
capterra: 'Ca', yelp: 'Yelp', twitter: 'X', |
| 88 |
linkedin: 'in', producthunt: 'PH' |
| 89 |
}; |
| 90 |
|
| 91 |
function renderStars(rating) { |
| 92 |
var stars = []; |
| 93 |
for (var i = 1; i <= 5; i++) { |
| 94 |
stars.push(el('span', { key: i, className: 'bkbg-ti-star' }, i <= rating ? '� |
| 95 |
' : '☆')); |
| 96 |
} |
| 97 |
return el('div', { className: 'bkbg-ti-stars' }, stars); |
| 98 |
} |
| 99 |
|
| 100 |
function renderPlatformBadge(platform) { |
| 101 |
if (!platform || platform === 'none') return null; |
| 102 |
var color = PLATFORM_COLORS[platform] || '#94a3b8'; |
| 103 |
var label = PLATFORM_LABELS[platform] || platform; |
| 104 |
return el('div', { |
| 105 |
className: 'bkbg-ti-platform', |
| 106 |
style: { background: color } |
| 107 |
}, label); |
| 108 |
} |
| 109 |
|
| 110 |
var inspector = el(InspectorControls, {}, |
| 111 |
|
| 112 |
el(PanelBody, { title: __('Author', 'blockenberg'), initialOpen: true }, |
| 113 |
el('label', { style: { display: 'block', fontWeight: 500, fontSize: 11, textTransform: 'uppercase', marginBottom: 8 } }, __('Author Photo', 'blockenberg')), |
| 114 |
el(ToggleControl, { |
| 115 |
label: __('Show Photo', 'blockenberg'), checked: a.showPhoto, __nextHasNoMarginBottom: true, |
| 116 |
onChange: function (v) { set({ showPhoto: v }); } |
| 117 |
}), |
| 118 |
a.showPhoto && el(MediaUpload, { |
| 119 |
onSelect: function (m) { set({ photoUrl: m.url, photoId: m.id }); }, |
| 120 |
allowedTypes: ['image'], |
| 121 |
value: a.photoId, |
| 122 |
render: function (ref) { |
| 123 |
return el('div', { className: 'bkbg-ti-photo-upload' }, |
| 124 |
a.photoUrl && el('img', { src: a.photoUrl, style: { width: 60, height: 60, borderRadius: '50%', objectFit: 'cover', marginBottom: 8 } }), |
| 125 |
el(Button, { variant: 'secondary', onClick: ref.open }, a.photoUrl ? __('Change Photo', 'blockenberg') : __('Upload Photo', 'blockenberg')), |
| 126 |
a.photoUrl && el(Button, { isDestructive: true, variant: 'link', onClick: function () { set({ photoUrl: '', photoId: 0 }); } }, __('Remove', 'blockenberg')) |
| 127 |
); |
| 128 |
} |
| 129 |
}), |
| 130 |
el(RangeControl, { label: __('Photo Size', 'blockenberg'), value: a.photoSize, onChange: function (v) { set({ photoSize: v }); }, min: 32, max: 100 }) |
| 131 |
), |
| 132 |
|
| 133 |
el(PanelBody, { title: __('Rating & Platform', 'blockenberg'), initialOpen: false }, |
| 134 |
el(ToggleControl, { |
| 135 |
label: __('Show Rating Stars', 'blockenberg'), checked: a.showRating, __nextHasNoMarginBottom: true, |
| 136 |
onChange: function (v) { set({ showRating: v }); } |
| 137 |
}), |
| 138 |
a.showRating && el(RangeControl, { label: __('Stars (1–5)', 'blockenberg'), value: a.rating, onChange: function (v) { set({ rating: v }); }, min: 1, max: 5 }), |
| 139 |
a.showRating && el(RangeControl, { label: __('Star Size', 'blockenberg'), value: a.starSize, onChange: function (v) { set({ starSize: v }); }, min: 12, max: 28 }), |
| 140 |
el(ToggleControl, { |
| 141 |
label: __('Show Platform Badge', 'blockenberg'), checked: a.showPlatform, __nextHasNoMarginBottom: true, |
| 142 |
onChange: function (v) { set({ showPlatform: v }); } |
| 143 |
}), |
| 144 |
a.showPlatform && el(SelectControl, { label: __('Platform', 'blockenberg'), value: a.platform, options: platformOptions, onChange: function (v) { set({ platform: v }); } }) |
| 145 |
), |
| 146 |
|
| 147 |
el(PanelBody, { title: __('Style & Layout', 'blockenberg'), initialOpen: false }, |
| 148 |
el(SelectControl, { label: __('Card Style', 'blockenberg'), value: a.style, options: styleOptions, onChange: function (v) { set({ style: v }); } }), |
| 149 |
el(SelectControl, { label: __('Alignment', 'blockenberg'), value: a.align, options: alignOptions, onChange: function (v) { set({ align: v }); } }), |
| 150 |
el(ToggleControl, { |
| 151 |
label: __('Show Quote Mark', 'blockenberg'), checked: a.showQuoteMark, __nextHasNoMarginBottom: true, |
| 152 |
onChange: function (v) { set({ showQuoteMark: v }); } |
| 153 |
}), |
| 154 |
el(RangeControl, { label: __('Max Width (px)', 'blockenberg'), value: a.maxWidth, onChange: function (v) { set({ maxWidth: v }); }, min: 200, max: 1200 }), |
| 155 |
el(RangeControl, { label: __('Card Padding', 'blockenberg'), value: a.cardPadding, onChange: function (v) { set({ cardPadding: v }); }, min: 12, max: 64 }), |
| 156 |
el(RangeControl, { label: __('Border Radius', 'blockenberg'), value: a.borderRadius, onChange: function (v) { set({ borderRadius: v }); }, min: 0, max: 48 }) |
| 157 |
), |
| 158 |
|
| 159 |
el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false }, |
| 160 |
getTypoControl()({ label: __('Quote', 'blockenberg'), value: a.quoteTypo, onChange: function (v) { set({ quoteTypo: v }); } }), |
| 161 |
getTypoControl()({ label: __('Name', 'blockenberg'), value: a.nameTypo, onChange: function (v) { set({ nameTypo: v }); } }), |
| 162 |
getTypoControl()({ label: __('Role', 'blockenberg'), value: a.roleTypo, onChange: function (v) { set({ roleTypo: v }); } }) |
| 163 |
), |
| 164 |
|
| 165 |
el(PanelColorSettings, { |
| 166 |
title: __('Colors', 'blockenberg'), initialOpen: false, |
| 167 |
colorSettings: [ |
| 168 |
{ value: a.bgColor, onChange: function (v) { set({ bgColor: v || '#ffffff' }); }, label: __('Card Background', 'blockenberg') }, |
| 169 |
{ value: a.quoteColor, onChange: function (v) { set({ quoteColor: v || '#1e293b' }); }, label: __('Quote Text Color', 'blockenberg') }, |
| 170 |
{ value: a.nameColor, onChange: function (v) { set({ nameColor: v || '#0f172a' }); }, label: __('Name Color', 'blockenberg') }, |
| 171 |
{ value: a.roleColor, onChange: function (v) { set({ roleColor: v || '#64748b' }); }, label: __('Role Color', 'blockenberg') }, |
| 172 |
{ value: a.starColor, onChange: function (v) { set({ starColor: v || '#f59e0b' }); }, label: __('Star Color', 'blockenberg') }, |
| 173 |
{ value: a.accentColor, onChange: function (v) { set({ accentColor: v || '#6c3fb5' }); }, label: __('Accent Color', 'blockenberg') }, |
| 174 |
{ value: a.borderColor, onChange: function (v) { set({ borderColor: v || '#e2e8f0' }); }, label: __('Border Color', 'blockenberg') }, |
| 175 |
{ value: a.quoteMarkColor, onChange: function (v) { set({ quoteMarkColor: v || '#6c3fb5' }); }, label: __('Quote Mark Color', 'blockenberg') }, |
| 176 |
] |
| 177 |
}) |
| 178 |
); |
| 179 |
|
| 180 |
var alignClass = 'bkbg-ti-align--' + a.align; |
| 181 |
var blockProps = useBlockProps({ |
| 182 |
className: 'bkbg-ti-wrap bkbg-ti-style--' + a.style + ' ' + alignClass, |
| 183 |
style: wrapStyle(a) |
| 184 |
}); |
| 185 |
|
| 186 |
var photoEl = a.showPhoto && ( |
| 187 |
a.photoUrl ? |
| 188 |
el('img', { className: 'bkbg-ti-photo', src: a.photoUrl, alt: a.name }) : |
| 189 |
el('div', { className: 'bkbg-ti-photo bkbg-ti-photo--placeholder' }, |
| 190 |
el('span', { className: 'dashicons dashicons-admin-users' }) |
| 191 |
) |
| 192 |
); |
| 193 |
|
| 194 |
return el('div', blockProps, |
| 195 |
inspector, |
| 196 |
el('div', { className: 'bkbg-ti-card' }, |
| 197 |
a.showRating && renderStars(a.rating), |
| 198 |
a.showQuoteMark && el('div', { className: 'bkbg-ti-qm' }, '\u201C'), |
| 199 |
el(RichText, { |
| 200 |
tagName: 'p', className: 'bkbg-ti-quote', |
| 201 |
value: a.quote, placeholder: __('Enter testimonial quote…', 'blockenberg'), |
| 202 |
onChange: function (v) { set({ quote: v }); } |
| 203 |
}), |
| 204 |
el('div', { className: 'bkbg-ti-author' }, |
| 205 |
photoEl, |
| 206 |
el('div', { className: 'bkbg-ti-author-text' }, |
| 207 |
el('div', { className: 'bkbg-ti-name' }, a.name), |
| 208 |
el('div', { className: 'bkbg-ti-role' }, |
| 209 |
a.role, a.showCompany && a.company ? ' · ' + a.company : '' |
| 210 |
) |
| 211 |
), |
| 212 |
a.showPlatform && renderPlatformBadge(a.platform) |
| 213 |
) |
| 214 |
) |
| 215 |
); |
| 216 |
}, |
| 217 |
|
| 218 |
save: function (props) { |
| 219 |
var a = props.attributes; |
| 220 |
var el = wp.element.createElement; |
| 221 |
|
| 222 |
function wrapStyle(a) { |
| 223 |
var _tvf = getTypoCssVars(); |
| 224 |
var s = { |
| 225 |
'--bkbg-ti-bg': a.bgColor, |
| 226 |
'--bkbg-ti-quote-c': a.quoteColor, |
| 227 |
'--bkbg-ti-name-c': a.nameColor, |
| 228 |
'--bkbg-ti-role-c': a.roleColor, |
| 229 |
'--bkbg-ti-star-c': a.starColor, |
| 230 |
'--bkbg-ti-star-sz': a.starSize + 'px', |
| 231 |
'--bkbg-ti-accent': a.accentColor, |
| 232 |
'--bkbg-ti-border': a.borderColor, |
| 233 |
'--bkbg-ti-qm-c': a.quoteMarkColor, |
| 234 |
'--bkbg-ti-photo-sz': a.photoSize + 'px', |
| 235 |
'--bkbg-ti-r': a.borderRadius + 'px', |
| 236 |
'--bkbg-ti-pad': a.cardPadding + 'px', |
| 237 |
'--bkbg-ti-max-w': a.maxWidth + 'px', |
| 238 |
}; |
| 239 |
if (_tvf) { |
| 240 |
Object.assign(s, _tvf(a.quoteTypo, '--bkti-qt-')); |
| 241 |
Object.assign(s, _tvf(a.nameTypo, '--bkti-nm-')); |
| 242 |
Object.assign(s, _tvf(a.roleTypo, '--bkti-rl-')); |
| 243 |
} |
| 244 |
return s; |
| 245 |
} |
| 246 |
|
| 247 |
var PLATFORM_COLORS = { |
| 248 |
google: '#ea4335', trustpilot: '#00b67a', g2: '#ff492c', |
| 249 |
capterra: '#ff9d28', yelp: '#d32323', twitter: '#1da1f2', |
| 250 |
linkedin: '#0077b5', producthunt: '#da552f' |
| 251 |
}; |
| 252 |
var PLATFORM_LABELS = { |
| 253 |
google: 'G', trustpilot: 'TP', g2: 'G2', |
| 254 |
capterra: 'Ca', yelp: 'Yelp', twitter: 'X', linkedin: 'in', producthunt: 'PH' |
| 255 |
}; |
| 256 |
|
| 257 |
var blockProps = wp.blockEditor.useBlockProps.save({ |
| 258 |
className: 'bkbg-ti-wrap bkbg-ti-style--' + a.style + ' bkbg-ti-align--' + a.align, |
| 259 |
style: wrapStyle(a) |
| 260 |
}); |
| 261 |
|
| 262 |
var stars = []; |
| 263 |
if (a.showRating) { |
| 264 |
for (var i = 1; i <= 5; i++) { |
| 265 |
stars.push(el('span', { key: i, className: 'bkbg-ti-star' }, i <= a.rating ? '� |
| 266 |
' : '☆')); |
| 267 |
} |
| 268 |
} |
| 269 |
|
| 270 |
var platformEl = null; |
| 271 |
if (a.showPlatform && a.platform && a.platform !== 'none') { |
| 272 |
platformEl = el('div', { |
| 273 |
className: 'bkbg-ti-platform', |
| 274 |
style: { background: PLATFORM_COLORS[a.platform] || '#94a3b8' } |
| 275 |
}, PLATFORM_LABELS[a.platform] || a.platform); |
| 276 |
} |
| 277 |
|
| 278 |
return el('div', blockProps, |
| 279 |
el('div', { className: 'bkbg-ti-card' }, |
| 280 |
a.showRating && el('div', { className: 'bkbg-ti-stars' }, stars), |
| 281 |
a.showQuoteMark && el('div', { className: 'bkbg-ti-qm' }, '\u201C'), |
| 282 |
el(RichText.Content, { tagName: 'p', className: 'bkbg-ti-quote', value: a.quote }), |
| 283 |
el('div', { className: 'bkbg-ti-author' }, |
| 284 |
a.showPhoto && ( |
| 285 |
a.photoUrl ? |
| 286 |
el('img', { className: 'bkbg-ti-photo', src: a.photoUrl, alt: a.name }) : |
| 287 |
el('div', { className: 'bkbg-ti-photo bkbg-ti-photo--placeholder' }, |
| 288 |
el('span', { className: 'dashicons dashicons-admin-users' }) |
| 289 |
) |
| 290 |
), |
| 291 |
el('div', { className: 'bkbg-ti-author-text' }, |
| 292 |
el('div', { className: 'bkbg-ti-name' }, a.name), |
| 293 |
el('div', { className: 'bkbg-ti-role' }, |
| 294 |
a.role, a.showCompany && a.company ? ' · ' + a.company : '' |
| 295 |
) |
| 296 |
), |
| 297 |
platformEl |
| 298 |
) |
| 299 |
) |
| 300 |
); |
| 301 |
} |
| 302 |
}); |
| 303 |
}() ); |
| 304 |
|