Remove unneeded number controls/logic

This commit is contained in:
Robin Cornett
2019-06-26 09:02:03 -04:00
parent 243bfff7ac
commit 53f74dedcc
3 changed files with 2 additions and 19 deletions
-11
View File
@@ -135,15 +135,12 @@
const {
TextControl,
SelectControl,
RangeControl,
CheckboxControl,
TextareaControl
} = wp.components;
const control = TextControl;
if ( 'select' === method ) {
return SelectControl;
} else if ( 'number' === method && 'number' === control_type ) {
return RangeControl;
} else if ( 'checkbox' === method ) {
return CheckboxControl;
} else if ( 'textarea' === method ) {
@@ -179,14 +176,6 @@
if ( 'select' === field.method ) {
control.options = field.options;
} else if ( 'number' === field.method ) {
control.min = field.min;
control.max = field.max;
if ( 'number' !== field.type ) {
control.type = 'number';
} else {
control.initialPosition = field.min;
}
} else if ( 'checkbox' === field.method ) {
control.checked = attributes[key];
}
+1 -1
View File
@@ -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:s}=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&&s({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,s=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:c,setAttributes:l}=r,i=e.element.Fragment,p=e.blockEditor.BlockControls,u=e.blockEditor.BlockAlignmentToolbar;let m=n.el(a,{block:t.block,attributes:c});return t.placeholder&&!c[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:c.blockAlignment,controls:["wide","full"],onChange:e=>{l({blockAlignment:e})}}))),n.el(s,{},function(t,r){const a=[],s=e.components.PanelBody;return Object.keys(r.panels).forEach(function(c,l){if(r.panels.hasOwnProperty(c)){const i=r.panels[c];a[l]=n.el(s,{title:i.title,initialOpen:i.initialOpen,className:n.params.prefix+"-panel-"+c},function(t,r){const a=[];return Object.keys(r).forEach(function(s,c){if(r.hasOwnProperty(s)){if(-1!==["blockAlignment","className"].indexOf(s))return;const l=r[s],i=function(t,n){const{TextControl:o,SelectControl:r,RangeControl:a,CheckboxControl:s,TextareaControl:c}=e.components,l=o;return"select"===t?r:"number"===t&&"number"===n?a:"checkbox"===t?s:"textarea"===t?c:l}(l.method,l.type);a[c]=n.el(i,function(e,t,r){const{attributes:a,setAttributes:s}=r,c={label:t.label,value:a[e],className:n.params.prefix+"-"+e,onChange:t=>{"taxonomy"===e&&o(e,t,r),s({[e]:t})}};return"select"===t.method?c.options=t.options:"number"===t.method?(c.min=t.min,c.max=t.max,"number"!==t.type?c.type="number":c.initialPosition=t.min):"checkbox"===t.method&&(c.checked=a[e]),c}(s,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){"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);
@@ -156,10 +156,7 @@ class DisplayFeaturedImageGenesisWidgetsBlocksFields {
'label' => $field['args']['label'],
'method' => $method,
);
if ( in_array( 'number', array( $field_type, $method ), true ) ) {
$attributes['min'] = $field['args']['min'];
$attributes['max'] = $field['args']['max'];
} elseif ( 'select' === $method ) {
if ( 'select' === $method ) {
$attributes['options'] = $this->convert_choices_for_select( $field['args']['choices'] );
}
@@ -175,9 +172,6 @@ class DisplayFeaturedImageGenesisWidgetsBlocksFields {
*/
private function get_field_type( $method ) {
$type = 'string';
if ( 'number' === $method ) {
return $method;
}
if ( 'checkbox' === $method ) {
return 'boolean';
}