!function(e){function r(e,t){e.onbeforeunload=function(){if(t.value!=t.defaultValue)return"edit.areyousure".localize()},t.form.addEvent("submit",function(){localStorage.removeItem(n),e.onbeforeunload=null})}function i(n,r,i){function f(){t=!1}function l(t){r.ifClass(t,o),t&&(e.update(),f())}var s=n=="",o="loading",u,a;if(!i.checked)r.cache&&(r.empty(),r.cache=null);else if(r.cache!=n){r.cache=n,r.ifClass(s,"empty");if(s){r.innerHTML="preview.zone".localize();return}e.Context=="comment"&&(u=$("authorname").value||e.UserName||"AnonymousCoward",a=$("link").value,a&&(u="[{0}|{1}]".xsubs(u,a)),n+="\n\n%%signature\n{0}, [\\{CurrentTimePlugin}]\n/%\n".xsubs(u)),t=!0,(new Request.HTML({url:e.XHRPreview,data:{page:e.PageName,wikimarkup:n,"X-XSRF-TOKEN":e.CsrfProtection},update:r,onRequest:l,onSuccess:l.pass(!0),onError:f})).send()}}function s(e){var t=[],n="¤",r=e.replace(/\{\{\{([\s\S]*?)\}\}\}/g,function(e){return e.replace(/^!/mg," ")}).replace(/^([!]{1,3})/mg,n+"$1"+n).split(n),i=r.shift().length,s=r.length,o,u,a;for(o=0;o<s;o+=2)u=r[o].length,a=r[o+1].split(/[\r\n]/)[0].replace(/(^|[^~])(__|""|\{\{|\}\}|%%\([^)]+\)|%%\S+\s|%%\([^)]+\)|\/%)/g,"$1").replace(/~([^~])/g,"$1").escapeHtml(),t[o/2]={title:a,start:i,depth:3-u},i+=u+r[o+1].length;return t}function o(t){return e.url2links(t.getData("text/uri-list"))||e.html2wiki(t.getData("text/html"))}var t,n;e.add("textarea#editorarea",function(u){function c(e){return a.getElement(e)}var a=u.form,f,l;r(window,u);if(f=c("textarea.snipeable")){f=new Snipe(f,{container:a,undoBtns:{undo:c("[data-cmd=undo]"),redo:c("[data-cmd=redo]")},snippets:e.Snips,directsnips:e.DirectSnips,dragAndDrop:o}),e.configPrefs(a,function(e,t){f.set(e,t)});if(l=c(".ajaxpreview")){var h=!1;setInterval(function(){if(h&&!t){var e=f.get("value").trim();localStorage.setItem(n,e),h=!1,i(e,l,c("[data-cmd=livepreview]"))}},250),f.addEvent("change",function(){h=!0})}new Snipe.Sections(f,{main:u,menu:c(".sections > ul"),parser:s}),n="wiki"+e.PageName;if(n in localStorage){var p=localStorage.getItem(n),d=c(".localstorage");d.appendChild("pre".slick({text:p})).openModal(function(){f.set("value",p)})}}}).add("textarea[name=htmlPageText]",function(){n="wiki"+e.PageName,n in localStorage&&localStorage.removeItem(n)})}(Wiki)