laipower/wp-content/plugins/subscribe2/gutenberg/shortcode.min.js

1 line
4.9 KiB
JavaScript

!function(e,t,s,i,r){var n=s.createElement,o=i.TextControl,a=i.CheckboxControl,c=i.RadioControl;function b(e,t,s){var i=e.attributes||"",r="",n="",o="",a="",c="",b="",u="";switch("subscribe"===i.hide?r=' hide="subscribe"':"unsubscribe"===i.hide&&(r=' hide="unsubscribe"'),""!==i.id&&undefined!==i.id&&(n=' id="'+i.id+'"'),!0===i.nojs&&(o=' nojs="true"'),!0===i.antispam&&(a=' antispam="true"'),""!==i.size&&undefined!==i.size&&"20"!==i.size&&(c=' size="'+i.size+'"'),!0===i.wrap&&(b=' wrap="false"'),""!==i.link&&undefined!==i.link&&(u=' link="'+i.link+'"'),t){case"hide":"none"===s?r="":"subscribe"===s?r=' hide="subscribe"':"unsubscribe"===s&&(r=' hide="unsubscribe"');break;case"id":n=""===s?"":' id="'+s+'"';break;case"nojs":!0===s?o=' nojs="true"':!1===s&&(o="");break;case"antispam":!0===s?a=' antispam="true"':!1===s&&(a="");break;case"size":c="20"===s?"":' size="'+s+'"';break;case"wrap":!0===s?b=' wrap="false"':!1===s&&(b="");break;case"link":u=""===s?"":' link="'+s+'"'}return e.attributes.shortcode="[subscribe2"+r+n+o+a+c+b+u+"]",e.attributes.shortcode}e.registerBlockType("subscribe2-html/shortcode",{title:t.__("Subscribe2 HTML","subscribe2"),icon:"email",category:"widgets",keywords:[t.__("email","subscribe2"),t.__("notification","subscribe2")],supports:{customClassName:!1,className:!1,multiple:!1,html:!1},attributes:{shortcode:{type:"text",selector:"p"},hide:{type:"string"},id:{type:"string"},nojs:{type:"boolean"},antispam:{type:"boolean"},size:{type:"number"},wrap:{type:"boolean"},link:{type:"string"}},transforms:{to:[{type:"block",blocks:["core/shortcode"],transform:function(t){return undefined!==t.shortcode&&""!==t.shortcode||(t.shortcode="[subscribe2]"),e.createBlock("core/shortcode",{text:t.shortcode})}}],from:[{type:"block",blocks:["core/shortcode"],transform:function(t){var s,i,r,n,o,a,c,b,u,l,d,p;if("subscribe2"===t.text.substr(1,10)){for(s=t.text,p=(i=t.text.replace(/^\[subscribe2|\]$/g,"").replace(/^\s+|\s+$/g,"").split(/['"]\s/g)).length,d=0;d<p;d++)"hide"===(r=i[d].split("="))[0]&&(n=r[1].replace(/['"]+/g,"")),"id"===r[0]&&(o=r[1].replace(/['"]+/g,"")),"nojs"===r[0]&&(a="true"===r[1].replace(/['"]+/g,"")),"antispam"===r[0]&&(c="true"===r[1].replace(/['"]+/g,"")),"size"===r[0]&&(b=r[1].replace(/['"]+/g,"")),"wrap"===r[0]&&(u="false"===r[1].replace(/['"]+/g,"")),"link"===r[0]&&(l=r[1].replace(/^['"]|['"]$/g,""));return e.createBlock("subscribe2-html/shortcode",{shortcode:s,hide:n,id:o,nojs:a,antispam:c,size:b,wrap:u,link:l})}}},{type:"shortcode",tag:"subscribe2",attributes:{shortcode:{type:"string",selector:"p"},hide:{type:"string",shortcode:function(e){return e.named.hide||"none"}},id:{type:"string",shortcode:function(e){return e.named.id||""}},nojs:{type:"boolean",shortcode:function(e){return e.named.nojs||!1}},antispam:{type:"boolean",shortcode:function(e){return e.named.antispam||!1}},size:{type:"number",shortcode:function(e){return e.named.size||"20"}},wrap:{type:"boolean",shortcode:function(e){return e.named.wrap||!1}},link:{type:"string",shortcode:function(e){return e.named.link||""}}}}]},edit:function(e){var s=e.attributes.hide||"none",i=e.attributes.id||"",u=e.attributes.nojs||!1,l=e.attributes.antispam||!1,d=e.attributes.size||"20",p=e.attributes.wrap||!1,h=e.attributes.link||"";return[e.isSelected&&n(r.InspectorControls,{key:"subscribe2-html/inspector"},n("h3",{},t.__("Subscribe2 Shortcode Parameters","subscribe2")),n(c,{label:t.__("Button Display Options","subscribe2"),selected:s,onChange:function(t){e.attributes.shortcode=b(e,"hide",t),e.setAttributes({hide:t})},options:[{value:"none",label:t.__("Show Both Buttons","subscribe2")},{value:"subscribe",label:t.__("Hide Subscribe Button","subscribe2")},{value:"unsubscribe",label:t.__("Hide Unsubscribe Button","subscribe2")}]}),n(o,{type:"number",label:t.__("Page ID","subscribe2"),value:i,onChange:function(t){e.attributes.shortcode=b(e,"id",t),e.setAttributes({id:t})}}),n(a,{label:t.__("Disable Javascript","subscribe2"),checked:u,onChange:function(t){e.attributes.shortcode=b(e,"nojs",t),e.setAttributes({nojs:t})}}),n(a,{label:t.__("Disable Simple Anti-Spam Measures","subscribe2"),checked:l,onChange:function(t){e.attributes.shortcode=b(e,"antispam",t),e.setAttributes({antispam:t})}}),n(o,{type:"number",label:t.__("Textbox size","subscribe2"),value:d,onChange:function(t){e.attributes.shortcode=b(e,"size",t),e.setAttributes({size:t})}}),n(a,{label:t.__("Disable wrapping of form buttons","subscribe2"),checked:p,onChange:function(t){e.attributes.shortcode=b(e,"wrap",t),e.setAttributes({wrap:t})}}),n(o,{type:"string",label:t.__("Link Text","subscribe2"),value:h,onChange:function(t){e.attributes.shortcode=b(e,"link",t),e.setAttributes({link:t})}})),n("div",{key:"subscribe2-html/block",style:{backgroundColor:"#ff0",color:"#000",padding:"2px",textAlign:"center"}},t.__("Subscribe2 HTML Shortcode","subscribe2"))]},save:function(e){return n(s.RawHTML,null,"<p>"+e.attributes.shortcode+"</p>")}})}(window.wp.blocks,window.wp.i18n,window.wp.element,window.wp.components,window.wp.editor);