From 4fad8668e2a373d4d88afce760fd39f59243af14 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Sun, 27 Sep 2015 21:04:59 +0100 Subject: [PATCH] update --- assets/js/app.min.js | 2 +- assets/src/js/app.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/assets/js/app.min.js b/assets/js/app.min.js index 1f2b1a56..0ffd6b15 100644 --- a/assets/js/app.min.js +++ b/assets/js/app.min.js @@ -1 +1 @@ -$(document).ready(function(){$(document).pjax("a[data-pjax]","#content")}),$(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}),$("body").on("click",".delete",function(a){return a.preventDefault(),button=$(this),button.data("file")&&confirm("Are you sure you want to delete 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)}):(name=button.parent().parent().attr("for")||button.parent().parent().attr("id")||button.parent().parent().parent().attr("id"),name=name.replace(/\[/,"\\["),name=name.replace(/\]/,"\\]"),console.log(name),$('label[for="'+name+'"]').fadeOut().remove(),$("#"+name).fadeOut().remove()),!1}),$("main").hasClass("browse")&&($(".new").click(function(a){return a.preventDefault(),$(this).data("opened")?($("#new-file").fadeOut(200),$(this).data("opened",!1)):($("#new-file").fadeIn(200),$(this).data("opened",!0)),!1}),$("#new-file").on("keypress","input",function(a){if(13==a.keyCode){a.preventDefault();var b=$(this).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){a.preventDefault(),$('.actions input[type="file"]').click()}),$('input[type="file"]').on("change",function(a){a.preventDefault(),files=a.target.files;var b=new FormData;$.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)})})),$(".editor")[0]&&(editor=!1,preview=$("#preview-area"),textarea=$("#content-area"),$("body").on("keypress","input",function(a){return 13==a.keyCode?(a.preventDefault(),$('input[value="Save"]').focus().click(),!1):void 0}),$("form").submit(function(a){a.preventDefault(),$("#preview-area").html("").fadeOut(),$("#preview").data("previewing","false"),$(".CodeMirror").fadeIn();var b=JSON.stringify($(this).serializeJSON()),c=$(this).find("input[type=submit]:focus");return $.ajax({type:"POST",url:window.location,data:b,headers:{"X-Regenerate":c.data("regenerate"),"X-Schedule":c.data("schedule"),"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)}),!1}),$("body").on("click",".add",function(a){if(a.preventDefault(),$("#new-admin-item-123").length)return console.log("oi"),!1;if(title=$(this).parent().parent(),fieldset=title.parent(),type=fieldset.data("type"),name=fieldset.attr("id"),title.is("h1")&&(fieldset=$(".frontmatter .container"),fieldset.prepend('
'),title=$("#ghost-admin-item-123"),type="object"),title.is("h2")&&(type="object"),"object"==type){if(title.after(''),element=$("#new-admin-item-123"),!document.cookie.replace(/(?:(?:^|.*;\s*)placeholdertip\s*\=\s*([^;]*).*$)|^.*$/,"$1")){var b=new Date;b.setDate(b.getDate()+365),document.cookie="placeholdertip=true; expires="+b.toUTCString+"; path=/",notification({text:'Write the field name and then press enter. If you want to create an array or an object, end the name with ":array" or ":object".',type:"information"})}$(element).keypress(function(a){if(13==a.which){if(a.preventDefault(),value=element.val(),""==value)return element.remove(),!1;if(elements=value.split(":"),elements.length>2)return notification({text:"Invalid syntax. It must be 'name[:type]'.",type:"error"}),!1;if(element.remove(),"undefined"==name?name=elements[0]:name=name+"["+elements[0]+"]",1==elements.length)title.after('
'),title.after('');else{var b='
\r\n

{{ $value.Title }}\r\n\r\n\r\n\r\n\r\n

\r\n
';b="array"==elements[1]?b.replace("{{ $value.Type }}","array"):b.replace("{{ $value.Type }}","object"),b=b.replace("{{ $value.Title }}",elements[0]),b=b.replace("{{ $value.Name }}",name),title.after(b)}return!1}})}return"array"==type&&(name+="[]",input=name,input=input.replace(/\[/,"\\["),input=input.replace(/\]/,"\\]"),input="#"+input,title.after('
')),!1}),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})))}),$.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+'
'};if(a=$.extend({},c,a),noty(a),!document.cookie.replace(/(?:(?:^|.*;\s*)stickynoties\s*\=\s*([^;]*).*$)|^.*$/,"$1")&&!a.timeout){var d=new Date;d.setDate(d.getDate()+365),document.cookie="stickynoties=true; expires="+d.toUTCString+"; path=/",notification({text:"Some notifications are sticky. If it doesn't go away, click to dismiss it.",type:"information"})}}; \ No newline at end of file +$(document).ready(function(){$(document).pjax("a[data-pjax]","#content")}),$(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}),$("body").on("click",".delete",function(a){return a.preventDefault(),button=$(this),button.data("file")&&confirm("Are you sure you want to delete 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)}):(name=button.parent().parent().attr("for")||button.parent().parent().attr("id")||button.parent().parent().parent().attr("id"),name=name.replace(/\[/,"\\["),name=name.replace(/\]/,"\\]"),console.log(name),$('label[for="'+name+'"]').fadeOut().remove(),$("#"+name).fadeOut().remove()),!1}),$("main").hasClass("browse")&&($(".new").click(function(a){return a.preventDefault(),$(this).data("opened")?($("#new-file").fadeOut(200),$(this).data("opened",!1)):($("#new-file").fadeIn(200),$(this).data("opened",!0)),!1}),$("#new-file").on("keypress","input",function(a){if(13==a.keyCode){a.preventDefault();var b=$(this).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})),$(".editor")[0]&&(editor=!1,preview=$("#preview-area"),textarea=$("#content-area"),$("body").on("keypress","input",function(a){return 13==a.keyCode?(a.preventDefault(),$('input[value="Save"]').focus().click(),!1):void 0}),$("form").submit(function(a){a.preventDefault(),$("#preview-area").html("").fadeOut(),$("#preview").data("previewing","false"),$(".CodeMirror").fadeIn();var b=JSON.stringify($(this).serializeJSON()),c=$(this).find("input[type=submit]:focus");return $.ajax({type:"POST",url:window.location,data:b,headers:{"X-Regenerate":c.data("regenerate"),"X-Schedule":c.data("schedule"),"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)}),!1}),$("body").on("click",".add",function(a){if(a.preventDefault(),$("#new-admin-item-123").length)return console.log("oi"),!1;if(title=$(this).parent().parent(),fieldset=title.parent(),type=fieldset.data("type"),name=fieldset.attr("id"),title.is("h1")&&(fieldset=$(".frontmatter .container"),fieldset.prepend('
'),title=$("#ghost-admin-item-123"),type="object"),title.is("h2")&&(type="object"),"object"==type){if(title.after(''),element=$("#new-admin-item-123"),!document.cookie.replace(/(?:(?:^|.*;\s*)placeholdertip\s*\=\s*([^;]*).*$)|^.*$/,"$1")){var b=new Date;b.setDate(b.getDate()+365),document.cookie="placeholdertip=true; expires="+b.toUTCString+"; path=/",notification({text:'Write the field name and then press enter. If you want to create an array or an object, end the name with ":array" or ":object".',type:"information"})}$(element).keypress(function(a){if(13==a.which){if(a.preventDefault(),value=element.val(),""==value)return element.remove(),!1;if(elements=value.split(":"),elements.length>2)return notification({text:"Invalid syntax. It must be 'name[:type]'.",type:"error"}),!1;if(element.remove(),"undefined"==name?name=elements[0]:name=name+"["+elements[0]+"]",1==elements.length)title.after('
'),title.after('');else{var b='
\r\n

{{ $value.Title }}\r\n\r\n\r\n\r\n\r\n

\r\n
';b="array"==elements[1]?b.replace("{{ $value.Type }}","array"):b.replace("{{ $value.Type }}","object"),b=b.replace("{{ $value.Title }}",elements[0]),b=b.replace("{{ $value.Name }}",name),title.after(b)}return!1}})}return"array"==type&&(name+="[]",input=name,input=input.replace(/\[/,"\\["),input=input.replace(/\]/,"\\]"),input="#"+input,title.after('
')),!1}),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})))}),$.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+'
'};if(a=$.extend({},c,a),noty(a),!document.cookie.replace(/(?:(?:^|.*;\s*)stickynoties\s*\=\s*([^;]*).*$)|^.*$/,"$1")&&!a.timeout){var d=new Date;d.setDate(d.getDate()+365),document.cookie="stickynoties=true; expires="+d.toUTCString+"; path=/",notification({text:"Some notifications are sticky. If it doesn't go away, click to dismiss it.",type:"information"})}}; \ No newline at end of file diff --git a/assets/src/js/app.js b/assets/src/js/app.js index 3a12000a..e1a22133 100644 --- a/assets/src/js/app.js +++ b/assets/src/js/app.js @@ -140,6 +140,7 @@ $(document).on('ready pjax:success', function() { $("#upload").click(function(event) { event.preventDefault(); $('.actions input[type="file"]').click(); + return false; }); $('input[type="file"]').on('change', function(event) { @@ -181,6 +182,7 @@ $(document).on('ready pjax:success', function() { }); console.log(data); }); + return false; }); } @@ -400,4 +402,4 @@ $(document).on('ready pjax:success', function() { }); } } -}); \ No newline at end of file +});