Files
wp-multisite-waas/assets/js/vue-apps.min.js
2025-04-07 11:40:19 -06:00

2 lines
3.9 KiB
JavaScript

(()=>{let{Vue:n,defineComponent:r}=window.wu_vue||{},s=wp.hooks||{},i=(window.wu_vue||{}).Vue,t=()=>{document.querySelectorAll("[data-wu-app]").forEach(t=>{var e;i&&(e=t.dataset.wuApp)&&((o,i,e=null)=>{if(window["wu_"+i]&&!["add_checkout_form_field"].includes(i))return;window["wu_"+i]=new n(r({name:"string"==typeof i?i:"",el:o,directives:{init:{bind(t,e,i){i.context[e.arg]=e.value}},initempty:{bind(t,e,i){""===i.context[e.arg]&&(i.context[e.arg]=e.value)}}},data(){let t=wu_settings.currency_symbol,e="";"%v%s"===wu_settings.currency_position?(t="",e=wu_settings.currency_symbol):"%s %v"===wu_settings.currency_position?t=wu_settings.currency_symbol+" ":"%v %s"===wu_settings.currency_position&&(t="",e=" "+wu_settings.currency_symbol);var i={money_settings:{prefix:t,suffix:e,decimal:wu_settings.decimal_separator,thousands:wu_settings.thousand_separator,precision:parseInt(wu_settings.precision,10),masked:!1}};return Object.assign({},JSON.parse(o.dataset.state||"{}"),i)},computed:{hooks:()=>s,console:()=>console,window:()=>window,shortcode(){return void 0===this.id||void 0===this.attributes?"":"["+(this.id+" "+Object.entries(this.attributes).map(([t,e])=>{if(e===this.defaults[t]||"object"==typeof e)return"";if(this.attributes[t+"_shortcode_requires"]&&Object.entries(this.attributes[t+"_shortcode_requires"]).some(([t,e])=>this.attributes[t]!==e))return"";return t+'="'+("string"==typeof e?e.trim():e)+'"'}).filter(t=>t).join(" ")).trim()+"]"}},mounted(){wu_on_load(),s.doAction("wu_"+i+"_mounted",this.$data);var t=o.dataset.onLoad;"function"==typeof window[t]&&window[t](),e&&e(),this.$nextTick(function(){window.wu_initialize_code_editors(),window.wubox.refresh()})},updated(){this._priorState||(this._priorState=this.$options.data());let e=this,t=Object.keys(this._data).find(t=>JSON.stringify(this._data[t])!==JSON.stringify(e._priorState[t]));this._priorState={...this._data},this.$nextTick(function(){s.doAction("wu_"+i+"_changed",t,e.$data),window.wu_initialize_code_editors(),window.wubox.refresh()})},methods:{send(t,e,i,o){return("window"===t?window:window[t])[e](i,o)},get_value(t){return window[t]},set_value(t,e){this[t]=e},get_state_value(t,e){return void 0===this[t]?e:this[t]},duplicate_and_clean(t,e){var i,e=document.querySelectorAll(e),e=e.item(e.length-1),o=e.cloneNode(!0);o.id=o.id+"_copy",o.querySelectorAll("input, textarea").forEach(t=>t.value=""),null!=(i=e.parentNode)&&i.insertBefore(o,e.nextSibling)},wu_format_money(t){return wu_format_money(t)},require(t,e){return"[object Array]"===Object.prototype.toString.call(this[t])?-1<this[t].indexOf(e):"[object Array]"===Object.prototype.toString.call(e)?-1<e.indexOf(this[t]):this[t]==e},open(t){t.preventDefault(),this.edit=!0}}})),window["wu_"+i].$watch("section",function(t){try{var e=new URL(window.location.href);e.searchParams.set(i,t),history.pushState({},"",e)}catch(t){console.warn("Browser does not support pushState.",t)}})})(t,e)})};document.addEventListener("DOMContentLoaded",()=>{i.component("colorPicker",{props:["value"],template:'<input type="text">',mounted(){let i=this;jQuery(this.$el).val(this.value).wpColorPicker({width:200,defaultColor:this.value,change(t,e){i.$emit("input",e.color.toString())}})},watch:{value(t){jQuery(this.$el).wpColorPicker("color",t)}},destroyed(){jQuery(this.$el).off().wpColorPicker("destroy")}}),i.component("wpEditor",{props:["value","id","name"],template:'<textarea v-bind="$props"></textarea>',mounted(){if(void 0!==wp.editor){let e=this;wp.editor.remove(this.id),wp.editor.initialize(this.id,{tinymce:{setup(t){t.on("init",function(){wubox.refresh()}),t.on("keyup",()=>{t.isDirty()&&e.$emit("input",t.getContent())})}}})}},destroyed(){void 0!==wp.editor&&wp.editor.remove(this.id)}}),document.body.addEventListener("wubox:unload",function(){var t="wu_"+document.getElementById("WUB_window").querySelector("ul[data-wu-app]").dataset.wuApp;delete window[t],delete window[t+"_errors"]}),document.body.addEventListener("wubox:load",t),t()})})();