function preg_quote(e,t){return(e+"").replace(new RegExp("[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\"+(t||"")+"-]","g"),"\\$&")}var Formula={init:function(){Formula.initValue(),Formula.initEvent(),Formula.initSubmit()},render:function(){var e=$.trim($("#editor").val()),t=$("#preview");e?(e=encodeURIComponent(e),e=editor.getOpt("formulaConfig").imageUrlTemplate.replace(/\{\}/,e),$("#previewImage").attr("src",e),t.show()):t.hide()},initValue:function(){var e=editor.selection.getRange().getClosedNode();!e||null===e.getAttribute("data-formula-image")||(e=e.getAttribute("data-formula-image"))&&($("#editor").val(decodeURIComponent(e)),Formula.render())},initEvent:function(){var e=null;$("#editor").on("change keypress",function(){e&&clearTimeout(e),e=setTimeout(function(){Formula.render()},1e3)}),$("#inputDemo").on("click",function(){$("#editor").val("f(a) = \\frac{1}{2\\pi i} \\oint\\frac{f(z)}{z-a}dz"),Formula.render()})},initSubmit:function(){dialog.onok=function(){editor.execCommand("formula",$.trim($("#editor").val())),editor.fireEvent("saveScene")},dialog.oncancel=function(){}}};