| 1 |
( function () { |
| 2 |
var el = window.wp.element.createElement; |
| 3 |
var { registerBlockType } = window.wp.blocks; |
| 4 |
var { InspectorControls, PanelColorSettings } = window.wp.blockEditor; |
| 5 |
var { PanelBody, RangeControl, SelectControl, TextControl, ToggleControl } = window.wp.components; |
| 6 |
var { __ } = window.wp.i18n; |
| 7 |
|
| 8 |
var _fctaTC, _fctaTV; |
| 9 |
function _tc() { return _fctaTC || (_fctaTC = window.bkbgTypographyControl); } |
| 10 |
function _tv() { return _fctaTV || (_fctaTV = window.bkbgTypoCssVars); } |
| 11 |
|
| 12 |
var POSITIONS = [ |
| 13 |
{label:'Bottom Right',value:'bottom-right'}, |
| 14 |
{label:'Bottom Left',value:'bottom-left'}, |
| 15 |
{label:'Bottom Center',value:'bottom-center'}, |
| 16 |
{label:'Top Right',value:'top-right'}, |
| 17 |
{label:'Top Left',value:'top-left'}, |
| 18 |
]; |
| 19 |
var ICONS = ['megaphone','admin-comments','email-alt','phone','format-chat','tickets-alt','cart','heart','star-filled','arrow-right-alt'].map(i=>({label:i,value:i})); |
| 20 |
|
| 21 |
function BtnPreview(a) { |
| 22 |
var btnStyle = { |
| 23 |
display:'inline-flex', alignItems:'center', gap:'8px', |
| 24 |
background:a.btnBg, color:a.btnColor, |
| 25 |
padding:a.paddingY+'px '+a.paddingX+'px', |
| 26 |
borderRadius:a.btnRadius+'px', |
| 27 |
boxShadow:a.btnShadow?'0 8px 24px rgba(0,0,0,0.2)':'none', |
| 28 |
textDecoration:'none', cursor:'pointer', |
| 29 |
}; |
| 30 |
return el('a',{className:'bkfcta-btn',href:a.url,style:btnStyle}, |
| 31 |
a.showIcon&&el('span',{className:'dashicons dashicons-'+a.icon,style:{fontSize:a.iconSize+'px',width:a.iconSize+'px',height:a.iconSize+'px',lineHeight:1}}), |
| 32 |
a.showLabel&&el('span',null,a.label), |
| 33 |
); |
| 34 |
} |
| 35 |
|
| 36 |
registerBlockType('blockenberg/floating-cta', { |
| 37 |
edit: function(props) { |
| 38 |
var a = props.attributes; |
| 39 |
var set = props.setAttributes; |
| 40 |
var wrapStyle = Object.assign({}, _tv()(a.typoBtn, '--bkbg-fcta-btn-')); |
| 41 |
return el('div',{ style: wrapStyle }, |
| 42 |
el(InspectorControls,null, |
| 43 |
el(PanelBody,{title:__('Button'),initialOpen:true}, |
| 44 |
el(TextControl,{label:__('Label'),value:a.label,onChange:v=>set({label:v})}), |
| 45 |
el(TextControl,{label:__('URL / Link'),value:a.url,onChange:v=>set({url:v})}), |
| 46 |
el(ToggleControl,{label:__('Open in New Tab'),checked:a.openInNew,onChange:v=>set({openInNew:v}),__nextHasNoMarginBottom:true}), |
| 47 |
el(ToggleControl,{label:__('Show Label Text'),checked:a.showLabel,onChange:v=>set({showLabel:v}),__nextHasNoMarginBottom:true}), |
| 48 |
el(ToggleControl,{label:__('Show Icon'),checked:a.showIcon,onChange:v=>set({showIcon:v}),__nextHasNoMarginBottom:true}), |
| 49 |
a.showIcon&&el(SelectControl,{label:__('Icon'),value:a.icon,options:ICONS,onChange:v=>set({icon:v})}), |
| 50 |
a.showIcon&&el(RangeControl,{label:__('Icon Size (px)'),value:a.iconSize,min:12,max:40,onChange:v=>set({iconSize:v})}), |
| 51 |
), |
| 52 |
el(PanelBody,{title:__('Position'),initialOpen:false}, |
| 53 |
el(SelectControl,{label:__('Screen Position'),value:a.position,options:POSITIONS,onChange:v=>set({position:v})}), |
| 54 |
el(RangeControl,{label:__('Offset X (px)'),value:a.offsetX,min:0,max:100,onChange:v=>set({offsetX:v})}), |
| 55 |
el(RangeControl,{label:__('Offset Y (px)'),value:a.offsetY,min:0,max:200,onChange:v=>set({offsetY:v})}), |
| 56 |
el(RangeControl,{label:__('Scroll to Show (px)'),value:a.scrollTrigger,min:0,max:2000,step:50,onChange:v=>set({scrollTrigger:v}),help:__('Show after scrolling this many pixels (0 = always visible)')}), |
| 57 |
el(RangeControl,{label:__('Z-index'),value:a.zIndex,min:100,max:100000,onChange:v=>set({zIndex:v})}), |
| 58 |
), |
| 59 |
el(PanelBody,{title:__('Style'),initialOpen:false}, |
| 60 |
el(RangeControl,{label:__('Padding X (px)'),value:a.paddingX,min:8,max:60,onChange:v=>set({paddingX:v})}), |
| 61 |
el(RangeControl,{label:__('Padding Y (px)'),value:a.paddingY,min:4,max:40,onChange:v=>set({paddingY:v})}), |
| 62 |
el(RangeControl,{label:__('Border Radius (px)'),value:a.btnRadius,min:0,max:60,onChange:v=>set({btnRadius:v})}), |
| 63 |
el(ToggleControl,{label:__('Button Shadow'),checked:a.btnShadow,onChange:v=>set({btnShadow:v}),__nextHasNoMarginBottom:true}), |
| 64 |
el(ToggleControl,{label:__('Pulsing Ring'),checked:a.pulsing,onChange:v=>set({pulsing:v}),__nextHasNoMarginBottom:true}), |
| 65 |
el(ToggleControl,{label:__('Show Dismiss (×)'),checked:a.showDismiss,onChange:v=>set({showDismiss:v}),__nextHasNoMarginBottom:true}), |
| 66 |
), |
| 67 |
|
| 68 |
el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false }, |
| 69 |
_tc()({ label: __('Button', 'blockenberg'), value: a.typoBtn, onChange: function (v) { set({ typoBtn: v }); } }) |
| 70 |
), |
| 71 |
el(PanelColorSettings,{title:__('Colors'),initialOpen:false,colorSettings:[ |
| 72 |
{label:__('Button Background'),value:a.btnBg,onChange:v=>set({btnBg:v||'#6c3fb5'})}, |
| 73 |
{label:__('Button Text'),value:a.btnColor,onChange:v=>set({btnColor:v||'#ffffff'})}, |
| 74 |
]}), |
| 75 |
), |
| 76 |
|
| 77 |
el('div',{style:{background:'#f9fafb',border:'1px dashed #c4b5fd',borderRadius:'10px',padding:'20px',textAlign:'center',color:'#6b7280',fontSize:'13px'}}, |
| 78 |
el('p',{style:{margin:'0 0 12px',fontWeight:600,color:'#6c3fb5'}},__('⚓ Floating CTA — Fixed Position on Frontend')), |
| 79 |
el('p',{style:{margin:'0 0 12px',fontSize:'12px'}},__('Position: ')+a.position+' | Scroll trigger: '+a.scrollTrigger+'px'), |
| 80 |
BtnPreview(a), |
| 81 |
), |
| 82 |
); |
| 83 |
}, |
| 84 |
|
| 85 |
save: function({attributes:a}) { |
| 86 |
var posStyle = {}; |
| 87 |
if (a.position==='bottom-right') { posStyle.bottom=a.offsetY+'px'; posStyle.right=a.offsetX+'px'; } |
| 88 |
else if (a.position==='bottom-left') { posStyle.bottom=a.offsetY+'px'; posStyle.left=a.offsetX+'px'; } |
| 89 |
else if (a.position==='bottom-center') { posStyle.bottom=a.offsetY+'px'; posStyle.left='50%'; posStyle.transform='translateX(-50%)'; } |
| 90 |
else if (a.position==='top-right') { posStyle.top=a.offsetY+'px'; posStyle.right=a.offsetX+'px'; } |
| 91 |
else if (a.position==='top-left') { posStyle.top=a.offsetY+'px'; posStyle.left=a.offsetX+'px'; } |
| 92 |
|
| 93 |
var wrapStyle = Object.assign({ position:'fixed', zIndex:a.zIndex, transition:'opacity 0.3s, transform 0.3s' }, posStyle, _tv()(a.typoBtn, '--bkbg-fcta-btn-')); |
| 94 |
|
| 95 |
return el('div',{ |
| 96 |
className:'bkfcta-wrap'+(a.pulsing?' bkfcta-pulsing':''), |
| 97 |
style:wrapStyle, |
| 98 |
'data-scroll-trigger':a.scrollTrigger, |
| 99 |
'data-dismiss':a.showDismiss?'1':'0', |
| 100 |
}, |
| 101 |
a.pulsing&&el('div',{className:'bkfcta-ring',style:{ |
| 102 |
position:'absolute', inset:0, borderRadius:a.btnRadius+'px', |
| 103 |
background:a.btnBg+'4d', animation:'bkfctaPulse 2s ease-out infinite', |
| 104 |
}}), |
| 105 |
el('a',{className:'bkfcta-btn',href:a.url, |
| 106 |
target:a.openInNew?'_blank':undefined, |
| 107 |
rel:a.openInNew?'noopener noreferrer':undefined, |
| 108 |
style:{ |
| 109 |
position:'relative', display:'inline-flex', alignItems:'center', gap:'8px', |
| 110 |
background:a.btnBg, color:a.btnColor, |
| 111 |
padding:a.paddingY+'px '+a.paddingX+'px', |
| 112 |
borderRadius:a.btnRadius+'px', |
| 113 |
boxShadow:a.btnShadow?'0 8px 24px rgba(0,0,0,0.2)':'none', |
| 114 |
textDecoration:'none', |
| 115 |
}}, |
| 116 |
a.showIcon&&el('span',{className:'dashicons dashicons-'+a.icon,style:{fontSize:a.iconSize+'px',width:a.iconSize+'px',height:a.iconSize+'px',lineHeight:1}}), |
| 117 |
a.showLabel&&el('span',null,a.label), |
| 118 |
), |
| 119 |
a.showDismiss&&el('button',{className:'bkfcta-dismiss',style:{ |
| 120 |
position:'absolute',top:'-8px',right:'-8px', |
| 121 |
width:'22px',height:'22px',borderRadius:'50%', |
| 122 |
background:'#374151',color:'#fff',border:'none',cursor:'pointer', |
| 123 |
fontSize:'12px',fontWeight:700,lineHeight:'22px',textAlign:'center',padding:0, |
| 124 |
}},'×'), |
| 125 |
); |
| 126 |
} |
| 127 |
}); |
| 128 |
}() ); |
| 129 |
|