| 1 |
( function () { |
| 2 |
var el = wp.element.createElement; |
| 3 |
var Fragment = wp.element.Fragment; |
| 4 |
var registerBlockType = wp.blocks.registerBlockType; |
| 5 |
var __ = wp.i18n.__; |
| 6 |
var InspectorControls = wp.blockEditor.InspectorControls; |
| 7 |
var PanelColorSettings = wp.blockEditor.PanelColorSettings; |
| 8 |
var RichText = wp.blockEditor.RichText; |
| 9 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 10 |
var PanelBody = wp.components.PanelBody; |
| 11 |
var RangeControl = wp.components.RangeControl; |
| 12 |
var SelectControl = wp.components.SelectControl; |
| 13 |
var TextControl = wp.components.TextControl; |
| 14 |
var ToggleControl = wp.components.ToggleControl; |
| 15 |
var _tc; function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); } |
| 16 |
var _tv; function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); } |
| 17 |
|
| 18 |
var v1Attributes = { |
| 19 |
"content":{"type":"string","default":"This is the full content that will be hidden behind the read more button. Add as much text as you like here \u2014 the block will collapse it to the preview height and show a gradient fade. The user can expand the full text with a click."}, |
| 20 |
"collapsedHeight":{"type":"number","default":180}, |
| 21 |
"readMoreLabel":{"type":"string","default":"Read more"}, |
| 22 |
"showLessLabel":{"type":"string","default":"Show less"}, |
| 23 |
"buttonStyle":{"type":"string","default":"solid"}, |
| 24 |
"buttonAlign":{"type":"string","default":"center"}, |
| 25 |
"showIcon":{"type":"boolean","default":true}, |
| 26 |
"animateDuration":{"type":"number","default":400}, |
| 27 |
"fadeHeight":{"type":"number","default":80}, |
| 28 |
"fadeColor":{"type":"string","default":"#ffffff"}, |
| 29 |
"borderRadius":{"type":"number","default":8}, |
| 30 |
"fontSize":{"type":"number","default":16}, |
| 31 |
"lineHeight":{"type":"number","default":1.7}, |
| 32 |
"textColor":{"type":"string","default":"#374151"}, |
| 33 |
"bgColor":{"type":"string","default":""}, |
| 34 |
"btnBg":{"type":"string","default":"#6c3fb5"}, |
| 35 |
"btnColor":{"type":"string","default":"#ffffff"}, |
| 36 |
"btnBorderColor":{"type":"string","default":"#6c3fb5"}, |
| 37 |
"paddingTop":{"type":"number","default":0}, |
| 38 |
"paddingBottom":{"type":"number","default":0} |
| 39 |
}; |
| 40 |
|
| 41 |
registerBlockType('blockenberg/read-more', { |
| 42 |
|
| 43 |
edit: function (props) { |
| 44 |
var attrs = props.attributes; |
| 45 |
var setAttr = props.setAttributes; |
| 46 |
var TC = getTypoControl(); |
| 47 |
|
| 48 |
var contentStyle = { |
| 49 |
color: attrs.textColor, |
| 50 |
position: 'relative' |
| 51 |
}; |
| 52 |
|
| 53 |
// Editor preview: show gradient overlay at bottom to simulate collapsed state |
| 54 |
var previewContentStyle = Object.assign({}, contentStyle, { |
| 55 |
maxHeight: attrs.collapsedHeight + 'px', |
| 56 |
overflow: 'hidden', |
| 57 |
position: 'relative' |
| 58 |
}); |
| 59 |
|
| 60 |
var btnStyle = {}; |
| 61 |
var bs = attrs.buttonStyle; |
| 62 |
if (bs === 'solid') { |
| 63 |
btnStyle = { |
| 64 |
background: attrs.btnBg, |
| 65 |
color: attrs.btnColor, |
| 66 |
border: 'none', |
| 67 |
borderRadius: attrs.borderRadius + 'px', |
| 68 |
padding: '10px 24px', |
| 69 |
cursor: 'pointer', |
| 70 |
fontWeight: 600, |
| 71 |
fontSize: '14px', |
| 72 |
display: 'inline-flex', |
| 73 |
alignItems: 'center', |
| 74 |
gap: '6px' |
| 75 |
}; |
| 76 |
} else if (bs === 'outlined') { |
| 77 |
btnStyle = { |
| 78 |
background: 'transparent', |
| 79 |
color: attrs.btnBg, |
| 80 |
border: '2px solid ' + attrs.btnBorderColor, |
| 81 |
borderRadius: attrs.borderRadius + 'px', |
| 82 |
padding: '8px 22px', |
| 83 |
cursor: 'pointer', |
| 84 |
fontWeight: 600, |
| 85 |
fontSize: '14px', |
| 86 |
display: 'inline-flex', |
| 87 |
alignItems: 'center', |
| 88 |
gap: '6px' |
| 89 |
}; |
| 90 |
} else { |
| 91 |
// link |
| 92 |
btnStyle = { |
| 93 |
background: 'transparent', |
| 94 |
color: attrs.btnBg, |
| 95 |
border: 'none', |
| 96 |
padding: '4px 0', |
| 97 |
cursor: 'pointer', |
| 98 |
fontWeight: 600, |
| 99 |
fontSize: '14px', |
| 100 |
textDecoration: 'underline', |
| 101 |
display: 'inline-flex', |
| 102 |
alignItems: 'center', |
| 103 |
gap: '6px' |
| 104 |
}; |
| 105 |
} |
| 106 |
|
| 107 |
var blockProps = useBlockProps((function() { |
| 108 |
var _tvFn = getTypoCssVars(); |
| 109 |
var s = {}; |
| 110 |
if (attrs.paddingTop) s.paddingTop = attrs.paddingTop + 'px'; |
| 111 |
if (attrs.paddingBottom) s.paddingBottom = attrs.paddingBottom + 'px'; |
| 112 |
if (attrs.bgColor) s.background = attrs.bgColor; |
| 113 |
if (_tvFn) { |
| 114 |
Object.assign(s, _tvFn(attrs.contentTypo || {}, '--bkrm-ct-')); |
| 115 |
} |
| 116 |
return { className: 'bkrm-wrap', style: s }; |
| 117 |
})()); |
| 118 |
|
| 119 |
return el(Fragment, null, |
| 120 |
el(InspectorControls, null, |
| 121 |
|
| 122 |
el(PanelBody, { title: __('Content', 'blockenberg'), initialOpen: true }, |
| 123 |
el('p', { style: { color: '#6b7280', fontSize: '12px', margin: '0 0 12px' } }, |
| 124 |
__('Edit the text directly in the block. Use the settings below to control how it collapses.', 'blockenberg') |
| 125 |
), |
| 126 |
el(RangeControl, { |
| 127 |
label: __('Collapsed height (px)', 'blockenberg'), |
| 128 |
value: attrs.collapsedHeight, min: 60, max: 600, |
| 129 |
onChange: function (v) { setAttr({ collapsedHeight: v }); } |
| 130 |
}), |
| 131 |
el(RangeControl, { |
| 132 |
label: __('Fade gradient height (px)', 'blockenberg'), |
| 133 |
value: attrs.fadeHeight, min: 20, max: 200, |
| 134 |
onChange: function (v) { setAttr({ fadeHeight: v }); } |
| 135 |
}) |
| 136 |
), |
| 137 |
|
| 138 |
el(PanelBody, { title: __('Button', 'blockenberg'), initialOpen: true }, |
| 139 |
el(TextControl, { |
| 140 |
label: __('Read more label', 'blockenberg'), |
| 141 |
value: attrs.readMoreLabel, |
| 142 |
onChange: function (v) { setAttr({ readMoreLabel: v }); } |
| 143 |
}), |
| 144 |
el(TextControl, { |
| 145 |
label: __('Show less label', 'blockenberg'), |
| 146 |
value: attrs.showLessLabel, |
| 147 |
onChange: function (v) { setAttr({ showLessLabel: v }); } |
| 148 |
}), |
| 149 |
el(SelectControl, { |
| 150 |
label: __('Button style', 'blockenberg'), |
| 151 |
value: attrs.buttonStyle, |
| 152 |
options: [ |
| 153 |
{ label: 'Solid', value: 'solid' }, |
| 154 |
{ label: 'Outlined', value: 'outlined' }, |
| 155 |
{ label: 'Link', value: 'link' } |
| 156 |
], |
| 157 |
onChange: function (v) { setAttr({ buttonStyle: v }); } |
| 158 |
}), |
| 159 |
el(SelectControl, { |
| 160 |
label: __('Button alignment', 'blockenberg'), |
| 161 |
value: attrs.buttonAlign, |
| 162 |
options: [ |
| 163 |
{ label: 'Left', value: 'left' }, |
| 164 |
{ label: 'Center', value: 'center' }, |
| 165 |
{ label: 'Right', value: 'right' } |
| 166 |
], |
| 167 |
onChange: function (v) { setAttr({ buttonAlign: v }); } |
| 168 |
}), |
| 169 |
el(ToggleControl, { |
| 170 |
label: __('Show chevron icon', 'blockenberg'), |
| 171 |
checked: attrs.showIcon, |
| 172 |
onChange: function (v) { setAttr({ showIcon: v }); }, |
| 173 |
__nextHasNoMarginBottom: true |
| 174 |
}), |
| 175 |
el(RangeControl, { |
| 176 |
label: __('Border radius (px)', 'blockenberg'), |
| 177 |
value: attrs.borderRadius, min: 0, max: 50, |
| 178 |
onChange: function (v) { setAttr({ borderRadius: v }); } |
| 179 |
}), |
| 180 |
el(RangeControl, { |
| 181 |
label: __('Animate duration (ms)', 'blockenberg'), |
| 182 |
value: attrs.animateDuration, min: 100, max: 1200, step: 50, |
| 183 |
onChange: function (v) { setAttr({ animateDuration: v }); } |
| 184 |
}) |
| 185 |
), |
| 186 |
|
| 187 |
el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false }, |
| 188 |
TC && el(TC, { label: __('Content', 'blockenberg'), value: attrs.contentTypo || {}, onChange: function(v) { setAttr({ contentTypo: v }); } }) |
| 189 |
), |
| 190 |
|
| 191 |
el(PanelBody, { title: __('Layout', 'blockenberg'), initialOpen: false }, |
| 192 |
el(RangeControl, { |
| 193 |
label: __('Padding Top (px)', 'blockenberg'), |
| 194 |
value: attrs.paddingTop, min: 0, max: 200, |
| 195 |
onChange: function (v) { setAttr({ paddingTop: v }); } |
| 196 |
}), |
| 197 |
el(RangeControl, { |
| 198 |
label: __('Padding Bottom (px)', 'blockenberg'), |
| 199 |
value: attrs.paddingBottom, min: 0, max: 200, |
| 200 |
onChange: function (v) { setAttr({ paddingBottom: v }); } |
| 201 |
}) |
| 202 |
), |
| 203 |
|
| 204 |
el(PanelColorSettings, { |
| 205 |
title: __('Colors', 'blockenberg'), |
| 206 |
initialOpen: false, |
| 207 |
colorSettings: [ |
| 208 |
{ label: __('Text Color', 'blockenberg'), value: attrs.textColor, onChange: function (v) { setAttr({ textColor: v || '#374151' }); } }, |
| 209 |
{ label: __('Fade / Background', 'blockenberg'), value: attrs.fadeColor, onChange: function (v) { setAttr({ fadeColor: v || '#ffffff' }); } }, |
| 210 |
{ label: __('Button Background', 'blockenberg'), value: attrs.btnBg, onChange: function (v) { setAttr({ btnBg: v || '#6c3fb5' }); } }, |
| 211 |
{ label: __('Button Text', 'blockenberg'), value: attrs.btnColor, onChange: function (v) { setAttr({ btnColor: v || '#ffffff' }); } }, |
| 212 |
{ label: __('Button Border', 'blockenberg'), value: attrs.btnBorderColor, onChange: function (v) { setAttr({ btnBorderColor: v || '#6c3fb5' }); } }, |
| 213 |
{ label: __('Section Background', 'blockenberg'), value: attrs.bgColor, onChange: function (v) { setAttr({ bgColor: v || '' }); } } |
| 214 |
] |
| 215 |
}) |
| 216 |
), |
| 217 |
|
| 218 |
el('div', blockProps, |
| 219 |
// Content area (editor shows trimmed preview) |
| 220 |
el('div', { |
| 221 |
className: 'bkrm-content', |
| 222 |
style: previewContentStyle |
| 223 |
}, |
| 224 |
el(RichText, { |
| 225 |
tagName: 'div', |
| 226 |
className: 'bkrm-text', |
| 227 |
value: attrs.content, |
| 228 |
onChange: function (v) { setAttr({ content: v }); }, |
| 229 |
placeholder: __('Add your full content here…', 'blockenberg'), |
| 230 |
style: { color: attrs.textColor } |
| 231 |
}), |
| 232 |
// Gradient fade overlay preview |
| 233 |
el('div', { |
| 234 |
className: 'bkrm-fade', |
| 235 |
style: { |
| 236 |
position: 'absolute', |
| 237 |
bottom: 0, |
| 238 |
left: 0, |
| 239 |
right: 0, |
| 240 |
height: attrs.fadeHeight + 'px', |
| 241 |
background: 'linear-gradient(to bottom, transparent, ' + (attrs.fadeColor || '#ffffff') + ')', |
| 242 |
pointerEvents: 'none' |
| 243 |
} |
| 244 |
}) |
| 245 |
), |
| 246 |
el('div', { |
| 247 |
className: 'bkrm-btn-wrap', |
| 248 |
style: { textAlign: attrs.buttonAlign, marginTop: '16px' } |
| 249 |
}, |
| 250 |
el('button', { className: 'bkrm-btn', style: btnStyle, type: 'button' }, |
| 251 |
attrs.readMoreLabel, |
| 252 |
attrs.showIcon && el('span', { className: 'bkrm-chevron', style: { fontSize: '12px', lineHeight: 1 } }, ' ▼') |
| 253 |
) |
| 254 |
) |
| 255 |
) |
| 256 |
); |
| 257 |
}, |
| 258 |
|
| 259 |
deprecated: [{ |
| 260 |
attributes: v1Attributes, |
| 261 |
save: function (props) { |
| 262 |
var a = props.attributes; |
| 263 |
var RichText = wp.blockEditor.RichText; |
| 264 |
|
| 265 |
var wrapStyle = { |
| 266 |
paddingTop: a.paddingTop + 'px', |
| 267 |
paddingBottom: a.paddingBottom + 'px', |
| 268 |
'--bkrm-collapsed': a.collapsedHeight + 'px', |
| 269 |
'--bkrm-fade-h': a.fadeHeight + 'px', |
| 270 |
'--bkrm-fade-c': a.fadeColor || '#ffffff', |
| 271 |
'--bkrm-dur': a.animateDuration + 'ms' |
| 272 |
}; |
| 273 |
if (a.bgColor) wrapStyle.background = a.bgColor; |
| 274 |
|
| 275 |
var contentStyle = { |
| 276 |
fontSize: a.fontSize + 'px', |
| 277 |
lineHeight: a.lineHeight, |
| 278 |
color: a.textColor |
| 279 |
}; |
| 280 |
|
| 281 |
var bs = a.buttonStyle; |
| 282 |
var btnStyle = {}; |
| 283 |
if (bs === 'solid') { |
| 284 |
btnStyle = { background: a.btnBg, color: a.btnColor, borderRadius: a.borderRadius + 'px' }; |
| 285 |
} else if (bs === 'outlined') { |
| 286 |
btnStyle = { color: a.btnBg, borderColor: a.btnBorderColor, borderRadius: a.borderRadius + 'px' }; |
| 287 |
} else { |
| 288 |
btnStyle = { color: a.btnBg }; |
| 289 |
} |
| 290 |
|
| 291 |
var blockProps = wp.blockEditor.useBlockProps.save({ className: 'bkrm-wrap', style: wrapStyle }); |
| 292 |
|
| 293 |
return el('div', blockProps, |
| 294 |
el('div', { className: 'bkrm-content bkrm-collapsed' }, |
| 295 |
el(RichText.Content, { |
| 296 |
tagName: 'div', |
| 297 |
className: 'bkrm-text', |
| 298 |
value: a.content, |
| 299 |
style: contentStyle |
| 300 |
}), |
| 301 |
el('div', { className: 'bkrm-fade', 'aria-hidden': 'true' }) |
| 302 |
), |
| 303 |
el('div', { |
| 304 |
className: 'bkrm-btn-wrap', |
| 305 |
style: { textAlign: a.buttonAlign } |
| 306 |
}, |
| 307 |
el('button', { |
| 308 |
className: 'bkrm-btn bkrm-btn--' + bs, |
| 309 |
style: btnStyle, |
| 310 |
type: 'button', |
| 311 |
'aria-expanded': 'false' |
| 312 |
}, |
| 313 |
el('span', { className: 'bkrm-label' }, a.readMoreLabel), |
| 314 |
a.showIcon && el('span', { className: 'bkrm-chevron', 'aria-hidden': 'true' }) |
| 315 |
) |
| 316 |
) |
| 317 |
); |
| 318 |
} |
| 319 |
}], |
| 320 |
|
| 321 |
save: function (props) { |
| 322 |
var a = props.attributes; |
| 323 |
|
| 324 |
var _tvFn = window.bkbgTypoCssVars; |
| 325 |
var wrapStyle = { |
| 326 |
paddingTop: a.paddingTop + 'px', |
| 327 |
paddingBottom: a.paddingBottom + 'px', |
| 328 |
'--bkrm-collapsed': a.collapsedHeight + 'px', |
| 329 |
'--bkrm-fade-h': a.fadeHeight + 'px', |
| 330 |
'--bkrm-fade-c': a.fadeColor || '#ffffff', |
| 331 |
'--bkrm-dur': a.animateDuration + 'ms' |
| 332 |
}; |
| 333 |
if (a.bgColor) wrapStyle.background = a.bgColor; |
| 334 |
if (_tvFn) { |
| 335 |
Object.assign(wrapStyle, _tvFn(a.contentTypo || {}, '--bkrm-ct-')); |
| 336 |
} |
| 337 |
|
| 338 |
var contentStyle = { |
| 339 |
color: a.textColor |
| 340 |
}; |
| 341 |
|
| 342 |
var bs = a.buttonStyle; |
| 343 |
var btnStyle = {}; |
| 344 |
if (bs === 'solid') { |
| 345 |
btnStyle = { background: a.btnBg, color: a.btnColor, borderRadius: a.borderRadius + 'px' }; |
| 346 |
} else if (bs === 'outlined') { |
| 347 |
btnStyle = { color: a.btnBg, borderColor: a.btnBorderColor, borderRadius: a.borderRadius + 'px' }; |
| 348 |
} else { |
| 349 |
btnStyle = { color: a.btnBg }; |
| 350 |
} |
| 351 |
|
| 352 |
var blockProps = wp.blockEditor.useBlockProps.save({ className: 'bkrm-wrap', style: wrapStyle }); |
| 353 |
|
| 354 |
return el('div', blockProps, |
| 355 |
el('div', { className: 'bkrm-content bkrm-collapsed' }, |
| 356 |
el(RichText.Content, { |
| 357 |
tagName: 'div', |
| 358 |
className: 'bkrm-text', |
| 359 |
value: a.content, |
| 360 |
style: contentStyle |
| 361 |
}), |
| 362 |
el('div', { className: 'bkrm-fade', 'aria-hidden': 'true' }) |
| 363 |
), |
| 364 |
el('div', { |
| 365 |
className: 'bkrm-btn-wrap', |
| 366 |
style: { textAlign: a.buttonAlign } |
| 367 |
}, |
| 368 |
el('button', { |
| 369 |
className: 'bkrm-btn bkrm-btn--' + bs, |
| 370 |
style: btnStyle, |
| 371 |
type: 'button', |
| 372 |
'aria-expanded': 'false' |
| 373 |
}, |
| 374 |
el('span', { className: 'bkrm-label' }, a.readMoreLabel), |
| 375 |
a.showIcon && el('span', { className: 'bkrm-chevron', 'aria-hidden': 'true' }) |
| 376 |
) |
| 377 |
) |
| 378 |
); |
| 379 |
} |
| 380 |
}); |
| 381 |
}() ); |
| 382 |
|