Former-commit-id: cbad4a55b9
pull/726/head
Henrique Dias 2017-01-02 16:01:35 +00:00
parent 7665b5d504
commit fa5387b141
4 changed files with 95 additions and 168 deletions

View File

@ -60,7 +60,7 @@ button:hover {
.container { .container {
width: 95%; width: 95%;
max-width: 960px; max-width: 960px;
margin: 0 auto; margin: 1em auto 0;
} }
i.spin { i.spin {
@ -68,155 +68,73 @@ i.spin {
} }
/* EDITOR */ /* * * * * * * * * * * * * * * *
* EDITOR *
* * * * * * * * * * * * * * * */
#editor .frontmatter { #editor {}
-webkit-column-count: 2;
-moz-column-count: 2;
column-count: 2;
-webkit-column-gap: 1em;
-moz-column-gap: 1em;
column-gap: 1em;
margin-bottom: 1em;
}
#editor .group, #editor .source {
#editor #editor-source {
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12);
display: block;
border-radius: .2em;
padding: .5em;
margin-bottom: 1em;
-webkit-column-break-inside: avoid;
page-break-inside: avoid;
break-inside: avoid;
background-color: #fff;
display: inline-block;
width: 100%;
break-inside: avoid-column;
}
#editor .block {
border-bottom: 1px solid #eee;
margin-bottom: .5em;
padding-bottom: .5em;
}
#editor .block:last-child {
border: 0;
margin: 0;
padding: 0;
}
#editor .block label {
display: block;
color: #212121;
font-weight: 500;
}
#editor h3 {
margin: 0 0 .5em;
display: inline-block;
vertical-align: middle;
width: calc(100% - 2.5em);
}
#editor .block input,
#editor .block .actions {
display: inline-block;
}
#editor .block input,
#editor .block textarea,
#editor fieldset input,
#editor fieldset textarea {
border: 0;
background-color: transparent;
overflow: hidden;
color: #9E9E9E;
resize: none;
width: calc(100% - 1.5em);
}
#editor .action {
border: 0;
background-color: transparent;
font-size: .8em;
margin: 0;
}
#editor .delete,
#editor .add {
color: #ddd;
}
#editor i {
padding: 0;
}
#editor .add:hover i {
color: #8BC34A;
}
#editor .delete:hover i {
color: #E53935;
}
#editor .add:hover i,
#editor .delete:hover i {
background-color: transparent;
}
#editor fieldset>.action {
opacity: 0;
}
#editor fieldset:hover>.action {
opacity: 1;
}
#editor textarea[name="content"] {
display: none; display: none;
} }
#editor fieldset fieldset { #editor .content {
margin-left: 1em; background: #fff;
padding: 1em 0;
} }
#editor button span { #editor #ace,
vertical-align: middle; #editor h2,
transition: 0.2s ease-in-out all; #editor .frontmatter {
width: 95%;
max-width: 960px;
margin: 1em auto 0;
} }
#editor button span i { #editor h2 {
vertical-align: sub; margin: 1.5em auto 1em;
font-size: 1.3rem; color: rgba(0, 0, 0, 0.3);
margin-right: .2em; font-weight: 500;
} }
#editor #publish { #editor .ace_gutter {
background-color: #167169; background-color: #fff;
} }
#editor .group.temp {
background-color: #f5f5f5; /* * * * * * * * * * * * * * * *
* EDITOR - MARKDOWN *
* * * * * * * * * * * * * * * */
.frontmatter {
-moz-column-count: 2;
-webkit-column-count: 2;
column-count: 2;
} }
#editor .group.temp label { .frontmatter label {
font-weight: lighter; display: block;
font-size: .8em;
margin-bottom: 1em;
color: #7d7d7d;
} }
#editor .group.temp input { .frontmatter label,
color: #212121; .frontmatter h3 {
font-weight: 500;
margin: .2em auto;
} }
#editor .right { fieldset {
display: inline-block; border: 0;
text-align: right; padding: 0;
float: right; }
.frontmatter>fieldset h3,
.frontmatter>.group h3 {
font-size: 1.5em;
}
fieldset h3,
.group h3 {
font-size: 0.9em;
} }
@ -762,9 +680,10 @@ header .actions {
#listing.list { #listing.list {
flex-direction: column; flex-direction: column;
margin-top: 3.25em; padding-top: 3.25em;
width: 100%; width: 100%;
max-width: 100%; max-width: 100%;
margin: 0;
} }
#listing.list .item { #listing.list .item {

View File

@ -1,6 +1,8 @@
'use strict'; 'use strict';
function textareaAutoGrow() { var editor = {};
editor.textareaAutoGrow = function() {
let autogrow = function() { let autogrow = function() {
this.style.height = '5px'; this.style.height = '5px';
this.style.height = this.scrollHeight + 'px'; this.style.height = this.scrollHeight + 'px';
@ -157,35 +159,40 @@ function addFrontMatterItem(event) {
} }
document.addEventListener("DOMContentLoaded", (event) => { document.addEventListener("DOMContentLoaded", (event) => {
textareaAutoGrow(); if (!document.getElementById('editor')) return;
editor.textareaAutoGrow();
templates.arrayItem = document.getElementById("array-item-template"); templates.arrayItem = document.getElementById("array-item-template");
templates.base = document.getElementById('base-template'); templates.base = document.getElementById('base-template');
templates.objectItem = document.getElementById("object-item-template"); templates.objectItem = document.getElementById("object-item-template");
templates.temporary = document.getElementById('temporary-template'); templates.temporary = document.getElementById('temporary-template');
buttons.save = document.querySelector('#save');
let container = document.getElementById('editor'), let container = document.getElementById('editor'),
button = document.querySelector('#save'),
kind = container.dataset.kind; kind = container.dataset.kind;
if (kind != 'frontmatter-only') { if (kind != 'frontmatter-only') {
let editor = document.getElementById('editor-source'), let editor = document.querySelector('.content #ace'),
mode = editor.dataset.mode, mode = editor.dataset.mode,
textarea = document.querySelector('textarea[name="content"]'), textarea = document.querySelector('textarea[name="content"]'),
aceEditor = ace.edit('editor-source'); aceEditor = ace.edit('ace'),
options = {
wrap: true,
maxLines: Infinity,
theme: "ace/theme/github",
showPrintMargin: false,
fontSize: "1em",
minLines: 20
};
aceEditor.getSession().setMode("ace/mode/" + mode); aceEditor.getSession().setMode("ace/mode/" + mode);
aceEditor.getSession().setValue(textarea.value); aceEditor.getSession().setValue(textarea.value);
aceEditor.getSession().on('change', function() { aceEditor.getSession().on('change', function() {
textarea.value = aceEditor.getSession().getValue(); textarea.value = aceEditor.getSession().getValue();
}); });
aceEditor.setOptions({
wrap: true, if (mode == "markdown") options.showGutter = false;
maxLines: Infinity, aceEditor.setOptions(options);
theme: "ace/theme/github",
showPrintMargin: false,
fontSize: "1em",
minLines: 20
});
} }
let deleteFrontMatterItemButtons = document.getElementsByClassName('delete'); let deleteFrontMatterItemButtons = document.getElementsByClassName('delete');
@ -209,7 +216,7 @@ document.addEventListener("DOMContentLoaded", (event) => {
data.content = data.content.toString(); data.content = data.content.toString();
} }
let html = button.querySelector('i').changeToLoading(), let html = buttons.save.querySelector('i').changeToLoading(),
request = new XMLHttpRequest(); request = new XMLHttpRequest();
request.open("PUT", toWebDavURL(window.location.pathname)); request.open("PUT", toWebDavURL(window.location.pathname));
@ -217,7 +224,7 @@ document.addEventListener("DOMContentLoaded", (event) => {
request.send(JSON.stringify(data)); request.send(JSON.stringify(data));
request.onreadystatechange = function() { request.onreadystatechange = function() {
if (request.readyState == 4) { if (request.readyState == 4) {
button.querySelector('i').changeToDone((request.status != 201), html); buttons.save.querySelector('i').changeToDone((request.status != 201), html);
} }
} }
} }

View File

@ -1,26 +1,27 @@
{{ define "content" }} {{ define "content" }}
{{ with .Data }} {{- with .Data }}
<div id="editor" class="container" data-kind="{{ .Class }}"> <form id="editor" {{ if eq .Mode "markdown" }}class="markdown"{{ end }} data-kind="{{ .Class }}">
<form method="POST" action="./"> {{- if or (eq .Class "frontmatter-only") (eq .Class "complete") }}
{{- if or (eq .Class "frontmatter-only") (eq .Class "complete") }} {{- if (eq .Class "complete")}}
<div class="frontmatter" data-type="parent"> <h2>Metadata</h2>
{{- template "blocks" .FrontMatter }} {{- end }}
<div class="button add">Add field</div> <div class="frontmatter" data-type="parent">
</div> {{- template "blocks" .FrontMatter }}
{{- end }} <div class="button add">Add field</div>
</div>
{{- end }}
{{ if or (eq .Class "content-only") (eq .Class "complete") }} {{ if or (eq .Class "content-only") (eq .Class "complete") }}
{{ if (eq .Class "complete")}} {{ if (eq .Class "complete")}}
<h3>Body</h3> <h2>Body</h2>
{{ end }}
<div class="content">
<div id="editor-source" data-mode="{{ .Mode }}"></div>
<textarea name="content">{{ .Content }}</textarea>
</div>
{{ end }} {{ end }}
</form> <div class="content">
</div> <div id="ace" data-mode="{{ .Mode }}"></div>
{{ end }} <textarea class="source" name="content">{{ .Content }}</textarea>
</div>
{{ end }}
</form>
{{- end }}
<template id="base-template"> <template id="base-template">
<fieldset id="" data-type=""> <fieldset id="" data-type="">

View File

@ -33,7 +33,7 @@
</div> </div>
{{ if and (eq .NumDirs 0) (eq .NumFiles 0) }} {{ if and (eq .NumDirs 0) (eq .NumFiles 0) }}
<h2 class="message">It feels lonely here.</h2> <h2 class="message">It feels lonely here :'(</h2>
{{ end }} {{ end }}
{{- if not (eq .NumDirs 0)}} {{- if not (eq .NumDirs 0)}}