Current Path : /storage/v11800/wthtest1/public_html/wp-content/plugins/elfsight-popup-cc/assets/ |
Linux v11800 5.3.0-1023-aws #25~18.04.1-Ubuntu SMP Fri Jun 5 15:19:18 UTC 2020 aarch64
|
Current File : /storage/v11800/wthtest1/public_html/wp-content/plugins/elfsight-popup-cc/assets/elfsight-block.js |
/*
Popup
Version: 1.0.0
Release date: Wed Nov 20 2019
https://elfsight.com
Copyright (c) 2019 Elfsight, LLC. ALL RIGHTS RESERVED
*/
!function(wp,$){"use strict";if(void 0===wp.components||void 0===wp.blocks||void 0===wp.element||void 0===wp.i18n)return!1;const{__:__}=wp.i18n,el=wp.element.createElement,registerBlockType=wp.blocks.registerBlockType,ServerSideRender=wp.components.ServerSideRender;let initTimeout;function initWidget(){clearTimeout(initTimeout),initTimeout=setTimeout(function(){let widgets=document.querySelectorAll("[data-elfsight-popup-options]");Array.prototype.slice.call(widgets).forEach(function(widget){let options=widget.getAttribute("data-elfsight-popup-options"),data=JSON.parse(decodeURIComponent(options));eval("eappsPopup(widget, data)"),widget.removeAttribute("data-elfsight-popup-options"),widget.removeAttribute("data-elfsight-popup-version"),widget.closest(".elfsight-block-widget-container").classList.add("elfsight-block-widget-initialized")})},1500)}async function getWidgets(){const e=await $.get(ajaxurl,{action:"elfsight-popup".replace(/-/g,"_")+"_widgets_api",endpoint:"list"});return e.status?[e.data,e.data.reduce(function(e,t){return e[t.id]=t,e},{})]:[]}function getWidgetId(e){let t;return e.some(function(e){if("1"===e.active)return t=e.id}),t}class Widget extends React.Component{componentDidMount(){initWidget()}componentDidUpdate(){initWidget()}render(){return this.props.id?el("div",{className:"elfsight-block-widget-container"},el(ServerSideRender,{block:"elfsight-popup/block",attributes:{id:this.props.id||"1"}}),el("div",{className:"elfsight-block-widget-placeholder"},el(IconBlock,{}),el("span",{},"Popup"))):[]}}class Button extends React.Component{render(){let e=document.location.origin+document.location.pathname.replace("post.php","admin.php")+"?page=elfsight-popup#";return el("a",{href:e+this.props.href,target:"_blank",className:this.props.className},this.props.text)}}class WidgetSelect extends React.Component{constructor(){super(),this.state={widgets:[]}}setWidget(e){e.preventDefault();let t=e.target.querySelector("option:checked");this.props.setAttributes({id:t.value.toString()})}componentDidMount(){getWidgets().then(e=>{const[t,i]=e;this.setState({widgets:t});const s=this.props.id,o=!(!i[s]||"1"!==i[s].active);!o&&i?this.props.setAttributes({id:getWidgetId(t),exist:!0}):this.props.setAttributes({id:s,exist:o})})}render(){return this.state.widgets.length>0?el("div",{className:"components-base-control"},el("div",{className:"components-base-control__field"},el("select",{className:"components-select-control__input",id:"elfsight-popup-block-control-id",value:this.props.id,onChange:this.setWidget.bind(this)},this.state.widgets.map(e=>wp.element.createElement("option",{value:e.id},[e.name]))))):[]}}registerBlockType("elfsight-popup/block",{title:"Popup",description:"Create various types of popups for your website for more leads and higher sales.",icon:{src:IconBlock},category:"widgets",keywords:["Popup","Elfsight"],supports:{html:!1},attributes:{id:{type:"number"},exist:{type:"bool",default:!1}},edit:function(e){const{attributes:{id:t,exist:i},setAttributes:s}=e;return getWidgets().then(e=>{const[o,l]=e;s(!i&&o?{id:getWidgetId(o),exist:!0}:{id:t,exist:i})}),el(wp.element.Fragment,{},el(wp.editor.InspectorControls,{},el(wp.components.PanelBody,{className:"elfsight-block-panel",title:"Select widget"},el(WidgetSelect,{id:t,setAttributes:function(t){e.setAttributes(t)}}),i?el("div",{className:"elfsight-block-panel-group"},el(Button,{href:"/edit-widget/"+t,className:"components-button is-button is-default is-large elfsight-block-panel-button",text:__("Edit Widget")}),el(Button,{href:"/add-widget/",className:"elfsight-block-panel-link",text:__("Create new widget")})):el("div",{className:"elfsight-block-panel-group"},el("span",{},__("No widgets yet")),el(Button,{href:"/add-widget/",className:"components-button is-button is-default is-primary is-large elfsight-block-panel-button",text:__("Create Widget")})))),i?el(Widget,{id:t,exist:i}):null,i?null:el("div",{className:"elfsight-block-form"},el("div",{className:"elfsight-block-form-header"},el(IconBlock,{}),el("span",{},"Popup")),el("div",{className:"elfsight-block-form-text"},__("Create various types of popups for your website for more leads and higher sales."),el("br"),el("strong",{},__("Let's create your first widget!"))),el(Button,{href:"/add-widget/",className:"components-button is-button is-default is-primary is-large elfsight-block-form-button",text:__("Create Widget")})))},save:function(){return null}})}(wp,jQuery);