$(document).ready(function(){$("#logout").click(function(a){return a.preventDefault(),$.ajax({type:"GET",url:"/admin",async:!1,username:"username",password:"password",headers:{Authorization:"Basic xxx"}}).fail(function(){window.location="/"}),!1}),$(document).pjax("a[data-pjax]","#content")}),$(document).on("ready pjax:success",function(){function a(){this.style.height="5px",this.style.height=this.scrollHeight+"px"}return document.title=document.getElementById("site-title").innerHTML,$("textarea").each(a),$("textarea").keyup(a),$(window).resize(function(){$("textarea").each(a)}),$("main").hasClass("browse")&&$(document).trigger("page:browse"),$(".editor")[0]&&$(document).trigger("page:editor"),!1}),$(document).on("page:browse",function(){$("body").off("click",".rename").on("click",".rename",function(a){a.preventDefault(),button=$(this);var b=prompt("New file name:");if(""==b)return!1;"/"!=b.substring(0,1)&&(b=window.location.pathname.replace("/admin/browse/","")+"/"+b);var c='{"filename": "'+b+'"}';return $.ajax({type:"PUT",url:button.data("file"),data:c,dataType:"json",encode:!0}).done(function(a){$.pjax({url:window.location.pathname,container:"#content"}),notification({text:button.data("message"),type:"success",timeout:5e3})}).fail(function(a){notification({text:"Something went wrong.",type:"error"}),console.log(a)}),!1}),$("body").off("click",".delete").on("click",".delete",function(a){return a.preventDefault(),button=$(this),$.ajax({type:"DELETE",url:button.data("file")}).done(function(a){button.parent().parent().fadeOut(),notification({text:button.data("message"),type:"success",timeout:5e3})}).fail(function(a){notification({text:"Something went wrong.",type:"error"}),console.log(a)}),!1}),$(".new").off("click").click(function(a){return a.preventDefault(),$(this).data("opened")?($(".foreground").fadeOut(200),$("#new-file-form").fadeOut(200),$(this).data("opened",!1)):($(".foreground").fadeIn(200),$("#new-file-form").fadeIn(200),$(this).data("opened",!0)),!1}),$(".foreground").off("click").click(function(){$(".input").fadeOut(200),$(".foreground").fadeOut(200),$(".new").data("opened",!1)}),$("#new-file-form").submit(function(a){a.preventDefault();var b=$("#new-file-name").val(),c=b.split(":"),d="",e="";if(""==b)return notification({text:"You have to write something. If you want to close the box, click the button again.",type:"warning",timeout:5e3}),!1;if(1==c.length)d=b;else{if(2!=c.length)return notification({text:"Hmm... I don't understand you. Try writing something like 'name[:archetype]'.",type:"error"}),!1;d=c[0],e=c[1]}var f='{"filename": "'+d+'", "archetype": "'+e+'"}';return $.ajax({type:"POST",url:window.location.pathname,data:f,dataType:"json",encode:!0}).done(function(a){notification({text:"File created successfully.",type:"success",timeout:5e3}),$.pjax({url:window.location.pathname.replace("browse","edit")+d,container:"#content"})}).fail(function(a){notification({text:"Something went wrong.",type:"error"}),console.log(a)}),!1}),$("#upload").click(function(a){return a.preventDefault(),$('.actions input[type="file"]').click(),!1}),$('input[type="file"]').on("change",function(a){a.preventDefault(),files=a.target.files;var b=new FormData;return $.each(files,function(a,c){b.append(a,c)}),$.ajax({url:window.location.pathname,type:"POST",data:b,cache:!1,dataType:"json",headers:{"X-Upload":"true"},processData:!1,contentType:!1}).done(function(a){notification({text:"File(s) uploaded successfully.",type:"success",timeout:5e3}),$.pjax({url:window.location.pathname,container:"#content"})}).fail(function(a){notification({text:"Something went wrong.",type:"error"}),console.log(a)}),!1})}),$(document).on("page:editor",function(){var a=$(".editor"),b=$("#editor-preview"),c=$("#editor-source");if(a.hasClass("complete")&&$("#site-title").keyup(function(){$(".frontmatter #title").val($(this).val())}),!a.hasClass("frontmatter-only")){var d=$("#editor-source").data("mode"),e=$('textarea[name="content"]').hide(),f=ace.edit("editor-source");f.getSession().setMode("ace/mode/"+d),f.getSession().setValue(e.val()),f.getSession().on("change",function(){e.val(f.getSession().getValue())}),f.setOptions({wrap:!0,maxLines:1/0,theme:"ace/theme/github",showPrintMargin:!1,fontSize:"1em"}),$("#see-source").off("click").click(function(a){a.preventDefault(),b.hide(),c.fadeIn(),$("#see-preview").data("previewing","false")}),$("#see-preview").off("click").click(function(a){if(a.preventDefault(),"true"==$(this).data("previewing"))b.hide(),c.fadeIn(),$(this).data("previewing","false");else{var d=new showdown.Converter,e=f.getValue(),g=d.makeHtml(e);c.hide(),b.html(g).fadeIn(),$(this).data("previewing","true")}return!1})}$("body").off("keypress","input").on("keypress","input",function(a){return 13==a.keyCode?(a.preventDefault(),$('input[value="Save"]').focus().click(),!1):void 0}),$("form").submit(function(d){d.preventDefault(),a.hasClass("frontmatter-only")||(b.html("").fadeOut(),$("#see-preview").data("previewing","false"),c.fadeIn());var e=JSON.stringify($(this).serializeJSON()),f=$(this).find("input[type=submit]:focus");return $.ajax({type:"POST",url:window.location,data:e,headers:{"X-Regenerate":f.data("regenerate"),"X-Schedule":f.data("schedule"),"X-Content-Type":f.data("type")},dataType:"json",encode:!0,contentType:"application/json; charset=utf-8"}).done(function(a){notification({text:f.data("message"),type:"success",timeout:5e3})}).fail(function(a){notification({text:"Something went wrong.",type:"error"}),console.log(a)}),!1}),$("body").on("click",".add",function(a){if(a.preventDefault(),defaultID="lorem-ipsum-sin-dolor-amet",$("#"+defaultID).length)return!1;if(block=$(this).parent().parent(),blockType=block.data("type"),blockID=block.attr("id"),block.is("div")&&block.hasClass("frontmatter")&&(block=$(".blocks"),block.append('
'),blockType="object"),"array"==blockType&&(newID=blockID+"[]",input=blockID,input=input.replace(/\[/,"\\["),input=input.replace(/\]/,"\\]"),block.append('