HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-160-generic #170-Ubuntu SMP Wed Oct 1 10:06:56 UTC 2025 x86_64
User: xnsbb3110 (1041)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: /home/shaping-sar.ru/public_html/wp-content/plugins/cyr2lat/assets/js/apps/tables.js
(()=>{"use strict";function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(e){return function(e){if(Array.isArray(e))return i(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return i(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?i(e,t):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var i=0,n=Array(t);i<t;i++)n[i]=e[i];return n}function n(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,a(n.key),n)}}function a(t){var i=function(t,i){if("object"!=e(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var a=n.call(t,i||"default");if("object"!=e(a))return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===i?String:Number)(t)}(t,"string");return"symbol"==e(i)?i:i+""}var s=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.OPTIONS_FORM_SELECTOR="#ctl-options",this.HEADER_SELECTOR=this.OPTIONS_FORM_SELECTOR+" h2",this.TABLE_SELECTOR=this.OPTIONS_FORM_SELECTOR+" table",this.SUBMIT_SELECTOR=this.OPTIONS_FORM_SELECTOR+" #submit",this.CURRENT_STUB_ID="ctl-current",this.CURRENT_NAV_TAB_CLASS="nav-tab-current",this.ACTIVE_NAV_TAB_CLASS="nav-tab-active",this.ACTIVE_TABLE_CLASS="active",this.EDIT_LABEL_ID="ctl-edit-label",this.EDIT_LABEL_ERROR_CLASS="ctl-edit-label-error",this.plusButton='<button type="button" aria-haspopup="true" aria-expanded="false" class="components-button block-editor-inserter__toggle has-icon" aria-label="Добавить блок"><svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" viewBox="-2 -2 24 24" role="img" aria-hidden="true" focusable="false"><path d="M10 1c-5 0-9 4-9 9s4 9 9 9 9-4 9-9-4-9-9-9zm0 16c-3.9 0-7-3.1-7-7s3.1-7 7-7 7 3.1 7 7-3.1 7-7 7zm1-11H9v3H6v2h3v3h2v-3h3V9h-3V6zM10 1c-5 0-9 4-9 9s4 9 9 9 9-4 9-9-4-9-9-9zm0 16c-3.9 0-7-3.1-7-7s3.1-7 7-7 7 3.1 7 7-3.1 7-7 7zm1-11H9v3H6v2h3v3h2v-3h3V9h-3V6z"></path></svg></button>',this.PLUS_CLASS="ctl-plus",this.optionsForm=document.querySelector(this.OPTIONS_FORM_SELECTOR),this.tablesData=this.getTablesData(),this.submitButton=document.querySelector(this.SUBMIT_SELECTOR),this.addWrapper(),this.addMessageLines(),this.moveTabs(),this.addEditLabelInput(),this.hideTables(),this.bindEvents(),this.setSubmitStatus(),this.checkLocale()},i=[{key:"getHeaders",value:function(){return t(document.querySelectorAll(this.HEADER_SELECTOR))}},{key:"getActiveHeader",value:function(){return document.querySelector(this.HEADER_SELECTOR+"."+this.ACTIVE_NAV_TAB_CLASS)}},{key:"getActiveIndex",value:function(){return this.getActiveHeader().dataset.index}},{key:"getTables",value:function(){return t(document.querySelectorAll(this.TABLE_SELECTOR))}},{key:"getActiveTable",value:function(){return document.querySelector(this.TABLE_SELECTOR+"."+this.ACTIVE_TABLE_CLASS)}},{key:"getInputs",value:function(){return t(document.querySelectorAll(this.OPTIONS_FORM_SELECTOR+" input"))}},{key:"getLabels",value:function(){return t(document.querySelectorAll(this.OPTIONS_FORM_SELECTOR+" label"))}},{key:"getPlusButtons",value:function(){return t(document.querySelectorAll(this.OPTIONS_FORM_SELECTOR+" ."+this.PLUS_CLASS))}},{key:"isActiveTableChanged",value:function(){var e=this.getActiveIndex();return JSON.stringify(this.getActiveTableData())!==JSON.stringify(this.tablesData[e])}},{key:"setSubmitStatus",value:function(){this.submitButton.disabled=!this.isActiveTableChanged()}},{key:"checkLocale",value:function(){var e=Cyr2LatTablesObject.ctlLocale;e="ru_RU"===e?"ISO9":e;var t=this.getActiveTableLocale();t!==e?this.showMessage(this.warningMessage,Cyr2LatTablesObject.localeWarning.replace("{active_table}",t)):this.clearMessage(this.warningMessage)}},{key:"saveActiveTable",value:function(){var e=this;if(this.isActiveTableChanged()){var i=this.getActiveTable(),n=document.createElement("form");n.action=this.optionsForm.getAttribute("action"),n.method=this.optionsForm.method,n.appendChild(i.cloneNode(!0)),t(i.querySelectorAll("input")).map((function(e){return n.querySelector("#"+e.id).value=e.value})),t(this.optionsForm.querySelectorAll('input[type="hidden"]')).map((function(e){return n.appendChild(e.cloneNode(!0))})),document.body.appendChild(n);var a=new URLSearchParams(t(new FormData(n)));return a.append("action",Cyr2LatTablesObject.action),a.append("nonce",Cyr2LatTablesObject.nonce),fetch(Cyr2LatTablesObject.ajaxUrl,{method:"POST",body:a}).then((function(e){if(!e.ok)throw new Error(e.statusText);return e.json()})).then((function(t){t.success?(e.showMessage(e.successMessage,t.data),e.tablesData=e.getTablesData()):e.showMessage(e.errorMessage,t.data)})).catch((function(t){return e.showMessage(e.errorMessage,t),{}})).finally((function(){n.parentNode.removeChild(n),e.setSubmitStatus()}))}}},{key:"getTableData",value:function(e){var i=this,n=t(e.querySelectorAll("input")),a={};return n.forEach((function(e){var t=document.querySelector(i.OPTIONS_FORM_SELECTOR+' label[for="'+e.id+'"]');a[t.innerHTML]=e.value})),a}},{key:"getTablesData",value:function(){var e=this;return this.getTables().map((function(t){return e.getTableData(t)}))}},{key:"getActiveTableData",value:function(){return this.getTableData(this.getActiveTable())}},{key:"getActiveTableLocale",value:function(){return this.getActiveTable().querySelector("tr").classList[0].replace("cyr-to-lat-tables-","").replace("-","_")}},{key:"addWrapper",value:function(){this.wrapper=document.createElement("ul"),this.wrapper.classList.add("nav-tab-wrapper"),this.optionsForm.insertBefore(this.wrapper,this.optionsForm.firstChild)}},{key:"addMessageLine",value:function(e){var t=document.createElement("div");return t.id=e,this.optionsForm.insertBefore(t,this.optionsForm.firstChild),t}},{key:"addMessageLines",value:function(){this.successMessage=this.addMessageLine("ctl-success"),this.errorMessage=this.addMessageLine("ctl-error"),this.warningMessage=this.addMessageLine("ctl-warning")}},{key:"moveTabs",value:function(){var e=document.querySelector(".ctl-settings-tabs");e&&this.optionsForm.insertBefore(e,this.optionsForm.firstChild)}},{key:"addEditLabelInput",value:function(){this.editLabelInput=document.createElement("input"),this.editLabelInput.id=this.EDIT_LABEL_ID,this.editLabelInput.style.display="none",document.body.appendChild(this.editLabelInput)}},{key:"hideEditLabelInput",value:function(){this.editLabelInput.style.display="none",this.editLabelInput.classList.remove(this.EDIT_LABEL_ERROR_CLASS),document.body.appendChild(this.editLabelInput)}},{key:"getLastCell",value:function(){return document.querySelector(this.OPTIONS_FORM_SELECTOR+" ."+this.ACTIVE_TABLE_CLASS+" ."+this.PLUS_CLASS).previousElementSibling}},{key:"addCell",value:function(){var e=this.getLastCell();e.parentElement.insertBefore(e.cloneNode(!0),e.nextElementSibling);var t=(e=this.getLastCell()).querySelector("label"),i=e.querySelector("input"),n=i.id.split("-"),a=n[0]+"-"+(parseInt(n[1])+1);t.htmlFor=a,t.innerHTML="",i.id=a,i.value="",i.setAttribute("value",""),this.replaceName(i,""),this.bindEvents(),this.editLabel(t)}},{key:"hideTables",value:function(){var e=this,t=0;this.getTables().map((function(i,n){i.classList.add("ctl-table"),e.CURRENT_STUB_ID===i.previousElementSibling.id&&(t=n,i.classList.add(e.ACTIVE_TABLE_CLASS));var a=document.createElement("div");return a.classList.add(e.PLUS_CLASS),a.innerHTML=e.plusButton,i.querySelector("td fieldset").appendChild(a),null})),this.getHeaders().map((function(i,n){return i.classList.add("nav-tab"),i.dataset.index=n.toString(),e.wrapper.appendChild(i),n===t&&(i.classList.add(e.CURRENT_NAV_TAB_CLASS),i.classList.add(e.ACTIVE_NAV_TAB_CLASS)),null}))}},{key:"bindEvents",value:function(){var e=this;this.getHeaders().map((function(t,i,n){return t.onclick=function(t){t.preventDefault();var i=t.target.dataset.index;if(i===e.getActiveIndex())return!1;e.saveActiveTable(),n.map((function(t){return t.classList.remove(e.ACTIVE_NAV_TAB_CLASS)})),n[i].classList.add(e.ACTIVE_NAV_TAB_CLASS);var a=e.getTables();return a.map((function(t){return t.classList.remove(e.ACTIVE_TABLE_CLASS)})),a[i].classList.add(e.ACTIVE_TABLE_CLASS),e.setSubmitStatus(),e.checkLocale(),!1},null})),this.getInputs().map((function(t){return t.oninput=function(){e.setSubmitStatus()},null})),this.getLabels().map((function(t){return t.onclick=function(t){return t.preventDefault(),e.editLabel(t.target),!1},null})),this.editLabelInput.onblur=function(){e.saveLabel()},this.editLabelInput.onkeyup=function(t){"Escape"===t.key&&e.saveLabel(!0),"Enter"===t.key&&e.saveLabel()},this.getPlusButtons().map((function(t){return t.onclick=function(t){return t.preventDefault(),e.addCell(t.target),!1},null})),this.submitButton.onclick=function(t){return t.preventDefault(),e.saveActiveTable(),!1}}},{key:"editLabel",value:function(e){e.parentNode.insertBefore(this.editLabelInput,e.nextSibling),this.editLabelInput.value=e.innerHTML,this.editLabelInput.classList.remove(this.EDIT_LABEL_ERROR_CLASS),this.editLabelInput.style.display="block",this.editLabelInput.focus()}},{key:"isUniqueLabel",value:function(e){return t(this.getActiveTable().querySelectorAll("label")).reduce((function(t,i){return t&&i.innerHTML!==e}),!0)}},{key:"saveLabel",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if("none"!==this.editLabelInput.style.display){var t=this.editLabelInput.value.trim();if(""===t){var i=document.getElementById(this.EDIT_LABEL_ID).parentElement;return this.hideEditLabelInput(),i.parentNode.removeChild(i),void this.setSubmitStatus()}var n=this.editLabelInput.parentNode.querySelector("label");if(e||t===n.innerHTML)this.hideEditLabelInput();else if(this.isUniqueLabel(t)){var a=this.editLabelInput.nextElementSibling;this.hideEditLabelInput(),n.innerHTML=t,this.replaceName(a,t),this.setSubmitStatus()}else this.editLabelInput.classList.add(this.EDIT_LABEL_ERROR_CLASS)}}},{key:"replaceName",value:function(e,t){e.name=e.name.replace(/(.+\[.+])\[.*]/g,"$1["+t+"]")}},{key:"clearMessage",value:function(e){e.innerHTML="",e.classList.remove("active")}},{key:"clearMessages",value:function(){this.clearMessage(this.successMessage),this.clearMessage(this.errorMessage),clearTimeout(this.msgTimer)}},{key:"showMessage",value:function(e,t){var i=this;e.innerHTML=t,e.classList.add("active"),this.msgTimer=setTimeout((function(){i.clearMessages()}),5e3)}}],i&&n(e.prototype,i),a&&n(e,a),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,i,a}();const r=s;document.addEventListener("DOMContentLoaded",(function(){new r}))})();