| 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 PanelBody = wp.components.PanelBody; |
| 8 |
var PanelColorSettings = wp.blockEditor.PanelColorSettings; |
| 9 |
var SelectControl = wp.components.SelectControl; |
| 10 |
var ToggleControl = wp.components.ToggleControl; |
| 11 |
var RangeControl = wp.components.RangeControl; |
| 12 |
var TextControl = wp.components.TextControl; |
| 13 |
|
| 14 |
var _tc; function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); } |
| 15 |
var _tv; function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); } |
| 16 |
|
| 17 |
var v1Attributes = { |
| 18 |
message: { type: 'string', default: '\ud83c\udf89 Limited time offer \u2014 Save 20% today!' }, |
| 19 |
linkLabel: { type: 'string', default: 'Shop Now' }, |
| 20 |
linkUrl: { type: 'string', default: '#' }, |
| 21 |
linkNewTab: { type: 'boolean', default: false }, |
| 22 |
showLink: { type: 'boolean', default: true }, |
| 23 |
showClose: { type: 'boolean', default: true }, |
| 24 |
cookieDays: { type: 'number', default: 3 }, |
| 25 |
position: { type: 'string', default: 'top' }, |
| 26 |
bgColor: { type: 'string', default: '#6c3fb5' }, |
| 27 |
bgColor2: { type: 'string', default: '#e91e8c' }, |
| 28 |
useGradient: { type: 'boolean', default: true }, |
| 29 |
textColor: { type: 'string', default: '#ffffff' }, |
| 30 |
fontSize: { type: 'number', default: 15 }, |
| 31 |
paddingV: { type: 'number', default: 12 }, |
| 32 |
animation: { type: 'string', default: 'slideDown' }, |
| 33 |
fontWeight: { type: 'number', default: 400 }, |
| 34 |
lineHeight: { type: 'number', default: 1.5 } |
| 35 |
}; |
| 36 |
|
| 37 |
registerBlockType( 'blockenberg/promo-banner', { |
| 38 |
deprecated: [{ |
| 39 |
attributes: v1Attributes, |
| 40 |
save: function (props) { |
| 41 |
var attrs = props.attributes; |
| 42 |
var RichText = wp.blockEditor.RichText; |
| 43 |
var bg = attrs.useGradient |
| 44 |
? 'linear-gradient(90deg, ' + attrs.bgColor + ', ' + attrs.bgColor2 + ')' |
| 45 |
: attrs.bgColor; |
| 46 |
return el( 'div', { |
| 47 |
className: 'bkpb-wrap bkpb-pos-' + attrs.position, |
| 48 |
style: { |
| 49 |
'--bkpb-bg': bg, |
| 50 |
'--bkpb-text': attrs.textColor, |
| 51 |
'--bkpb-pv': attrs.paddingV + 'px', |
| 52 |
'--bkpb-fs': attrs.fontSize + 'px', |
| 53 |
'--bkpb-fw': attrs.fontWeight, |
| 54 |
'--bkpb-lh': attrs.lineHeight |
| 55 |
}, |
| 56 |
'data-cookie': attrs.cookieDays, |
| 57 |
'data-animation': attrs.animation |
| 58 |
}, |
| 59 |
el( RichText.Content, { tagName: 'span', className: 'bkpb-message', value: attrs.message } ), |
| 60 |
attrs.showLink && el( 'a', { |
| 61 |
className: 'bkpb-btn', |
| 62 |
href: attrs.linkUrl, |
| 63 |
target: attrs.linkNewTab ? '_blank' : '_self', |
| 64 |
rel: attrs.linkNewTab ? 'noopener noreferrer' : null |
| 65 |
}, attrs.linkLabel ), |
| 66 |
attrs.showClose && el( 'button', { className: 'bkpb-close', 'aria-label': 'Close' }, '\u00d7' ) |
| 67 |
); |
| 68 |
} |
| 69 |
}], |
| 70 |
edit: function ( props ) { |
| 71 |
var attrs = props.attributes; |
| 72 |
var setAttr = props.setAttributes; |
| 73 |
var TC = getTypoControl(); |
| 74 |
|
| 75 |
var bg = attrs.useGradient |
| 76 |
? 'linear-gradient(90deg, ' + attrs.bgColor + ', ' + attrs.bgColor2 + ')' |
| 77 |
: attrs.bgColor; |
| 78 |
|
| 79 |
var wrapStyle = (function () { |
| 80 |
var _tv = getTypoCssVars(); |
| 81 |
var s = { |
| 82 |
'--bkpb-bg': bg, |
| 83 |
'--bkpb-text': attrs.textColor, |
| 84 |
'--bkpb-pv': attrs.paddingV + 'px' |
| 85 |
}; |
| 86 |
if (_tv) { |
| 87 |
Object.assign(s, _tv(attrs.msgTypo || {}, '--bkpb-msg-')); |
| 88 |
} |
| 89 |
return s; |
| 90 |
})(); |
| 91 |
|
| 92 |
return el( 'div', null, |
| 93 |
el( InspectorControls, null, |
| 94 |
el( PanelBody, { title: __( 'Content', 'blockenberg' ), initialOpen: true }, |
| 95 |
el( ToggleControl, { |
| 96 |
label: __( 'Show Button / Link', 'blockenberg' ), |
| 97 |
checked: attrs.showLink, |
| 98 |
onChange: function (v) { setAttr({ showLink: v }); }, |
| 99 |
__nextHasNoMarginBottom: true |
| 100 |
} ), |
| 101 |
attrs.showLink && el( TextControl, { |
| 102 |
label: __( 'Button Label', 'blockenberg' ), |
| 103 |
value: attrs.linkLabel, |
| 104 |
onChange: function (v) { setAttr({ linkLabel: v }); } |
| 105 |
} ), |
| 106 |
attrs.showLink && el( TextControl, { |
| 107 |
label: __( 'Button URL', 'blockenberg' ), |
| 108 |
value: attrs.linkUrl, |
| 109 |
onChange: function (v) { setAttr({ linkUrl: v }); } |
| 110 |
} ), |
| 111 |
attrs.showLink && el( ToggleControl, { |
| 112 |
label: __( 'Open in New Tab', 'blockenberg' ), |
| 113 |
checked: attrs.linkNewTab, |
| 114 |
onChange: function (v) { setAttr({ linkNewTab: v }); }, |
| 115 |
__nextHasNoMarginBottom: true |
| 116 |
} ), |
| 117 |
el( ToggleControl, { |
| 118 |
label: __( 'Show Close Button', 'blockenberg' ), |
| 119 |
checked: attrs.showClose, |
| 120 |
onChange: function (v) { setAttr({ showClose: v }); }, |
| 121 |
__nextHasNoMarginBottom: true |
| 122 |
} ), |
| 123 |
attrs.showClose && el( RangeControl, { |
| 124 |
label: __( 'Remember Close (days)', 'blockenberg' ), |
| 125 |
value: attrs.cookieDays, min: 0, max: 30, |
| 126 |
onChange: function (v) { setAttr({ cookieDays: v }); } |
| 127 |
} ) |
| 128 |
), |
| 129 |
el( PanelBody, { title: __( 'Appearance', 'blockenberg' ), initialOpen: false }, |
| 130 |
el( SelectControl, { |
| 131 |
label: __( 'Position', 'blockenberg' ), |
| 132 |
value: attrs.position, |
| 133 |
options: [ |
| 134 |
{ label: 'Top Fixed', value: 'top' }, |
| 135 |
{ label: 'Bottom Fixed', value: 'bottom' }, |
| 136 |
{ label: 'Inline', value: 'inline' } |
| 137 |
], |
| 138 |
onChange: function (v) { setAttr({ position: v }); } |
| 139 |
} ), |
| 140 |
el( SelectControl, { |
| 141 |
label: __( 'Entrance Animation', 'blockenberg' ), |
| 142 |
value: attrs.animation, |
| 143 |
options: [ |
| 144 |
{ label: 'Slide Down', value: 'slideDown' }, |
| 145 |
{ label: 'Fade In', value: 'fadeIn' }, |
| 146 |
{ label: 'None', value: 'none' } |
| 147 |
], |
| 148 |
onChange: function (v) { setAttr({ animation: v }); } |
| 149 |
} ), |
| 150 |
el( RangeControl, { |
| 151 |
label: __( 'Vertical Padding (px)', 'blockenberg' ), |
| 152 |
value: attrs.paddingV, min: 6, max: 32, |
| 153 |
onChange: function (v) { setAttr({ paddingV: v }); } |
| 154 |
} ), |
| 155 |
el( ToggleControl, { |
| 156 |
label: __( 'Use Gradient Background', 'blockenberg' ), |
| 157 |
checked: attrs.useGradient, |
| 158 |
onChange: function (v) { setAttr({ useGradient: v }); }, |
| 159 |
__nextHasNoMarginBottom: true |
| 160 |
} ) |
| 161 |
), |
| 162 |
|
| 163 |
el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false }, |
| 164 |
TC && el(TC, { label: __('Message', 'blockenberg'), value: attrs.msgTypo || {}, onChange: function(v) { setAttr({ msgTypo: v }); } }) |
| 165 |
), |
| 166 |
el( PanelBody, { title: __( 'Colors', 'blockenberg' ), initialOpen: false }, |
| 167 |
el( PanelColorSettings, { |
| 168 |
title: __( 'Colors', 'blockenberg' ), |
| 169 |
colorSettings: [ |
| 170 |
{ value: attrs.bgColor, onChange: function(v){setAttr({bgColor:v||'#6c3fb5'});}, label: __('Background / Gradient Start') }, |
| 171 |
{ value: attrs.bgColor2, onChange: function(v){setAttr({bgColor2:v||'#e91e8c'});}, label: __('Gradient End') }, |
| 172 |
{ value: attrs.textColor, onChange: function(v){setAttr({textColor:v||'#ffffff'});}, label: __('Text Color') } |
| 173 |
] |
| 174 |
} ) |
| 175 |
) |
| 176 |
), |
| 177 |
el( 'div', { |
| 178 |
className: 'bkpb-wrap bkpb-pos-' + attrs.position, |
| 179 |
style: wrapStyle |
| 180 |
}, |
| 181 |
el( RichText, { |
| 182 |
tagName: 'span', |
| 183 |
className: 'bkpb-message', |
| 184 |
value: attrs.message, |
| 185 |
onChange: function (v) { setAttr({ message: v }); }, |
| 186 |
placeholder: __( 'Your announcement text…', 'blockenberg' ) |
| 187 |
} ), |
| 188 |
attrs.showLink && el( 'a', { |
| 189 |
className: 'bkpb-btn', |
| 190 |
href: attrs.linkUrl, |
| 191 |
target: attrs.linkNewTab ? '_blank' : '_self' |
| 192 |
}, attrs.linkLabel ), |
| 193 |
attrs.showClose && el( 'button', { |
| 194 |
className: 'bkpb-close', |
| 195 |
'aria-label': 'Close' |
| 196 |
}, '×' ) |
| 197 |
) |
| 198 |
); |
| 199 |
}, |
| 200 |
save: function ( props ) { |
| 201 |
var attrs = props.attributes; |
| 202 |
var bg = attrs.useGradient |
| 203 |
? 'linear-gradient(90deg, ' + attrs.bgColor + ', ' + attrs.bgColor2 + ')' |
| 204 |
: attrs.bgColor; |
| 205 |
return el( 'div', { |
| 206 |
className: 'bkpb-wrap bkpb-pos-' + attrs.position, |
| 207 |
style: (function () { |
| 208 |
var _tv = getTypoCssVars(); |
| 209 |
var s = { |
| 210 |
'--bkpb-bg': bg, |
| 211 |
'--bkpb-text': attrs.textColor, |
| 212 |
'--bkpb-pv': attrs.paddingV + 'px' |
| 213 |
}; |
| 214 |
if (_tv) { |
| 215 |
Object.assign(s, _tv(attrs.msgTypo || {}, '--bkpb-msg-')); |
| 216 |
} |
| 217 |
return s; |
| 218 |
})(), |
| 219 |
'data-cookie': attrs.cookieDays, |
| 220 |
'data-animation': attrs.animation |
| 221 |
}, |
| 222 |
el( RichText.Content, { tagName: 'span', className: 'bkpb-message', value: attrs.message } ), |
| 223 |
attrs.showLink && el( 'a', { |
| 224 |
className: 'bkpb-btn', |
| 225 |
href: attrs.linkUrl, |
| 226 |
target: attrs.linkNewTab ? '_blank' : '_self', |
| 227 |
rel: attrs.linkNewTab ? 'noopener noreferrer' : null |
| 228 |
}, attrs.linkLabel ), |
| 229 |
attrs.showClose && el( 'button', { className: 'bkpb-close', 'aria-label': 'Close' }, '×' ) |
| 230 |
); |
| 231 |
} |
| 232 |
} ); |
| 233 |
} )(); |
| 234 |
|