| 1 |
/*--------------------------------------// |
| 2 |
WordPress Blocks |
| 3 |
Version: 1.1 |
| 4 |
Original code: Arnan de Gans |
| 5 |
Copyright: See notice in adrotate.php |
| 6 |
//--------------------------------------// |
| 7 |
Changelog: |
| 8 |
//--------------------------------------// |
| 9 |
23 October 2025 |
| 10 |
* Code tweaks |
| 11 |
17 April 2022 |
| 12 |
* Initial release |
| 13 |
//--------------------------------------*/ |
| 14 |
var el = wp.element.createElement, |
| 15 |
__ = wp.i18n.__, |
| 16 |
registerBlockType = wp.blocks.registerBlockType, |
| 17 |
RichText = wp.blocks.RichText, |
| 18 |
BlockBoxStyle = { 'box-sizing': 'border-box', position: 'relative', padding: '1em', 'min-height': '20px', width: '100%', margin: '0', color: '#1e1e1e', 'border-radius': '2px', 'background-color': '#f7f7f7', 'box-shadow': 'inset 0 0 0 1px #1e1e1e', outline: '1px solid transparent', 'background-image': 'linear-gradient(to bottom right, #f7f7f7, #1fa4d1)' }; |
| 19 |
|
| 20 |
registerBlockType('adrotate/advert', { |
| 21 |
title: __('AdRotate Advert', 'adrotate'), |
| 22 |
icon: 'editor-code', |
| 23 |
category: 'custom-adrotate', |
| 24 |
description: __('Show a single advert by entering an advert ID.', 'adrotate'), |
| 25 |
keywords: ['ad', 'advert', 'adrotate', 'banner', 'affiliate', 'adsense', 'promotion', 'promo'], |
| 26 |
|
| 27 |
attributes: { |
| 28 |
advert_id: { |
| 29 |
type: 'string', |
| 30 |
selector: 'input', |
| 31 |
}, |
| 32 |
}, |
| 33 |
supports: { |
| 34 |
html: false, |
| 35 |
}, |
| 36 |
|
| 37 |
edit: function( props ) { |
| 38 |
if(isNaN(props.attributes.advert_id)) props.attributes.advert_id = 0; |
| 39 |
|
| 40 |
return el('div', { |
| 41 |
className: props.className + 'components-placeholder widefat', |
| 42 |
style: BlockBoxStyle, |
| 43 |
}, |
| 44 |
el('div', { |
| 45 |
className: 'components-placeholder__label', |
| 46 |
style: { 'font-size': '18pt', 'font-weight': '400' }, |
| 47 |
}, __('AdRotate Advert', 'adrotate')), |
| 48 |
|
| 49 |
el('label', { |
| 50 |
className: 'components-placeholder__instructions group-' + props.attributes.advert_id, |
| 51 |
}, __('Enter an Advert ID (numbers only):', 'adrotate')), |
| 52 |
el('input', { |
| 53 |
className: 'components-text-control__input group-' + props.attributes.advert_id, |
| 54 |
onChange: function(e) { props.setAttributes({advert_id: e.target.value}); }, |
| 55 |
value: Number(props.attributes.advert_id), |
| 56 |
isSelected: props.isSelected, |
| 57 |
style: { 'background-color': '#fefefe' } |
| 58 |
}), |
| 59 |
el('div', { |
| 60 |
className: 'components-placeholder__instructions group-' + props.attributes.advert_id, |
| 61 |
style: { 'font-size': '70%', 'font-style': 'italic' }, |
| 62 |
}, __('You can find the advert ID in Manage Adverts. Any special markup, code or layout styles can be applied in the advert itself.', 'adrotate')), |
| 63 |
); |
| 64 |
}, |
| 65 |
|
| 66 |
save: function( props ) { |
| 67 |
return null; |
| 68 |
}, |
| 69 |
} ); |
| 70 |
|
| 71 |
registerBlockType('adrotate/group', { |
| 72 |
title: __('AdRotate Group', 'adrotate'), |
| 73 |
icon: 'editor-code', |
| 74 |
category: 'custom-adrotate', |
| 75 |
description: __('Show a group of adverts by entering a group ID.', 'adrotate'), |
| 76 |
keywords: ['ad', 'advert', 'adrotate', 'banner', 'group', 'affiliate', 'adsense', 'promotion', 'promo'], |
| 77 |
|
| 78 |
attributes: { |
| 79 |
group_id: { |
| 80 |
type: 'string', |
| 81 |
selector: 'input', |
| 82 |
}, |
| 83 |
}, |
| 84 |
supports: { |
| 85 |
html: false, |
| 86 |
}, |
| 87 |
|
| 88 |
edit: function( props ) { |
| 89 |
if(isNaN(props.attributes.group_id)) props.attributes.group_id = 0; |
| 90 |
|
| 91 |
return el('div', { |
| 92 |
className: props.className + 'components-placeholder widefat', |
| 93 |
style: BlockBoxStyle, |
| 94 |
}, |
| 95 |
el('div', { |
| 96 |
className: 'components-placeholder__label', |
| 97 |
style: { 'font-size': '18pt', 'font-weight': '400' }, |
| 98 |
}, __('AdRotate Group', 'adrotate')), |
| 99 |
|
| 100 |
el('label', { |
| 101 |
className: 'components-placeholder__instructions group-' + props.attributes.group_id, |
| 102 |
}, __('Enter a group ID (numbers only):', 'adrotate')), |
| 103 |
el('input', { |
| 104 |
className: 'components-text-control__input group-' + props.attributes.group_id, |
| 105 |
onChange: function(e) { props.setAttributes({group_id: e.target.value}); }, |
| 106 |
value: Number(props.attributes.group_id), |
| 107 |
isSelected: props.isSelected, |
| 108 |
style: { 'background-color': '#fefefe' } |
| 109 |
}), |
| 110 |
el('div', { |
| 111 |
className: 'components-placeholder__instructions group-' + props.attributes.group_id, |
| 112 |
style: { 'font-size': '70%', 'font-style': 'italic' }, |
| 113 |
}, __('You can find the group ID in Manage Groups. Choose adverts, special markup, add code or layout styles when editing the group.', 'adrotate')), |
| 114 |
); |
| 115 |
}, |
| 116 |
|
| 117 |
save: function( props ) { |
| 118 |
return null; |
| 119 |
}, |
| 120 |
}); |
| 121 |
|