Liferay.Loader.define("wiki-web@7.0.40/wiki/js/WikiPortlet.es",["module","exports","require","frontend-js-web"],(function(t,e,n){window;{Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var o=n("frontend-js-web");const t=Liferay.Language.get("uploads-are-in-progress-confirmation"),r=Liferay.Language.get("you-may-lose-formatting-when-switching-from-x-to-x");class i{constructor({constants:e,currentAction:n,namespace:o,renderUrl:s,rootNodeId:i,strings:a={confirmDiscardImages:t,confirmLoseFormatting:r}}){this._constants=e,this._currentAction=n,this._namespace=o,this._renderUrl=s,this._strings=a,this.rootNode=document.getElementById(i),this.workflowActionInputNode=document.getElementById("".concat(o,"workflowAction")),this._events=[],this._attachEvents()}dispose(){this._events.forEach((({event:t,listener:e,target:n})=>n.removeEventListener(t,e))),this._events=[]}_addEventListener(t,e,n){t.addEventListener(e,n),this._events.push({event:e,fn:n,target:t})}_attachEvents(){const t=this._namespace,e=document.getElementById("".concat(t,"format"));e&&(this._currentFormatLabel=e.options[e.selectedIndex].text.trim(),this._currentFormatIndex=e.selectedIndex,this._addEventListener(e,"change",(t=>{this._changeWikiFormat(t)})));const n=document.getElementById("".concat(t,"publishButton"));n&&this._addEventListener(n,"click",(()=>{this.workflowActionInputNode.value=this._constants.ACTION_PUBLISH,this._save()}));const o=document.getElementById("".concat(t,"saveButton"));o&&this._addEventListener(o,"click",(()=>{this.workflowActionInputNode.value=this._constants.ACTION_SAVE_DRAFT,this._save()}));const s="".concat(t,"pageAttachments");Liferay.componentReady(s).then((t=>{t.get("contentBox").delegate("click",this._removeAttachment.bind(this),".delete-attachment")})),this.searchContainerId=s}_changeWikiFormat(t){const e=t.currentTarget,n=e.options[e.selectedIndex].text.trim(),o=Liferay.Util.sub(this._strings.confirmLoseFormatting,this._currentFormatLabel,n);if(confirm(o)){this.rootNode.querySelector('[name="'.concat(this._namespace,'fm"]')).setAttribute("action",this._renderUrl),this._save()}else e.selectedIndex=this.currentFormatIndex}_removeAttachment(t){const e=t.currentTarget,n=e.getAttribute("data-url");(0,o.fetch)(n).then((()=>{Liferay.componentReady(this.searchContainerId).then((t=>{t.deleteRow(e.ancestor("tr"),e.getAttribute("data-rowid")),t.updateDataStore()}))}))}_removeTempImages(){const t=this.rootNode.querySelector("img[data-random-id]");let e=!0;return t&&t.length>0&&(confirm(this._strings.confirmDiscardImages)?t.forEach((t=>{t.parentElement.remove()})):e=!1),e}_save(){const t=this._namespace;if(this._removeTempImages()){document.getElementById(t+this._constants.CMD).value=this._currentAction;const e=window["".concat(t,"contentEditor")];e&&(document.getElementById("".concat(t,"content")).value=e.getHTML()),submitForm(document["".concat(t,"fm")])}}}var s=i;e.default=s}}));
//# sourceMappingURL=WikiPortlet.es.js.map