forked from WonderCMS/wondercms-cdn-files
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wcms-admin.min.js
1 lines (1 loc) · 5.13 KB
/
wcms-admin.min.js
1
!function(e){var t={};function n(o){if(t[o])return t[o].exports;var s=t[o]={i:o,l:!1,exports:{}};return e[o].call(s.exports,s,s.exports,n),s.l=!0,s.exports}n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)n.d(o,s,function(t){return e[t]}.bind(null,s));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t){class n{constructor(){const e=this,t=document.querySelectorAll('[data-toggle="wcms-modal"]'),n=document.querySelectorAll('[data-dismiss="wcms-modal"]'),s=document.getElementsByClassName("wcms-modal");t.forEach(e=>{e.addEventListener("click",(function(){o.toggleModal(this,!0)}))}),document.addEventListener("click",(function(e){([...s].includes(e.target)||[...n].includes(e.target))&&o.toggleModal(this,!1)})),document.querySelectorAll("ul.nav-tabs > li > a").forEach(e=>{e.addEventListener("click",(function(e){e.preventDefault(),o.openTabAction(this)}))}),document.querySelectorAll("[data-loader-id]").forEach(e=>{e.addEventListener("click",(function(e){o.showLoader(!0,this.dataset.loaderId)}))}),document.querySelectorAll("div.editText:not(.editTextOpen)").forEach(t=>{t.addEventListener("click",e.constructEditableFieldsAction)}),document.querySelectorAll("i.menu-toggle").forEach(t=>{t.addEventListener("click",e.hideOrShowMenuItemsAction)}),document.getElementById("menuItemAdd").addEventListener("click",o.createNewPage),document.querySelectorAll(".menu-item-up, .menu-item-down").forEach(t=>{t.addEventListener("click",e.reorderMenuItemsAction)}),document.getElementById("changeDefaultPage").addEventListener("change",o.changeDefaultPage)}constructEditableFieldsAction(){if(this.classList.contains("editTextOpen"))return;this.classList.add("editTextOpen"),o.editableTextArea(this),this.firstChild.focus();const e=this.getElementsByTagName("textarea");autosize(e),tabOverride.set(e)}reorderMenuItemsAction(){const e=this.classList.contains("menu-item-up")?"-1":"1";o.sendPostRequest("menuItems",e,"menuItemOrder",this.dataset.menu)}hideOrShowMenuItemsAction(){const e=this;let t=null;if(e.classList.contains("menu-item-hide"))e.classList.remove("eyeShowIcon","menu-item-hide"),e.classList.add("eyeHideIcon","menu-item-show"),e.setAttribute("title","Hide page from menu"),t="hide";else{if(!e.classList.contains("menu-item-show"))return;e.classList.add("eyeShowIcon","menu-item-hide"),e.classList.remove("eyeHideIcon","menu-item-show"),e.setAttribute("title","Show page in menu"),t="show"}e.setAttribute("data-visibility",t),o.sendPostRequest("menuItems"," ","menuItemVsbl",e.dataset.menu,t)}}const o={openTabAction(e){const t=e.closest(".nav-tabs"),n=e.getAttribute("href").replace("#",""),o=document.getElementById(n),s=o.closest(".tab-content");t.querySelector(".active").classList.remove("active"),s.querySelector(".active").classList.remove("active"),o.classList.add("active"),e.classList.add("active")},toggleModal(e,t){if(t){const t=e.getAttribute("href").replace("#","");document.body.classList.add("modal-open"),document.getElementById(t).style.display="block";const n=e.dataset.targetTab;if(n){const e=document.querySelector('ul.nav-tabs > li > a[href="'+n+'"]');e&&o.openTabAction(e)}}else document.body.classList.remove("modal-open"),e.dataset&&e.dataset.dismiss?e.closest(".wcms-modal").style.display="none":[].forEach.call(document.getElementsByClassName("wcms-modal"),(function(e){e.style.display="none"}))},createNewPage:()=>{let e=prompt("Enter page name");if(!e)return!1;e=e.replace(/[`~;:'",.<>\{\}\[\]\\\/]/gi,"").trim(),o.sendPostRequest("menuItems",e,"menuItem","none","hide")},changeDefaultPage:()=>{o.sendPostRequest("defaultPage",this.value,"config")},contentSave:(e,t,n,s,i,a)=>{if(t!==a)return void o.sendPostRequest(e,t,n,s,i);const c=document.getElementById(e);c.classList.remove("editTextOpen"),c.innerHTML=t},sendPostRequest:(e,t,n,s,i=null)=>{o.showLoader(!0);const a={fieldname:e,token:token,content:encodeURIComponent(t),target:n,menu:s,visibility:i},c=Object.keys(a).map((function(e,t){return[e,a[e]].join("=")})).join("&"),d=new XMLHttpRequest;d.onreadystatechange=function(){setTimeout(()=>window.location.reload(),50)},d.open("POST","",!1),d.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"),d.send(c)},showLoader:(e,t="save")=>{document.getElementById(t).style.display=e?"block":"none"},editableTextArea:e=>{const t=e,n=t.innerHTML,s=t.getAttribute("id"),i=document.createElement("textarea");i.onblur=function(){o.contentSave(s,this.value,t.dataset.target,t.dataset.menu,t.dataset.visibility,n)},i.setAttribute("id",s+"_field"),i.innerHTML=n,e.innerHTML="",e.appendChild(i)}};document.addEventListener("DOMContentLoaded",(function(){new n}))}]);