From 6810eab3bb6e1730129a2dfaf61fe4550d5e0b39 Mon Sep 17 00:00:00 2001 From: Robin Cornett Date: Wed, 26 Jun 2019 07:16:28 -0400 Subject: [PATCH] Move placeholder to JS edit --- includes/js/block.js | 28 ++++++++++++------- includes/js/block.min.js | 2 +- ...uredimagegenesis-widgets-blocks-output.php | 3 -- includes/widgets/fields/blocks.php | 2 ++ 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/includes/js/block.js b/includes/js/block.js index b7318de..22c1cc6 100644 --- a/includes/js/block.js +++ b/includes/js/block.js @@ -4,7 +4,8 @@ (function ( wp, undefined ) { 'use strict'; - const DFIGBlockObject = { + const prefix = 'displayfeaturedimagegenesis', + DFIGBlockObject = { el: wp.element.createElement, }; @@ -38,11 +39,18 @@ Fragment = wp.element.Fragment, BlockControls = wp.blockEditor.BlockControls, BlockAlignmentToolbar = wp.blockEditor.BlockAlignmentToolbar; + let render = DFIGBlockObject.el( ServerSideRender, { + block: params.block, + attributes: attributes + } ); + if ( params.placeholder && ! attributes[ params.required ] ) { + render = DFIGBlockObject.el( 'div', { + className: prefix + '-placeholder', + }, params.placeholder ); + } + return [ - DFIGBlockObject.el( ServerSideRender, { - block: params.block, - attributes: attributes - } ), + render, DFIGBlockObject.el( Fragment, null, DFIGBlockObject.el( BlockControls, null, DFIGBlockObject.el( BlockAlignmentToolbar, { @@ -85,7 +93,7 @@ panels[ index ] = DFIGBlockObject.el( PanelBody, { title: IndividualPanel.title, initialOpen: IndividualPanel.initialOpen, - className: 'scriptless-panel-' + key + className: prefix + '-panel-' + key }, _getControls( props, IndividualPanel.attributes, blockName ) ); } } ); @@ -164,7 +172,7 @@ const control = { label: field.label, value: attributes[key], - className: 'displayfeaturedimagegenesis-' + key, + className: prefix + '-' + key, onChange: ( value ) => { if ( 'taxonomy' === key ) { onChangeSelect( key, value, props, blockName ); @@ -198,7 +206,7 @@ * @param blockName */ function onChangeSelect( select_id, value, props, blockName ) { - if ( 'displayfeaturedimagegenesis/term' !== blockName ) { + if ( prefix + '/term' !== blockName ) { return; } const data = _getAjaxData( select_id, value, props ); @@ -215,7 +223,7 @@ */ function _getAjaxData( select_id, value, props ) { const data = { - action: 'displayfeaturedimagegenesis_block', + action: prefix + '_block', security: DFIGBlockObject.params.security }, {attributes} = props; @@ -263,7 +271,7 @@ * @private */ function _modifySelectInput( options, key, attributes ) { - const selectID = $( '.displayfeaturedimagegenesis-' + key + ' select' ), + const selectID = $( '.' + prefix + '-' + key + ' select' ), oldValue = attributes[key] || ''; selectID.empty(); _updateSelectOptions( options, selectID, oldValue ); diff --git a/includes/js/block.min.js b/includes/js/block.min.js index 0ce7005..552cf1e 100644 --- a/includes/js/block.min.js +++ b/includes/js/block.min.js @@ -1 +1 @@ -!function(e,t){"use strict";const n={el:e.element.createElement};function o(e,o,s,i){if("displayfeaturedimagegenesis/term"!==i)return;!function(e,o,s){const{attributes:i,setAttributes:r}=s;$.post(n.params.ajax_url,e,function(e){if(t!==e.success&&!1===e.success)return!1;const n=$.parseJSON(e);!function(e,t,n){const o=$(".displayfeaturedimagegenesis-"+t+" select"),s=n[t]||"";o.empty(),function(e,t,n){$.each(e,function(e,o){const s=$("