This commit is contained in:
Henrique Dias committed 2016-01-31 22:24:04 +00:00
1 parent 94a71a6eb3
commit 7a2f1965e3
2 files changed
+18 -15

No files matched your search

+1 -1
View File
@@ -1 +1 @@
$(document).ready(function(){$(document).pjax("a[data-pjax]","#content")}),$(document).on("ready pjax:success",function(){function a(a){this.style.height="5px",this.style.height=this.scrollHeight+"px"}if($(".datetimepicker").datetimepicker({format:"Y-m-d H:i:s+00:00"}),$("#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]){$("textarea").keyup(a),$("textarea").each(a);var b=ace.edit("source-area");b.getSession().setMode("ace/mode/markdown"),b.setOptions({wrap:!0,maxLines:1/0,theme:"ace/theme/github",showPrintMargin:!1,fontSize:"1em"}),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(),"undefined"!=typeof b&&b&&b.save();var c=JSON.stringify($(this).serializeJSON()),d=$(this).find("input[type=submit]:focus");return $.ajax({type:"POST",url:window.location,data:c,headers:{"X-Regenerate":d.data("regenerate"),"X-Schedule":d.data("schedule"),"X-Content-Type":d.data("type")},dataType:"json",encode:!0,contentType:"application/json; charset=utf-8"}).done(function(a){notification({text:d.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){return a.preventDefault(),defaultId="new-admin-item-123",$("#"+defaultId).length?!1:(fieldset=$(this).parent().parent(),type=fieldset.data("type"),name=fieldset.attr("id"),fieldset.is("div")&&fieldset.hasClass("frontmatter")&&(fieldset=$(".blocks"),fieldset.prepend('<div class="block" id="'+defaultId+'"></div>'),title=$("#"+defaultId),type="object"),"array"==type&&(name+="[]",input=name,input=input.replace(/\[/,"\\["),input=input.replace(/\]/,"\\]"),input="#"+input,fieldset.append('<div id="'+name+"-"+$(input).length+'" data-type="array-item"><input name="'+name+':auto" id="'+name+'"></input><span class="actions"> <button class="delete">&#8722;</button></span></div></div>')),!1)}),textarea[0]&&(options={mode:textarea.data("mode"),theme:"ttcn",lineWrapping:!0,lineNumbers:!0,scrollbarStyle:null},"markdown"==textarea.data("mode")&&(options.lineNumbers=!1),b=CodeMirLine truncated
$(document).ready(function(){$(document).pjax("a[data-pjax]","#content")}),$(document).on("ready pjax:success",function(){function a(a){this.style.height="5px",this.style.height=this.scrollHeight+"px"}if($(".datetimepicker").datetimepicker({format:"Y-m-d H:i:s+00:00"}),$("#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]){$("textarea").keyup(a),$("textarea").each(a);var b=ace.edit("source-area");b.getSession().setMode("ace/mode/markdown"),b.setOptions({wrap:!0,maxLines:1/0,theme:"ace/theme/github",showPrintMargin:!1,fontSize:"1em"}),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(),"undefined"!=typeof b&&b&&b.save();var c=JSON.stringify($(this).serializeJSON()),d=$(this).find("input[type=submit]:focus");return $.ajax({type:"POST",url:window.location,data:c,headers:{"X-Regenerate":d.data("regenerate"),"X-Schedule":d.data("schedule"),"X-Content-Type":d.data("type")},dataType:"json",encode:!0,contentType:"application/json; charset=utf-8"}).done(function(a){notification({text:d.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="new-admin-item-123",$("#"+defaultId).length)return!1;if(fieldset=$(this).parent().parent(),type=fieldset.data("type"),name=fieldset.attr("id"),newItem="",fieldset.is("div")&&fieldset.hasClass("frontmatter")&&(fieldset=$(".blocks"),fieldset.prepend('<div class="block" id="'+defaultId+'"></div>'),newItem=$("#"+defaultId),type="object"),"array"==type&&(name+="[]",input=name,input=input.replace(/\[/,"\\["),input=input.replace(/\]/,"\\]"),input="#"+input,fieldset.append('<div id="'+name+"-"+$(input).length+'" data-type="array-item"><input name="'+name+':auto" id="'+name+'"></input><span class="actions"> <button class="delete">&#8722;</button></span></div></div>')),"object"==type){if(newItem.html('<input id="name-'+defaultId+'" placeholder="Write the field name and press enter..."></input>'),element=$("#name-"+defaultId),!document.cookLine truncated
+17 -14
View File
@@ -280,12 +280,13 @@ $(document).on('ready pjax:success', function() {
fieldset = $(this).parent().parent();
type = fieldset.data("type");
name = fieldset.attr("id");
newItem = "";
// Main add button, below the title
if (fieldset.is('div') && fieldset.hasClass("frontmatter")) {
fieldset = $('.blocks');
fieldset.prepend('<div class="block" id="' + defaultId + '"></div>');
title = $("#" + defaultId);
newItem = $("#" + defaultId);
type = "object";
}
@@ -299,16 +300,9 @@ $(document).on('ready pjax:success', function() {
fieldset.append('<div id="' + name + '-' + $(input).length + '" data-type="array-item"><input name="' + name + ':auto" id="' + name + '"></input><span class="actions"> <button class="delete">&#8722;</button></span></div></div>');
}
/*
/* WHAT IS THIS FOR?
if (title.is('h2')) {
type = "object"
}
if (type == "object") {
fieldset.after('<input id="new-admin-item-123" placeholder="Write the field name and press enter..."></input>');
element = $("#new-admin-item-123");
newItem.html('<input id="name-' + defaultId + '" placeholder="Write the field name and press enter..."></input>');
element = $("#name-" + defaultId);
if (!document.cookie.replace(/(?:(?:^|.*;\s*)placeholdertip\s*\=\s*([^;]*).*$)|^.*$/, "$1")) {
var date = new Date();
@@ -327,7 +321,7 @@ $(document).on('ready pjax:success', function() {
value = element.val();
if (value == "") {
element.remove();
newItem.remove();
return false;
}
@@ -350,8 +344,8 @@ $(document).on('ready pjax:success', function() {
}
if (elements.length == 1) {
title.after('<input name="' + name + ':auto" id="' + name + '"></input><br>');
title.after('<label for="' + name + '">' + value + ' <span class="actions"><button class="delete"><i class="fa fa-minus"></i></button></span></label>');
newItem.append('<input name="' + name + ':auto" id="' + name + '"></input><br>');
newItem.prepend('<label for="' + name + '">' + value + '</label> <span class="actions"><button class="delete">&#8722;</button></span>');
} else {
var fieldset = "<fieldset id=\"{{ $value.Name }}\" data-type=\"{{ $value.Type }}\">\r\n<h3>{{ $value.Title }}\r\n<span class=\"actions\">\r\n<button class=\"add\"><i class=\"fa fa-plus\"><\/i><\/button>\r\n<button class=\"delete\"><i class=\"fa fa-minus\"><\/i><\/button>\r\n<\/span>\r\n<\/h3>\r\n<\/fieldset>";
@@ -363,7 +357,7 @@ $(document).on('ready pjax:success', function() {
fieldset = fieldset.replace("{{ $value.Title }}", elements[0]);
fieldset = fieldset.replace("{{ $value.Name }}", name);
title.after(fieldset);
newItem.after(fieldset);
}
return false;
@@ -371,6 +365,15 @@ $(document).on('ready pjax:success', function() {
});
}
/*
/* WHAT IS THIS FOR?
if (title.is('h2')) {
type = "object"
}
*/
return false;