| 1 |
( function () { |
| 2 |
var el = wp.element.createElement; |
| 3 |
var useState = wp.element.useState; |
| 4 |
var __ = wp.i18n.__; |
| 5 |
var registerBlockType = wp.blocks.registerBlockType; |
| 6 |
var InspectorControls = wp.blockEditor.InspectorControls; |
| 7 |
var RichText = wp.blockEditor.RichText; |
| 8 |
var MediaUpload = wp.blockEditor.MediaUpload; |
| 9 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 10 |
var PanelColorSettings = wp.blockEditor.PanelColorSettings; |
| 11 |
var PanelBody = wp.components.PanelBody; |
| 12 |
var RangeControl = wp.components.RangeControl; |
| 13 |
var SelectControl = wp.components.SelectControl; |
| 14 |
var ToggleControl = wp.components.ToggleControl; |
| 15 |
var TextControl = wp.components.TextControl; |
| 16 |
var Button = wp.components.Button; |
| 17 |
|
| 18 |
var _tc, _tvf; |
| 19 |
Object.defineProperty(window, '_tc', { get: function () { return _tc || (_tc = window.bkbgTypographyControl); } }); |
| 20 |
Object.defineProperty(window, '_tvf', { get: function () { return _tvf || (_tvf = window.bkbgTypoCssVars); } }); |
| 21 |
function getTypoControl(label, key, attrs, setA) { return _tc(label, key, attrs, setA); } |
| 22 |
function getTypoCssVars(attrs) { |
| 23 |
var v = {}; |
| 24 |
_tvf(v, 'headingTypo', attrs, '--bkvh-hd-'); |
| 25 |
_tvf(v, 'subTypo', attrs, '--bkvh-sb-'); |
| 26 |
_tvf(v, 'eyebrowTypo', attrs, '--bkvh-ey-'); |
| 27 |
_tvf(v, 'ctaTypo', attrs, '--bkvh-ct-'); |
| 28 |
return v; |
| 29 |
} |
| 30 |
|
| 31 |
function wrapStyle(a) { |
| 32 |
var s = getTypoCssVars(a); |
| 33 |
s['--bkbg-vh-bg'] = a.bgColor; |
| 34 |
s['--bkbg-vh-heading-c'] = a.headingColor; |
| 35 |
s['--bkbg-vh-sub-c'] = a.subColor; |
| 36 |
s['--bkbg-vh-eyebrow-c'] = a.eyebrowColor; |
| 37 |
s['--bkbg-vh-accent'] = a.accentColor; |
| 38 |
s['--bkbg-vh-btn-bg'] = a.btnBg; |
| 39 |
s['--bkbg-vh-btn-text'] = a.btnText; |
| 40 |
s['--bkbg-vh-btn2-bg'] = a.btn2Bg; |
| 41 |
s['--bkbg-vh-btn2-text'] = a.btn2Text; |
| 42 |
s['--bkbg-vh-btn2-border'] = a.btn2Border; |
| 43 |
s['--bkbg-vh-video-border'] = a.videoBorder; |
| 44 |
s['--bkbg-vh-cta-r'] = a.ctaRadius + 'px'; |
| 45 |
s['--bkbg-vh-pt'] = a.paddingTop + 'px'; |
| 46 |
s['--bkbg-vh-pb'] = a.paddingBottom + 'px'; |
| 47 |
s['--bkbg-vh-max-w'] = a.maxWidth + 'px'; |
| 48 |
s['--bkbg-vh-video-r'] = a.videoRadius + 'px'; |
| 49 |
return s; |
| 50 |
} |
| 51 |
|
| 52 |
var ASPECT_MAP = { '16-9': '56.25%', '4-3': '75%', '21-9': '42.86%' }; |
| 53 |
|
| 54 |
registerBlockType('blockenberg/video-hero', { |
| 55 |
title: __('Video Hero', 'blockenberg'), |
| 56 |
icon: 'video-alt3', |
| 57 |
category: 'bkbg-layout', |
| 58 |
|
| 59 |
edit: function (props) { |
| 60 |
var a = props.attributes; |
| 61 |
var set = props.setAttributes; |
| 62 |
|
| 63 |
var styleOptions = [ |
| 64 |
{ label: __('Dark', 'blockenberg'), value: 'dark' }, |
| 65 |
{ label: __('Light', 'blockenberg'), value: 'light' }, |
| 66 |
{ label: __('Gradient', 'blockenberg'), value: 'gradient' }, |
| 67 |
]; |
| 68 |
var layoutOptions = [ |
| 69 |
{ label: __('Video below content', 'blockenberg'), value: 'below' }, |
| 70 |
{ label: __('Video beside content', 'blockenberg'), value: 'side' }, |
| 71 |
]; |
| 72 |
var aspectOptions = [ |
| 73 |
{ label: __('16:9 (Widescreen)', 'blockenberg'), value: '16-9' }, |
| 74 |
{ label: __('4:3', 'blockenberg'), value: '4-3' }, |
| 75 |
{ label: __('21:9 (Cinematic)', 'blockenberg'), value: '21-9' }, |
| 76 |
]; |
| 77 |
var alignOptions = [ |
| 78 |
{ label: __('Center', 'blockenberg'), value: 'center' }, |
| 79 |
{ label: __('Left', 'blockenberg'), value: 'left' }, |
| 80 |
]; |
| 81 |
|
| 82 |
function isYoutube(url) { return url && (url.includes('youtube.com') || url.includes('youtu.be')); } |
| 83 |
function isVimeo(url) { return url && url.includes('vimeo.com'); } |
| 84 |
|
| 85 |
function renderVideoPreview() { |
| 86 |
var padPct = ASPECT_MAP[a.aspectRatio] || '56.25%'; |
| 87 |
var shadowStyle = a.videoShadow ? { boxShadow: '0 24px 64px rgba(0,0,0,0.25)' } : {}; |
| 88 |
return el('div', { |
| 89 |
className: 'bkbg-vh-video-wrap bkbg-vh-video--' + a.aspectRatio, |
| 90 |
style: Object.assign({ borderRadius: a.videoRadius + 'px' }, shadowStyle, { border: '1px solid ' + a.videoBorder }) |
| 91 |
}, |
| 92 |
el('div', { className: 'bkbg-vh-video-inner', style: { paddingBottom: padPct, position: 'relative' } }, |
| 93 |
a.videoUrl && (isYoutube(a.videoUrl) || isVimeo(a.videoUrl)) |
| 94 |
? el('div', { className: 'bkbg-vh-video-embed', style: { position: 'absolute', inset: 0 } }, |
| 95 |
el('div', { style: { background: '#000', width: '100%', height: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#fff', fontSize: '14px', borderRadius: a.videoRadius + 'px' } }, |
| 96 |
el('span', { style: { opacity: .6 } }, '▶ ' + (isYoutube(a.videoUrl) ? 'YouTube' : 'Vimeo') + ' video will play on frontend') |
| 97 |
) |
| 98 |
) |
| 99 |
: el('div', { style: { position: 'absolute', inset: 0, background: 'rgba(255,255,255,.06)', display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: '12px', borderRadius: a.videoRadius + 'px' } }, |
| 100 |
el('span', { className: 'dashicons dashicons-video-alt3', style: { fontSize: '48px', width: '48px', height: '48px', color: a.accentColor } }), |
| 101 |
el('span', { style: { color: 'rgba(255,255,255,.5)', fontSize: '13px' } }, a.videoUrl ? a.videoUrl.substring(0, 40) + '…' : __('No video URL set', 'blockenberg')) |
| 102 |
), |
| 103 |
a.showPlayButton && el('div', { className: 'bkbg-vh-play-btn', style: { position: 'absolute', top: '50%', left: '50%', transform: 'translate(-50%,-50%)', width: '64px', height: '64px', background: a.accentColor, borderRadius: '50%', display: 'flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer' } }, |
| 104 |
el('span', { style: { color:'#fff', fontSize:'24px', marginLeft:'4px' } }, '▶') |
| 105 |
) |
| 106 |
) |
| 107 |
); |
| 108 |
} |
| 109 |
|
| 110 |
var blockProps = useBlockProps({ |
| 111 |
className: 'bkbg-vh-wrap bkbg-vh-style--' + a.style + ' bkbg-vh-layout--' + a.videoLayout + ' bkbg-vh-align--' + a.contentAlign, |
| 112 |
style: wrapStyle(a) |
| 113 |
}); |
| 114 |
|
| 115 |
var inspector = el(InspectorControls, {}, |
| 116 |
el(PanelBody, { title: __('Content', 'blockenberg'), initialOpen: true }, |
| 117 |
el(ToggleControl, { |
| 118 |
label: __('Show Eyebrow', 'blockenberg'), |
| 119 |
checked: a.showEyebrow, |
| 120 |
__nextHasNoMarginBottom: true, |
| 121 |
onChange: function (v) { set({ showEyebrow: v }); } |
| 122 |
}), |
| 123 |
a.showEyebrow && el(TextControl, { |
| 124 |
label: __('Eyebrow Text', 'blockenberg'), |
| 125 |
value: a.eyebrow, |
| 126 |
onChange: function (v) { set({ eyebrow: v }); } |
| 127 |
}), |
| 128 |
el(ToggleControl, { |
| 129 |
label: __('Show Subheading', 'blockenberg'), |
| 130 |
checked: a.showSubheading, |
| 131 |
__nextHasNoMarginBottom: true, |
| 132 |
onChange: function (v) { set({ showSubheading: v }); } |
| 133 |
}), |
| 134 |
el(ToggleControl, { |
| 135 |
label: __('Show Primary CTA', 'blockenberg'), |
| 136 |
checked: a.showCta, |
| 137 |
__nextHasNoMarginBottom: true, |
| 138 |
onChange: function (v) { set({ showCta: v }); } |
| 139 |
}), |
| 140 |
a.showCta && el(TextControl, { |
| 141 |
label: __('CTA Text', 'blockenberg'), |
| 142 |
value: a.ctaText, |
| 143 |
onChange: function (v) { set({ ctaText: v }); } |
| 144 |
}), |
| 145 |
a.showCta && el(TextControl, { |
| 146 |
label: __('CTA URL', 'blockenberg'), |
| 147 |
value: a.ctaUrl, |
| 148 |
onChange: function (v) { set({ ctaUrl: v }); } |
| 149 |
}), |
| 150 |
el(ToggleControl, { |
| 151 |
label: __('Show Secondary CTA', 'blockenberg'), |
| 152 |
checked: a.showSecondaryCta, |
| 153 |
__nextHasNoMarginBottom: true, |
| 154 |
onChange: function (v) { set({ showSecondaryCta: v }); } |
| 155 |
}), |
| 156 |
a.showSecondaryCta && el(TextControl, { |
| 157 |
label: __('Secondary Text', 'blockenberg'), |
| 158 |
value: a.ctaSecondaryText, |
| 159 |
onChange: function (v) { set({ ctaSecondaryText: v }); } |
| 160 |
}), |
| 161 |
a.showSecondaryCta && el(TextControl, { |
| 162 |
label: __('Secondary URL', 'blockenberg'), |
| 163 |
value: a.ctaSecondaryUrl, |
| 164 |
onChange: function (v) { set({ ctaSecondaryUrl: v }); } |
| 165 |
}) |
| 166 |
), |
| 167 |
el(PanelBody, { title: __('Video', 'blockenberg'), initialOpen: false }, |
| 168 |
el(TextControl, { |
| 169 |
label: __('Video URL / Embed URL', 'blockenberg'), |
| 170 |
value: a.videoUrl, |
| 171 |
onChange: function (v) { set({ videoUrl: v }); }, |
| 172 |
help: __('YouTube, Vimeo, or direct embed URL', 'blockenberg') |
| 173 |
}), |
| 174 |
el('div', { style: { marginBottom: '12px' } }, |
| 175 |
el('label', { style: { display:'block', fontSize:'11px', fontWeight:'500', marginBottom:'6px', textTransform:'uppercase', letterSpacing:'.05em' } }, __('Poster / Thumbnail Image', 'blockenberg')), |
| 176 |
el(MediaUpload, { |
| 177 |
onSelect: function (m) { set({ posterUrl: m.url, posterId: m.id }); }, |
| 178 |
allowedTypes: ['image'], |
| 179 |
value: a.posterId, |
| 180 |
render: function (p) { |
| 181 |
return el('div', {}, |
| 182 |
a.posterUrl && el('img', { src: a.posterUrl, style: { width: '100%', height: '80px', objectFit: 'cover', borderRadius: '6px', marginBottom: '6px' } }), |
| 183 |
el(Button, { onClick: p.open, variant: 'secondary', isSmall: true }, a.posterUrl ? __('Change Poster', 'blockenberg') : __('Set Poster Image', 'blockenberg')) |
| 184 |
); |
| 185 |
} |
| 186 |
}) |
| 187 |
), |
| 188 |
el(SelectControl, { |
| 189 |
label: __('Video Layout', 'blockenberg'), |
| 190 |
value: a.videoLayout, |
| 191 |
options: layoutOptions, |
| 192 |
onChange: function (v) { set({ videoLayout: v }); } |
| 193 |
}), |
| 194 |
el(SelectControl, { |
| 195 |
label: __('Aspect Ratio', 'blockenberg'), |
| 196 |
value: a.aspectRatio, |
| 197 |
options: aspectOptions, |
| 198 |
onChange: function (v) { set({ aspectRatio: v }); } |
| 199 |
}), |
| 200 |
el(ToggleControl, { |
| 201 |
label: __('Show Play Button Overlay', 'blockenberg'), |
| 202 |
checked: a.showPlayButton, |
| 203 |
__nextHasNoMarginBottom: true, |
| 204 |
onChange: function (v) { set({ showPlayButton: v }); } |
| 205 |
}), |
| 206 |
el(ToggleControl, { |
| 207 |
label: __('Video Shadow', 'blockenberg'), |
| 208 |
checked: a.videoShadow, |
| 209 |
__nextHasNoMarginBottom: true, |
| 210 |
onChange: function (v) { set({ videoShadow: v }); } |
| 211 |
}), |
| 212 |
el(RangeControl, { |
| 213 |
label: __('Video Border Radius (px)', 'blockenberg'), |
| 214 |
value: a.videoRadius, |
| 215 |
onChange: function (v) { set({ videoRadius: v }); }, |
| 216 |
min: 0, |
| 217 |
max: 32 |
| 218 |
}) |
| 219 |
), |
| 220 |
el(PanelBody, { title: __('Style & Layout', 'blockenberg'), initialOpen: false }, |
| 221 |
el(SelectControl, { |
| 222 |
label: __('Section Style', 'blockenberg'), |
| 223 |
value: a.style, |
| 224 |
options: styleOptions, |
| 225 |
onChange: function (v) { set({ style: v }); } |
| 226 |
}), |
| 227 |
el(SelectControl, { |
| 228 |
label: __('Content Alignment', 'blockenberg'), |
| 229 |
value: a.contentAlign, |
| 230 |
options: alignOptions, |
| 231 |
onChange: function (v) { set({ contentAlign: v }); } |
| 232 |
}), |
| 233 |
el(RangeControl, { |
| 234 |
label: __('Max Content Width (px)', 'blockenberg'), |
| 235 |
value: a.maxWidth, |
| 236 |
onChange: function (v) { set({ maxWidth: v }); }, |
| 237 |
min: 480, |
| 238 |
max: 1200, |
| 239 |
step: 20 |
| 240 |
}), |
| 241 |
el(RangeControl, { |
| 242 |
label: __('Padding Top (px)', 'blockenberg'), |
| 243 |
value: a.paddingTop, |
| 244 |
onChange: function (v) { set({ paddingTop: v }); }, |
| 245 |
min: 0, max: 200 |
| 246 |
}), |
| 247 |
el(RangeControl, { |
| 248 |
label: __('Padding Bottom (px)', 'blockenberg'), |
| 249 |
value: a.paddingBottom, |
| 250 |
onChange: function (v) { set({ paddingBottom: v }); }, |
| 251 |
min: 0, max: 200 |
| 252 |
}) |
| 253 |
), |
| 254 |
el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false }, |
| 255 |
getTypoControl(__('Heading', 'blockenberg'), 'headingTypo', a, set), |
| 256 |
getTypoControl(__('Subheading', 'blockenberg'), 'subTypo', a, set), |
| 257 |
getTypoControl(__('Eyebrow', 'blockenberg'), 'eyebrowTypo', a, set), |
| 258 |
getTypoControl(__('CTA Button', 'blockenberg'), 'ctaTypo', a, set) |
| 259 |
), |
| 260 |
el(PanelColorSettings, { |
| 261 |
title: __('Colors', 'blockenberg'), |
| 262 |
initialOpen: false, |
| 263 |
colorSettings: [ |
| 264 |
{ label: __('Background', 'blockenberg'), value: a.bgColor, onChange: function (v) { set({ bgColor: v || '#0f172a' }); } }, |
| 265 |
{ label: __('Accent Color', 'blockenberg'), value: a.accentColor, onChange: function (v) { set({ accentColor: v || '#6c3fb5' }); } }, |
| 266 |
{ label: __('Heading', 'blockenberg'), value: a.headingColor, onChange: function (v) { set({ headingColor: v || '#ffffff' }); } }, |
| 267 |
{ label: __('Subheading', 'blockenberg'), value: a.subColor, onChange: function (v) { set({ subColor: v || 'rgba(255,255,255,0.65)' }); } }, |
| 268 |
{ label: __('Eyebrow', 'blockenberg'), value: a.eyebrowColor, onChange: function (v) { set({ eyebrowColor: v || '#a78bfa' }); } }, |
| 269 |
{ label: __('Primary Button', 'blockenberg'), value: a.btnBg, onChange: function (v) { set({ btnBg: v || '#6c3fb5' }); } }, |
| 270 |
{ label: __('Primary Button Text', 'blockenberg'), value: a.btnText, onChange: function (v) { set({ btnText: v || '#ffffff' }); } }, |
| 271 |
{ label: __('Secondary Button Text', 'blockenberg'), value: a.btn2Text, onChange: function (v) { set({ btn2Text: v || 'rgba(255,255,255,0.85)' }); } }, |
| 272 |
{ label: __('Video Border', 'blockenberg'), value: a.videoBorder, onChange: function (v) { set({ videoBorder: v || 'rgba(255,255,255,0.1)' }); } }, |
| 273 |
] |
| 274 |
}) |
| 275 |
); |
| 276 |
|
| 277 |
var canvas = el('div', blockProps, |
| 278 |
el('div', { className: 'bkbg-vh-inner' }, |
| 279 |
el('div', { className: 'bkbg-vh-content' }, |
| 280 |
a.showEyebrow && a.eyebrow && el('span', { className: 'bkbg-vh-eyebrow' }, a.eyebrow), |
| 281 |
el(RichText, { |
| 282 |
tagName: 'h1', |
| 283 |
className: 'bkbg-vh-heading', |
| 284 |
value: a.heading, |
| 285 |
onChange: function (v) { set({ heading: v }); }, |
| 286 |
placeholder: __('Enter headline…', 'blockenberg'), |
| 287 |
allowedFormats: ['core/bold', 'core/italic'] |
| 288 |
}), |
| 289 |
a.showSubheading && el(RichText, { |
| 290 |
tagName: 'p', |
| 291 |
className: 'bkbg-vh-sub', |
| 292 |
value: a.subheading, |
| 293 |
onChange: function (v) { set({ subheading: v }); }, |
| 294 |
placeholder: __('Enter subheading…', 'blockenberg'), |
| 295 |
allowedFormats: ['core/bold', 'core/italic'] |
| 296 |
}), |
| 297 |
(a.showCta || a.showSecondaryCta) && el('div', { className: 'bkbg-vh-ctas' }, |
| 298 |
a.showCta && el('a', { className: 'bkbg-vh-btn bkbg-vh-btn--primary', href: '#', onClick: function (e) { e.preventDefault(); } }, a.ctaText), |
| 299 |
a.showSecondaryCta && el('a', { className: 'bkbg-vh-btn bkbg-vh-btn--secondary', href: '#', onClick: function (e) { e.preventDefault(); } }, a.ctaSecondaryText) |
| 300 |
) |
| 301 |
), |
| 302 |
el('div', { className: 'bkbg-vh-video-col' }, |
| 303 |
renderVideoPreview() |
| 304 |
) |
| 305 |
) |
| 306 |
); |
| 307 |
|
| 308 |
return el('div', {}, inspector, canvas); |
| 309 |
}, |
| 310 |
|
| 311 |
save: function (props) { |
| 312 |
var a = props.attributes; |
| 313 |
var blockProps = useBlockProps.save({ |
| 314 |
className: 'bkbg-vh-wrap bkbg-vh-style--' + a.style + ' bkbg-vh-layout--' + a.videoLayout + ' bkbg-vh-align--' + a.contentAlign, |
| 315 |
style: wrapStyle(a) |
| 316 |
}); |
| 317 |
var padPct = ASPECT_MAP[a.aspectRatio] || '56.25%'; |
| 318 |
var shadowStyle = a.videoShadow ? { boxShadow: '0 24px 64px rgba(0,0,0,0.25)' } : {}; |
| 319 |
|
| 320 |
return el('div', blockProps, |
| 321 |
el('div', { className: 'bkbg-vh-inner' }, |
| 322 |
el('div', { className: 'bkbg-vh-content' }, |
| 323 |
a.showEyebrow && a.eyebrow && el('span', { className: 'bkbg-vh-eyebrow' }, a.eyebrow), |
| 324 |
el(RichText.Content, { tagName: 'h1', className: 'bkbg-vh-heading', value: a.heading }), |
| 325 |
a.showSubheading && el(RichText.Content, { tagName: 'p', className: 'bkbg-vh-sub', value: a.subheading }), |
| 326 |
(a.showCta || a.showSecondaryCta) && el('div', { className: 'bkbg-vh-ctas' }, |
| 327 |
a.showCta && el('a', { className: 'bkbg-vh-btn bkbg-vh-btn--primary', href: a.ctaUrl }, a.ctaText), |
| 328 |
a.showSecondaryCta && el('a', { className: 'bkbg-vh-btn bkbg-vh-btn--secondary', href: a.ctaSecondaryUrl }, a.ctaSecondaryText) |
| 329 |
) |
| 330 |
), |
| 331 |
el('div', { className: 'bkbg-vh-video-col' }, |
| 332 |
el('div', { |
| 333 |
className: 'bkbg-vh-video-wrap bkbg-vh-video--' + a.aspectRatio, |
| 334 |
style: Object.assign({ borderRadius: a.videoRadius + 'px' }, shadowStyle, { border: '1px solid ' + a.videoBorder }) |
| 335 |
}, |
| 336 |
el('div', { className: 'bkbg-vh-video-inner', style: { paddingBottom: padPct, position: 'relative' } }, |
| 337 |
el('iframe', { |
| 338 |
className: 'bkbg-vh-iframe', |
| 339 |
src: a.videoUrl, |
| 340 |
frameBorder: '0', |
| 341 |
allow: 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture', |
| 342 |
allowFullScreen: true, |
| 343 |
style: { position: 'absolute', inset: 0, width: '100%', height: '100%', borderRadius: a.videoRadius + 'px' } |
| 344 |
}), |
| 345 |
a.showPlayButton && a.posterUrl && el('div', { |
| 346 |
className: 'bkbg-vh-poster', |
| 347 |
'data-video': a.videoUrl, |
| 348 |
style: { position: 'absolute', inset: 0, cursor: 'pointer' } |
| 349 |
}, |
| 350 |
el('img', { src: a.posterUrl, alt: '', style: { width: '100%', height: '100%', objectFit: 'cover', borderRadius: a.videoRadius + 'px' } }), |
| 351 |
el('div', { className: 'bkbg-vh-play-btn' }, |
| 352 |
el('span', {}, '▶') |
| 353 |
) |
| 354 |
) |
| 355 |
) |
| 356 |
) |
| 357 |
) |
| 358 |
) |
| 359 |
); |
| 360 |
} |
| 361 |
}); |
| 362 |
}() ); |
| 363 |
|