mirror of
https://github.com/10h30/display-featured-image-genesis.git
synced 2026-07-18 14:03:20 +09:00
1 line
2.6 KiB
JavaScript
1 line
2.6 KiB
JavaScript
!function(e,t){"use strict";const n="displayfeaturedimagegenesis",o={el:e.element.createElement};function r(e,r,c,l){if(n+"/term"!==l)return;!function(e,r,c){const{attributes:l,setAttributes:s}=c;$.post(o.params.ajax_url,e,function(e){if(t!==e.success&&!1===e.success)return!1;const o=$.parseJSON(e);!function(e,t,o){const r=$("."+n+"-"+t+" select"),c=o[t]||"";r.empty(),function(e,t,n){$.each(e,function(e,o){const r=$("<option />").val(e).text(o),c=e?"append":"prepend";t.val(n),t[c](r)})}(e,r,c)}(o,"term",l),r&&s({term:""})})}(function(e,t,r){const c={action:n+"_block",security:o.params.security},{attributes:l}=r;c.taxonomy="taxonomy"===e?t:l.taxonomy;return c}(e,r,c),e,c)}o.init=function(t){const c=e.blocks.registerBlockType,l=e.components.ServerSideRender,s=e.blockEditor.InspectorControls;c(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:c=>{const{attributes:a,setAttributes:i}=c,u=e.element.Fragment,m=e.blockEditor.BlockControls,p=e.blockEditor.BlockAlignmentToolbar;let b=o.el(l,{block:t.block,attributes:a});return t.placeholder&&!a[t.required]&&(b=o.el("div",{className:n+"-placeholder"},t.placeholder)),[b,o.el(u,null,o.el(m,null,o.el(p,{value:a.blockAlignment,controls:["wide","full"],onChange:e=>{i({blockAlignment:e})}}))),o.el(s,{},function(t,c,l){const s=[],a=e.components.PanelBody;return Object.keys(c.panels).forEach(function(i,u){if(c.panels.hasOwnProperty(i)){const m=c.panels[i];s[u]=o.el(a,{title:m.title,initialOpen:m.initialOpen,className:n+"-panel-"+i},function(t,c,l){const s=[];return Object.keys(c).forEach(function(a,i){if(c.hasOwnProperty(a)){if(-1!==["blockAlignment","className"].indexOf(a))return;const u=c[a],m=function(t,n){const{TextControl:o,SelectControl:r,RangeControl:c,CheckboxControl:l,TextareaControl:s}=e.components,a=o;return"select"===t?r:"number"===t&&"number"===n?c:"checkbox"===t?l:"textarea"===t?s:a}(u.method,u.type);s[i]=o.el(m,function(e,t,o,c){const{attributes:l,setAttributes:s}=o,a={label:t.label,value:l[e],className:n+"-"+e,onChange:t=>{"taxonomy"===e&&r(e,t,o,c),s({[e]:t})}};return"select"===t.method?a.options=t.options:"number"===t.method?(a.min=t.min,a.max=t.max,"number"!==t.type?a.type="number":a.initialPosition=t.min):"checkbox"===t.method&&(a.checked=l[e]),a}(a,u,t,l))}}),s}(t,m.attributes,l))}}),s}(c,t,t.block),r(!1,!1,c))]},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); |