/* 3.4.1 */ 
document.addEventListener("DOMContentLoaded",(function(){var e=document.querySelector(".ace-editor");if(e){var t=document.createElement("div");t.id="codemirror-container",e.parentNode.insertBefore(t,e),e.style.display="none";var r=document.getElementById("content_type"),n=r?r.value.toLowerCase():"xml",o=window.initCodeMirror("codemirror-container",e.value,!1,n,d),a=document.getElementById("content-error");t.appendChild(a);var i=e.value;setInterval((function(){if(o){var t=window.getCodeMirrorValue(o);t!==i&&(e.value=t,i=t)}}),100),r&&r.addEventListener("change",(function(){var e=this.value.toLowerCase();e!==n&&function(e){if(o){var r=window.getCodeMirrorValue(o);o._cleanupCallback&&o._cleanupCallback(),o.destroy(),t.innerHTML="",t.appendChild(a),o=window.initCodeMirror("codemirror-container",r,!1,e.toLowerCase(),d),n=e.toLowerCase()}}(e)})),document.getElementById("template-form").addEventListener("submit",(function(t){var r=window.getCodeMirrorValue(o);e.value=r;var n=document.getElementById("content_type").value;try{if("JSON"===n.toUpperCase())try{"JSON"===n.toUpperCase()?function(e,t){JSON.parse(e),t.classList.add("hide")}(r,a):function(e,t){if((new DOMParser).parseFromString(e,"text/xml").getElementsByTagName("parsererror").length>0)throw t.classList.remove("hide"),new Error("XML parsing failed");t.classList.add("hide")}(r,a)}catch(e){return t.preventDefault(),function(e,t){e.classList.remove("hide"),e.textContent=t}(a,"JSON"===n.toUpperCase()?"JSON Error: "+e.message:"XML Error: "+e.message),!1}}catch(e){return t.preventDefault(),a.textContent="XML Error: "+e.message,!1}})),t.addEventListener("focusin",(function(){$.Shortcuts.stop()})),t.addEventListener("focusout",(function(){$.Shortcuts.start()}))}function d(t){e.value=t}}));