filebrowser/assets/public/js/app.min.js

1 line
12 KiB
JavaScript
Raw Normal View History

$(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:end",function(){function a(){this.style.height="5px",this.style.height=this.scrollHeight+"px"}return $("#content").off(),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(){var a="#foreground",b="form#delete",c=null;$("#content").on("click",".delete",function(d){return d.preventDefault(),c=new Object,c.url=$(this).data("file"),c.row=$(this).parent().parent(),c.filename=$(c.row).find(".filename").text(),$(b).find("span").text(c.filename),$(b).fadeIn(200),$(a).fadeIn(200),!1}),$("#content").on("submit",b,function(d){if(d.preventDefault(),null==c)return notification({text:"Something is wrong with your form.",type:"error"}),!1;var e=new XMLHttpRequest;return e.open("DELETE",c.url),e.send(),e.onreadystatechange=function(){if(4==e.readyState){var d=JSON.parse(e.responseText),f="success",g=5e3;$(a).fadeOut(200),$(b).fadeOut(200),$(c.row).fadeOut(200),200!=e.status&&(f="error",g=!1),notification({text:d.message,type:f,timeout:g}),c=null}},!1}),$("#content").on("change",'input[type="file"]',function(a){a.preventDefault(),files=a.target.files,$("#loading").fadeIn();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}),$("#loading").fadeOut(),$.pjax({url:window.location.pathname,container:"#content"})}).fail(function(a){$("#loading").fadeOut(),notification({text:"Something went wrong.",type:"error"}),console.log(a)}),!1}),$("#content").on("click","#upload",function(a){return a.preventDefault(),$('.actions input[type="file"]').click(),!1});var d="form#new",e=d+' input[type="text"]';$("#content").on("click",".new",function(b){return b.preventDefault(),$(a).fadeIn(200),$(d).fadeIn(200),!1}),$("#content").on("keypress",e,function(a){return 13==a.keyCode?(a.preventDefault(),$(d).submit(),!1):void 0}),$("#content").on("submit",d,function(a){a.preventDefault();var b=$(e).val(),c=b.split(":"),d="",f="";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],f=c[1]}var g={filename:d,archetype:f},h=new XMLHttpRequest;return h.open("POST",window.location.pathname),h.setRequestHeader("Content-Type","application/json;charset=UTF-8"),h.send(JSON.stringify(g)),h.onreadystatechange=function(){if(4==h.readyState){var a=JSON.parse(h.responseText),b="success",c=5e3;200!=h.status&&(b="error",c=!1),notification({text:a.message,type:b,timeout:c}),200==h.status&&$.pjax({url:a.location,container:"#content"})}},!1});var f="form#rename",g=f+' input[type="text"]',h=null;$("#content").on("click",".rename",function(b){return b.preventDefault(),h=$(this).parent().parent().find(".filename").text(),$(a).fadeIn(200),$(f).fadeIn(200),$(f).find("span").text(h),$(f).find('input[type="text"]').val(h),!1}),$("#content").on("keypress",g,function(a){return 13==a.keyCode?(a.preventDefault(),$(f).submit(),!1):void 0}),$("#content").on("submit",f,function(a){a.preventDefault();var b=$(this).find('input[type="text"]').val();if(""===b)return!1;"/"!=b.substring(0,1)&&(b=window.location.pathname.replace("/admin/browse/","")+"/"+b);var c={filename:b},d=new XMLHttpRequest;return d.open("PU