$(document).ready(function(){$(document).pjax("a","#main")}),$(document).on("ready pjax:success",function(){$(".scroll").perfectScrollbar(),$("#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}),$(".editor")[0]&&(editor=!1,preview=$("#preview-area"),textarea=$("#content-area"),textarea[0]&&(options={mode:textarea.data("mode"),theme:"mdn-like",lineWrapping:!0,lineNumbers:!0,scrollbarStyle:null},"markdown"==textarea.data("mode")&&(options.lineNumbers=!1),editor=CodeMirror.fromTextArea(textarea[0],options),codemirror=$(".CodeMirror"),$("#preview").click(function(a){if(a.preventDefault(),"true"==$(this).data("previewing"))preview.hide(),codemirror.fadeIn(),$(this).data("previewing","false"),notification({text:"Think, relax and do the better you can!",type:"information",timeout:2e3});else{editor.save();var b=new showdown.Converter,c=textarea.val(),d=b.makeHtml(c);codemirror.hide(),preview.html(d).fadeIn(),$(this).data("previewing","true"),notification({text:"This is how your post looks like.",type:"information",timeout:2e3})}return!1})),$("form").submit(function(a){a.preventDefault();var b=JSON.stringify($(this).serializeJSON()),c=$(this).find("input[type=submit]:focus");$.ajax({type:"POST",url:window.location,data:b,headers:{"X-Regenerate":c.data("regenerate"),"X-Content-Type":c.data("type")},dataType:"json",encode:!0}).done(function(a){notification({text:c.data("message"),type:"success",timeout:5e3})}).fail(function(a){notification({text:"Something went wrong.",type:"error"}),console.log(a)})}),$(".add").click(function(a){return a.preventDefault(),$("#new").length?!1:(title=$(this).parent().parent(),fieldset=title.parent(),type=fieldset.data("type"),name=fieldset.data("name"),title.is("h1")&&(fieldset=$(".sidebar .content"),fieldset.prepend('
'),title=$("#ghost"),type="object"),"object"==type&&(title.after(''),element=$("#new"),$(element).keypress(function(a){return 13==a.which?(a.preventDefault(),value=element.val(),element.remove(),""==value?!1:("undefined"==name?name=value:name=name+"["+value+"]",title.after('
'),title.after(''),!1)):void 0})),"array"==type&&(name+="[]",title.after('
')),!1)}),$("body").on("keypress","input",function(a){return 13==a.keyCode?(a.preventDefault(),$('input[value="Save"]').focus().click(),!1):void 0}))}),$(document).on("pjax:send",function(){$("#loading").fadeIn()}),$(document).on("pjax:complete",function(){$("#loading").fadeOut()}),$.noty.themes.admin={name:"admin",helpers:{},modal:{css:{position:"fixed",width:"100%",height:"100%",backgroundColor:"#000",zIndex:1e4,opacity:.6,display:"none",left:0,top:0}}},$.noty.defaults={layout:"topRight",theme:"admin",dismissQueue:!0,animation:{open:"animated bounceInRight",close:"animated fadeOut",easing:"swing",speed:500},timeout:!1,force:!1,modal:!1,maxVisible:5,killer:!1,closeWith:["click"],callback:{onShow:function(){},afterShow:function(){},onClose:function(){},afterClose:function(){},onCloseClick:function(){}},buttons:!1},notification=function(a){var b;switch(a.type){case"success":b='';break;case"error":b='';break;case"warning":b='';break;case"information":b='';break;default:b=''}var c={template:'
'+b+'
'};a=$.extend({},c,a),noty(a)};