progresses on #9
This commit is contained in:
parent
5dc65eb143
commit
8f3d50512c
File diff suppressed because one or more lines are too long
|
@ -1 +1 @@
|
|||
$(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");console.log(b),$.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(),fieldset=$(this).closest("fieldset"),fieldset.append('<input name="'+fieldset.attr("name")+'" id="'+fieldset.attr("name")+'" value=""></input><br>'),!1}))}),$(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='<i class="fa fa-check"></i>';break;case"error":b='<i class="fa fa-times"></i>';break;case"warning":b='<i class="fa fa-exclamation"></i>';break;case"information":b='<i class="fa fa-info"></i>';break;default:b='<i class="fa fa-bell"></i>'}var c={template:'<div class="noty_message"><span class="noty_icon">'+b+'</span><span class="noty_text"></span></div>'};a=$.extend({},c,a),noty(a)};
|
||||
$(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('<div id="ghost"></div>'),title=$("#ghost"),type="object"),"object"==type&&(title.after('<input id="new" placeholder="Write the field name and press enter..."></input>'),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('<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>'),!1)):void 0})),"array"==type&&(name+="[]",title.after('<input name="'+name+':auto" id="'+name+'"></input><br>')),!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='<i class="fa fa-check"></i>';break;case"error":b='<i class="fa fa-times"></i>';break;case"warning":b='<i class="fa fa-exclamation"></i>';break;case"information":b='<i class="fa fa-info"></i>';break;default:b='<i class="fa fa-bell"></i>'}var c={template:'<div class="noty_message"><span class="noty_icon">'+b+'</span><span class="noty_text"></span></div>'};a=$.extend({},c,a),noty(a)};
|
|
@ -7,8 +7,8 @@ $(document).on('ready pjax:success', function() {
|
|||
$('.scroll').perfectScrollbar();
|
||||
|
||||
// Log out the user sending bad credentials to the server
|
||||
$("#logout").click(function(e) {
|
||||
e.preventDefault();
|
||||
$("#logout").click(function(event) {
|
||||
event.preventDefault();
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "/admin",
|
||||
|
@ -21,7 +21,6 @@ $(document).on('ready pjax:success', function() {
|
|||
}).fail(function() {
|
||||
window.location = "/";
|
||||
});
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
|
@ -31,6 +30,7 @@ $(document).on('ready pjax:success', function() {
|
|||
preview = $("#preview-area");
|
||||
textarea = $("#content-area");
|
||||
|
||||
// If it has a textarea
|
||||
if (textarea[0]) {
|
||||
options = {
|
||||
mode: textarea.data("mode"),
|
||||
|
@ -45,58 +45,54 @@ $(document).on('ready pjax:success', function() {
|
|||
}
|
||||
|
||||
editor = CodeMirror.fromTextArea(textarea[0], options);
|
||||
codemirror = $('.CodeMirror');
|
||||
|
||||
// Toggles between preview and editing mode
|
||||
$("#preview").click(function(event) {
|
||||
event.preventDefault();
|
||||
|
||||
// If it currently in the preview mode, hide the preview
|
||||
// and show the editor
|
||||
if ($(this).data("previewing") == "true") {
|
||||
preview.hide();
|
||||
codemirror.fadeIn();
|
||||
$(this).data("previewing", "false");
|
||||
notification({
|
||||
text: "Think, relax and do the better you can!",
|
||||
type: 'information',
|
||||
timeout: 2000
|
||||
});
|
||||
} else {
|
||||
// Copy the editor content to texteare
|
||||
editor.save()
|
||||
|
||||
// If it's in editing mode, convert the markdown to html
|
||||
// and show it
|
||||
var converter = new showdown.Converter(),
|
||||
text = textarea.val(),
|
||||
html = converter.makeHtml(text);
|
||||
|
||||
// Hide the editor and show the preview
|
||||
codemirror.hide();
|
||||
preview.html(html).fadeIn();
|
||||
$(this).data("previewing", "true");
|
||||
notification({
|
||||
text: "This is how your post looks like.",
|
||||
type: 'information',
|
||||
timeout: 2000
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
codemirror = $('.CodeMirror');
|
||||
|
||||
// Toggles between preview and editing mode
|
||||
$("#preview").click(function(event) {
|
||||
event.preventDefault();
|
||||
|
||||
// If it currently in the preview mode, hide the preview
|
||||
// and show the editor
|
||||
if ($(this).data("previewing") == "true") {
|
||||
preview.hide();
|
||||
codemirror.fadeIn();
|
||||
$(this).data("previewing", "false");
|
||||
notification({
|
||||
text: "Think, relax and do the better you can!",
|
||||
type: 'information',
|
||||
timeout: 2000
|
||||
});
|
||||
} else {
|
||||
// Copy the editor content to texteare
|
||||
editor.save()
|
||||
|
||||
// If it's in editing mode, convert the markdown to html
|
||||
// and show it
|
||||
var converter = new showdown.Converter(),
|
||||
text = textarea.val(),
|
||||
html = converter.makeHtml(text);
|
||||
|
||||
// Hide the editor and show the preview
|
||||
codemirror.hide();
|
||||
preview.html(html).fadeIn();
|
||||
$(this).data("previewing", "true");
|
||||
notification({
|
||||
text: "This is how your post looks like.",
|
||||
type: 'information',
|
||||
timeout: 2000
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
// Submites any form in the page in JSON format
|
||||
$('form').submit(function(event) {
|
||||
event.preventDefault();
|
||||
|
||||
var data = JSON.stringify($(this).serializeJSON()),
|
||||
button = $(this).find("input[type=submit]:focus");
|
||||
|
||||
console.log(data)
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: window.location,
|
||||
|
@ -120,24 +116,79 @@ $(document).on('ready pjax:success', function() {
|
|||
});
|
||||
console.log(data);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
// Adds one more field to the current group
|
||||
// TODO: improve this function. add group/field/array/obj
|
||||
$(".add").click(function(e) {
|
||||
e.preventDefault();
|
||||
fieldset = $(this).closest("fieldset");
|
||||
fieldset.append("<input name=\"" + fieldset.attr("name") + "\" id=\"" + fieldset.attr("name") + "\" value=\"\"></input><br>");
|
||||
$(".add").click(function(event) {
|
||||
event.preventDefault();
|
||||
|
||||
if ($("#new").length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
title = $(this).parent().parent();
|
||||
fieldset = title.parent();
|
||||
type = fieldset.data("type");
|
||||
name = fieldset.data("name");
|
||||
|
||||
if (title.is('h1')) {
|
||||
fieldset = $('.sidebar .content');
|
||||
fieldset.prepend('<div id="ghost"></div>');
|
||||
title = $('#ghost');
|
||||
type = "object";
|
||||
}
|
||||
|
||||
if (type == "object") {
|
||||
title.after('<input id="new" placeholder="Write the field name and press enter..."></input>');
|
||||
element = $("#new");
|
||||
|
||||
$(element).keypress(function(event) {
|
||||
if (event.which == 13) {
|
||||
event.preventDefault();
|
||||
value = element.val();
|
||||
element.remove();
|
||||
|
||||
if (value == "") {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (name == "undefined") {
|
||||
name = value
|
||||
} else {
|
||||
name = name + '[' + value + ']';
|
||||
}
|
||||
|
||||
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>');
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (type == "array") {
|
||||
name = name + "[]";
|
||||
title.after('<input name="' + name + ':auto" id="' + name + '"></input><br>');
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
|
||||
$('body').on('keypress', 'input', function(event) {
|
||||
if (event.keyCode == 13) {
|
||||
event.preventDefault();
|
||||
$('input[value="Save"]').focus().click();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on('pjax:send', function() {
|
||||
$('#loading').fadeIn()
|
||||
})
|
||||
$('#loading').fadeIn();
|
||||
});
|
||||
|
||||
$(document).on('pjax:complete', function() {
|
||||
$('#loading').fadeOut()
|
||||
})
|
||||
$('#loading').fadeOut();
|
||||
});
|
|
@ -111,11 +111,16 @@
|
|||
}
|
||||
|
||||
.frontmatter-only input {
|
||||
color: rgba(255,255,255,.4);
|
||||
background-color: rgba(255,255,255,0.4);
|
||||
color : #aaa;
|
||||
}
|
||||
|
||||
.frontmatter-only label {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.frontmatter-only input:focus {
|
||||
color: rgba(255,255,255,.85);
|
||||
color: #555;
|
||||
}
|
||||
|
||||
.frontmatter-only .action-bar input,
|
||||
|
@ -131,6 +136,13 @@
|
|||
font-size: 1.5em;
|
||||
}
|
||||
|
||||
input::-webkit-input-placeholder,
|
||||
input:-moz-placeholder,
|
||||
input::-moz-placeholder,
|
||||
input:-ms-input-placeholder {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
/* EDITOR CONTENT ONLY STYLES */
|
||||
.content-only #content-area,
|
||||
.content-only #preview-area {
|
||||
|
|
|
@ -83,16 +83,31 @@ input[type="submit"].default:active {
|
|||
background-color: #1e88e5;
|
||||
}
|
||||
|
||||
button.add {
|
||||
button.add,
|
||||
button.delete {
|
||||
vertical-align: middle;
|
||||
border-radius : 50%;
|
||||
height : 1.5em;
|
||||
width : 1.5em;
|
||||
font-size : .7em;
|
||||
padding : 0;
|
||||
opacity : 0;
|
||||
}
|
||||
|
||||
h3:hover > button.add {
|
||||
button.add {
|
||||
background-color: #00c853;
|
||||
}
|
||||
|
||||
button.delete {
|
||||
background-color: #ff5252;
|
||||
}
|
||||
|
||||
.editor .actions {
|
||||
opacity : 0;
|
||||
transition: .2s ease-in-out opacity;
|
||||
}
|
||||
|
||||
label:hover > .actions,
|
||||
h1:hover > .actions,
|
||||
h3:hover > .actions {
|
||||
opacity: 1;
|
||||
}
|
|
@ -7,7 +7,7 @@
|
|||
{{ if not (eq .Class "full") }}
|
||||
<header>
|
||||
<div class="content">
|
||||
<h1>{{ .Name }}</h1>
|
||||
<h1>{{ .Name }} <span class="actions"><button class="add"><i class="fa fa-plus"></i></button> <button class="delete"><i class="fa fa-minus"></i></button></span></h1>
|
||||
</div>
|
||||
</header>
|
||||
{{ end }}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
{{ define "frontmatter" }}
|
||||
{{ range $key, $value := . }}
|
||||
{{ if or (eq $value.Type "object") (eq $value.Type "array") }}
|
||||
<fieldset>
|
||||
<h3>{{ splitCapitalize $value.Title }} <button class="add"><i class="fa fa-plus"></i></button></h3>
|
||||
<fieldset data-name="{{ $value.Name }}" data-type="{{ $value.Type }}">
|
||||
<h3>{{ splitCapitalize $value.Title }} <span class="actions"><button class="add"><i class="fa fa-plus"></i></button> <button class="delete"><i class="fa fa-minus"></i></button></span></h3>
|
||||
{{ template "frontmatter" $value.Content }}
|
||||
</fieldset>
|
||||
{{ else }}
|
||||
{{ if not (eq $value.Parent.Type "array") }}
|
||||
<label for="{{ $value.Name }}">{{ splitCapitalize $value.Title }}</label>
|
||||
<label for="{{ $value.Name }}">{{ splitCapitalize $value.Title }} <span class="actions"><button class="delete"><i class="fa fa-minus"></i></button></span></label>
|
||||
{{ end }}
|
||||
<input name="{{ $value.Name }}:auto" id="{{ $value.Name }}" value="{{ $value.Content }}"></input><br>
|
||||
{{ end }}
|
||||
|
|
Loading…
Reference in New Issue