mirror of
https://github.com/10h30/display-featured-image-genesis.git
synced 2026-06-05 15:08:20 +09:00
Fix block script dependencies
This commit is contained in:
+49
-49
@@ -2,7 +2,7 @@
|
||||
* Copyright (c) 2019 Robin Cornett
|
||||
*/
|
||||
|
||||
(function ( wp, undefined ) {
|
||||
( function ( wp, $, undefined ) {
|
||||
'use strict';
|
||||
const DFIGBlockObject = {
|
||||
el: wp.element.createElement,
|
||||
@@ -13,8 +13,8 @@
|
||||
*/
|
||||
DFIGBlockObject.init = function ( params ) {
|
||||
const registerBlockType = wp.blocks.registerBlockType,
|
||||
ServerSideRender = wp.components.ServerSideRender,
|
||||
InspectorControls = wp.blockEditor.InspectorControls;
|
||||
ServerSideRender = wp.components.ServerSideRender,
|
||||
InspectorControls = wp.blockEditor.InspectorControls;
|
||||
|
||||
registerBlockType( params.block, {
|
||||
title: params.title,
|
||||
@@ -26,23 +26,23 @@
|
||||
html: false
|
||||
},
|
||||
|
||||
getEditWrapperProps( {blockAlignment} ) {
|
||||
return {'data-align': blockAlignment};
|
||||
getEditWrapperProps ( { blockAlignment } ) {
|
||||
return { 'data-align': blockAlignment };
|
||||
},
|
||||
|
||||
edit: props => {
|
||||
const {
|
||||
attributes,
|
||||
setAttributes
|
||||
} = props,
|
||||
Fragment = wp.element.Fragment,
|
||||
BlockControls = wp.blockEditor.BlockControls,
|
||||
BlockAlignmentToolbar = wp.blockEditor.BlockAlignmentToolbar;
|
||||
attributes,
|
||||
setAttributes
|
||||
} = props,
|
||||
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 ] ) {
|
||||
if ( params.placeholder && !attributes[ params.required ] ) {
|
||||
render = DFIGBlockObject.el( 'div', {
|
||||
className: DFIGBlockObject.params.prefix + '-placeholder',
|
||||
}, params.placeholder );
|
||||
@@ -54,9 +54,9 @@
|
||||
DFIGBlockObject.el( BlockControls, null,
|
||||
DFIGBlockObject.el( BlockAlignmentToolbar, {
|
||||
value: attributes.blockAlignment,
|
||||
controls: ['wide', 'full'],
|
||||
controls: [ 'wide', 'full' ],
|
||||
onChange: ( value ) => {
|
||||
setAttributes( {blockAlignment: value} );
|
||||
setAttributes( { blockAlignment: value } );
|
||||
},
|
||||
} )
|
||||
),
|
||||
@@ -82,12 +82,12 @@
|
||||
* @return {Array}
|
||||
* @private
|
||||
*/
|
||||
function _getPanels( props, params ) {
|
||||
const panels = [],
|
||||
PanelBody = wp.components.PanelBody;
|
||||
function _getPanels ( props, params ) {
|
||||
const panels = [],
|
||||
PanelBody = wp.components.PanelBody;
|
||||
Object.keys( params.panels ).forEach( function ( key, index ) {
|
||||
if ( params.panels.hasOwnProperty( key ) ) {
|
||||
const IndividualPanel = params.panels[key];
|
||||
const IndividualPanel = params.panels[ key ];
|
||||
panels[ index ] = DFIGBlockObject.el( PanelBody, {
|
||||
title: IndividualPanel.title,
|
||||
initialOpen: IndividualPanel.initialOpen,
|
||||
@@ -107,7 +107,7 @@
|
||||
* @return {Array}
|
||||
* @private
|
||||
*/
|
||||
function _getControls( props, fields ) {
|
||||
function _getControls ( props, fields ) {
|
||||
const controls = [];
|
||||
Object.keys( fields ).forEach( function ( key, index ) {
|
||||
if ( fields.hasOwnProperty( key ) ) {
|
||||
@@ -115,9 +115,9 @@
|
||||
if ( -1 !== skipped.indexOf( key ) ) {
|
||||
return;
|
||||
}
|
||||
const IndividualField = fields[key],
|
||||
control = _getControlType( IndividualField.method, IndividualField.type );
|
||||
controls[index] = DFIGBlockObject.el( control, _getIndividualControl( key, IndividualField, props ) );
|
||||
const IndividualField = fields[ key ],
|
||||
control = _getControlType( IndividualField.method, IndividualField.type );
|
||||
controls[ index ] = DFIGBlockObject.el( control, _getIndividualControl( key, IndividualField, props ) );
|
||||
}
|
||||
} );
|
||||
|
||||
@@ -131,13 +131,13 @@
|
||||
* @return {*}
|
||||
* @private
|
||||
*/
|
||||
function _getControlType( method, control_type ) {
|
||||
function _getControlType ( method, control_type ) {
|
||||
const {
|
||||
TextControl,
|
||||
SelectControl,
|
||||
CheckboxControl,
|
||||
TextareaControl
|
||||
} = wp.components;
|
||||
TextControl,
|
||||
SelectControl,
|
||||
CheckboxControl,
|
||||
TextareaControl
|
||||
} = wp.components;
|
||||
const control = TextControl;
|
||||
if ( 'select' === method ) {
|
||||
return SelectControl;
|
||||
@@ -160,24 +160,24 @@
|
||||
* @return {{label: *, value: *, className: string, onChange: onChange}}
|
||||
* @private
|
||||
*/
|
||||
function _getIndividualControl( key, field, props ) {
|
||||
const {attributes, setAttributes} = props;
|
||||
function _getIndividualControl ( key, field, props ) {
|
||||
const { attributes, setAttributes } = props;
|
||||
const control = {
|
||||
label: field.label,
|
||||
value: attributes[key],
|
||||
value: attributes[ key ],
|
||||
className: DFIGBlockObject.params.prefix + '-' + key,
|
||||
onChange: ( value ) => {
|
||||
if ( 'taxonomy' === key ) {
|
||||
onChangeSelect( key, value, props );
|
||||
}
|
||||
setAttributes( {[key]: value} );
|
||||
setAttributes( { [ key ]: value } );
|
||||
}
|
||||
};
|
||||
|
||||
if ( 'select' === field.method ) {
|
||||
control.options = field.options;
|
||||
} else if ( 'checkbox' === field.method ) {
|
||||
control.checked = attributes[key];
|
||||
control.checked = attributes[ key ];
|
||||
}
|
||||
|
||||
return control;
|
||||
@@ -189,7 +189,7 @@
|
||||
* @param value
|
||||
* @param props
|
||||
*/
|
||||
function onChangeSelect( select_id, value, props ) {
|
||||
function onChangeSelect ( select_id, value, props ) {
|
||||
if ( DFIGBlockObject.params.prefix + '/term' !== props.name ) {
|
||||
return;
|
||||
}
|
||||
@@ -205,12 +205,12 @@
|
||||
* @returns {{action: string, security: *}}
|
||||
* @private
|
||||
*/
|
||||
function _getAjaxData( select_id, value, props ) {
|
||||
const data = {
|
||||
action: DFIGBlockObject.params.prefix + '_block',
|
||||
security: DFIGBlockObject.params.security
|
||||
},
|
||||
{attributes} = props;
|
||||
function _getAjaxData ( select_id, value, props ) {
|
||||
const data = {
|
||||
action: DFIGBlockObject.params.prefix + '_block',
|
||||
security: DFIGBlockObject.params.security
|
||||
},
|
||||
{ attributes } = props;
|
||||
if ( 'taxonomy' === select_id ) {
|
||||
data.taxonomy = value;
|
||||
} else {
|
||||
@@ -228,8 +228,8 @@
|
||||
* @return
|
||||
* @private
|
||||
*/
|
||||
function _doAjaxUpdate( data, select_id, props ) {
|
||||
const {attributes, setAttributes} = props;
|
||||
function _doAjaxUpdate ( data, select_id, props ) {
|
||||
const { attributes, setAttributes } = props;
|
||||
$.post( DFIGBlockObject.params.ajax_url, data, function ( response ) {
|
||||
|
||||
if ( undefined !== response.success && false === response.success ) {
|
||||
@@ -254,9 +254,9 @@
|
||||
* @param attributes
|
||||
* @private
|
||||
*/
|
||||
function _modifySelectInput( options, key, attributes ) {
|
||||
function _modifySelectInput ( options, key, attributes ) {
|
||||
const selectID = $( '.' + DFIGBlockObject.params.prefix + '-' + key + ' select' ),
|
||||
oldValue = attributes[key] || '';
|
||||
oldValue = attributes[ key ] || '';
|
||||
selectID.empty();
|
||||
_updateSelectOptions( options, selectID, oldValue );
|
||||
}
|
||||
@@ -268,13 +268,13 @@
|
||||
* @param oldValue
|
||||
* @private
|
||||
*/
|
||||
function _updateSelectOptions( options, selectID, oldValue ) {
|
||||
function _updateSelectOptions ( options, selectID, oldValue ) {
|
||||
$.each( options, function ( key, value ) {
|
||||
const new_option = $( '<option />' )
|
||||
.val( key ).text( value ),
|
||||
method = ! key ? 'prepend' : 'append';
|
||||
.val( key ).text( value ),
|
||||
method = !key ? 'prepend' : 'append';
|
||||
selectID.val( oldValue );
|
||||
selectID[method]( new_option );
|
||||
selectID[ method ]( new_option );
|
||||
} );
|
||||
}
|
||||
|
||||
@@ -287,4 +287,4 @@
|
||||
}
|
||||
} );
|
||||
}
|
||||
} )( wp );
|
||||
} )( wp, jQuery );
|
||||
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
!function(e,t){"use strict";const n={el:e.element.createElement};function o(e,o,r){if(n.params.prefix+"/term"!==r.name)return;!function(e,o,r){const{attributes:a,setAttributes:c}=r;$.post(n.params.ajax_url,e,function(e){if(t!==e.success&&!1===e.success)return!1;const r=$.parseJSON(e);!function(e,t,o){const r=$("."+n.params.prefix+"-"+t+" select"),a=o[t]||"";r.empty(),function(e,t,n){$.each(e,function(e,o){const r=$("<option />").val(e).text(o),a=e?"append":"prepend";t.val(n),t[a](r)})}(e,r,a)}(r,"term",a),o&&c({term:""})})}(function(e,t,o){const r={action:n.params.prefix+"_block",security:n.params.security},{attributes:a}=o;r.taxonomy="taxonomy"===e?t:a.taxonomy;return r}(e,o,r),e,r)}n.init=function(t){const r=e.blocks.registerBlockType,a=e.components.ServerSideRender,c=e.blockEditor.InspectorControls;r(t.block,{title:t.title,description:t.description,keywords:t.keywords,icon:t.icon,category:t.category,supports:{html:!1},getEditWrapperProps:({blockAlignment:e})=>({"data-align":e}),edit:r=>{const{attributes:s,setAttributes:l}=r,i=e.element.Fragment,p=e.blockEditor.BlockControls,u=e.blockEditor.BlockAlignmentToolbar;let m=n.el(a,{block:t.block,attributes:s});return t.placeholder&&!s[t.required]&&(m=n.el("div",{className:n.params.prefix+"-placeholder"},t.placeholder)),[m,n.el(i,null,n.el(p,null,n.el(u,{value:s.blockAlignment,controls:["wide","full"],onChange:e=>{l({blockAlignment:e})}}))),n.el(c,{},function(t,r){const a=[],c=e.components.PanelBody;return Object.keys(r.panels).forEach(function(s,l){if(r.panels.hasOwnProperty(s)){const i=r.panels[s];a[l]=n.el(c,{title:i.title,initialOpen:i.initialOpen,className:n.params.prefix+"-panel-"+s},function(t,r){const a=[];return Object.keys(r).forEach(function(c,s){if(r.hasOwnProperty(c)){if(-1!==["blockAlignment","className"].indexOf(c))return;const l=r[c],i=function(t,n){const{TextControl:o,SelectControl:r,CheckboxControl:a,TextareaControl:c}=e.components,s=o;return"select"===t?r:"checkbox"===t?a:"textarea"===t?c:s}(l.method,l.type);a[s]=n.el(i,function(e,t,r){const{attributes:a,setAttributes:c}=r,s={label:t.label,value:a[e],className:n.params.prefix+"-"+e,onChange:t=>{"taxonomy"===e&&o(e,t,r),c({[e]:t})}};return"select"===t.method?s.options=t.options:"checkbox"===t.method&&(s.checked=a[e]),s}(c,l,t))}}),a}(t,i.attributes))}}),a}(r,t),o(!1,!1,r))]},save:e=>null})},n.params="undefined"==typeof DisplayFeaturedImageBlock?"":DisplayFeaturedImageBlock,void 0!==n.params&&Object.keys(n.params.blocks).forEach(function(e,t){n.params.blocks.hasOwnProperty(e)&&n.init(n.params.blocks[e])})}(wp);
|
||||
!function(e,t,n){"use strict";const o={el:e.element.createElement};function r(e,r,a){if(o.params.prefix+"/term"!==a.name)return;!function(e,r,a){const{attributes:c,setAttributes:s}=a;t.post(o.params.ajax_url,e,function(e){if(n!==e.success&&!1===e.success)return!1;const a=t.parseJSON(e);!function(e,n,r){const a=t("."+o.params.prefix+"-"+n+" select"),c=r[n]||"";a.empty(),function(e,n,o){t.each(e,function(e,r){const a=t("<option />").val(e).text(r),c=e?"append":"prepend";n.val(o),n[c](a)})}(e,a,c)}(a,"term",c),r&&s({term:""})})}(function(e,t,n){const r={action:o.params.prefix+"_block",security:o.params.security},{attributes:a}=n;r.taxonomy="taxonomy"===e?t:a.taxonomy;return r}(e,r,a),e,a)}o.init=function(t){const n=e.blocks.registerBlockType,a=e.components.ServerSideRender,c=e.blockEditor.InspectorControls;n(t.block,{title:t.title,description:t.description,keywords:t.keywords,icon:t.icon,category:t.category,supports:{html:!1},getEditWrapperProps:({blockAlignment:e})=>({"data-align":e}),edit:n=>{const{attributes:s,setAttributes:l}=n,i=e.element.Fragment,p=e.blockEditor.BlockControls,u=e.blockEditor.BlockAlignmentToolbar;let m=o.el(a,{block:t.block,attributes:s});return t.placeholder&&!s[t.required]&&(m=o.el("div",{className:o.params.prefix+"-placeholder"},t.placeholder)),[m,o.el(i,null,o.el(p,null,o.el(u,{value:s.blockAlignment,controls:["wide","full"],onChange:e=>{l({blockAlignment:e})}}))),o.el(c,{},function(t,n){const a=[],c=e.components.PanelBody;return Object.keys(n.panels).forEach(function(s,l){if(n.panels.hasOwnProperty(s)){const i=n.panels[s];a[l]=o.el(c,{title:i.title,initialOpen:i.initialOpen,className:o.params.prefix+"-panel-"+s},function(t,n){const a=[];return Object.keys(n).forEach(function(c,s){if(n.hasOwnProperty(c)){if(-1!==["blockAlignment","className"].indexOf(c))return;const l=n[c],i=function(t,n){const{TextControl:o,SelectControl:r,CheckboxControl:a,TextareaControl:c}=e.components,s=o;return"select"===t?r:"checkbox"===t?a:"textarea"===t?c:s}(l.method,l.type);a[s]=o.el(i,function(e,t,n){const{attributes:a,setAttributes:c}=n,s={label:t.label,value:a[e],className:o.params.prefix+"-"+e,onChange:t=>{"taxonomy"===e&&r(e,t,n),c({[e]:t})}};return"select"===t.method?s.options=t.options:"checkbox"===t.method&&(s.checked=a[e]),s}(c,l,t))}}),a}(t,i.attributes))}}),a}(n,t),r(!1,!1,n))]},save:e=>null})},o.params="undefined"==typeof DisplayFeaturedImageBlock?"":DisplayFeaturedImageBlock,void 0!==o.params&&Object.keys(o.params.blocks).forEach(function(e,t){o.params.blocks.hasOwnProperty(e)&&o.init(o.params.blocks[e])})}(wp,jQuery);
|
||||
@@ -64,7 +64,7 @@ class DisplayFeaturedImageGenesisWidgetsBlocks {
|
||||
wp_register_script(
|
||||
"{$this->prefix}-block",
|
||||
plugin_dir_url( dirname( __FILE__ ) ) . "js/block{$minify}.js",
|
||||
array( 'wp-blocks', 'wp-element', 'wp-components', 'wp-editor' ),
|
||||
array( 'jquery', 'wp-blocks', 'wp-element', 'wp-components', 'wp-editor' ),
|
||||
$version,
|
||||
false
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user