add textarea auto grow and some more stuff

This commit is contained in:
Henrique Dias 2016-06-27 12:19:40 +01:00
parent 44cd9bf930
commit c5d9803bae
5 changed files with 87 additions and 12 deletions

View File

@ -106,6 +106,7 @@ button, html [type="button"], [type="reset"], [type="submit"] {
background-color: #26a69a; background-color: #26a69a;
text-align: center; text-align: center;
letter-spacing: .5px; letter-spacing: .5px;
-webkit-transition: .2s ease-out;
transition: .2s ease-out; transition: .2s ease-out;
cursor: pointer; cursor: pointer;
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12); box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12);
@ -131,6 +132,8 @@ fieldset {
border: none; border: none;
margin: 0; margin: 0;
padding: 0; padding: 0;
-webkit-column-break-inside: avoid;
page-break-inside: avoid;
break-inside: avoid; break-inside: avoid;
} }
legend { legend {
@ -217,6 +220,7 @@ table {
} }
tr { tr {
cursor: pointer; cursor: pointer;
-webkit-transition: 0.1s ease all;
transition: 0.1s ease all; transition: 0.1s ease all;
border-bottom: 1px dashed #dadada; border-bottom: 1px dashed #dadada;
} }
@ -320,6 +324,7 @@ pre {
/* Support for Firefox. */ /* Support for Firefox. */
-moz-osx-font-smoothing: grayscale; -moz-osx-font-smoothing: grayscale;
/* Support for IE. */ /* Support for IE. */
-webkit-font-feature-settings: 'liga';
font-feature-settings: 'liga'; font-feature-settings: 'liga';
} }
@ -397,6 +402,8 @@ header form input {
position: fixed; position: fixed;
top: 0; top: 0;
left: 0; left: 0;
display: -webkit-box;
display: -ms-flexbox;
display: flex; display: flex;
width: 100%; width: 100%;
padding: 0.5em; padding: 0.5em;
@ -404,6 +411,8 @@ header form input {
} }
#toolbar div, header div { #toolbar div, header div {
vertical-align: middle; vertical-align: middle;
-webkit-box-flex: 1;
-ms-flex-positive: 1;
flex-grow: 1; flex-grow: 1;
} }
#toolbar p, header p { #toolbar p, header p {
@ -417,6 +426,7 @@ header form input {
#toolbar { #toolbar {
z-index: 1000; z-index: 1000;
top: -4em; top: -4em;
-webkit-transition: 0.2s ease-in-out all;
transition: 0.2s ease-in-out all; transition: 0.2s ease-in-out all;
opacity: 0; opacity: 0;
color: #fff; color: #fff;
@ -433,6 +443,7 @@ header form input {
display: inline-block; display: inline-block;
margin: 0 0.2em; margin: 0 0.2em;
cursor: pointer; cursor: pointer;
-webkit-transition: 0.2s ease all;
transition: 0.2s ease all; transition: 0.2s ease all;
border: 0; border: 0;
border-radius: 50%; border-radius: 50%;
@ -443,6 +454,7 @@ header form input {
} }
.action i { .action i {
padding: 0.5em; padding: 0.5em;
-webkit-transition: 0.2s ease-in-out all;
transition: 0.2s ease-in-out all; transition: 0.2s ease-in-out all;
border-radius: 50%; border-radius: 50%;
} }
@ -463,23 +475,34 @@ header form input {
/* LISTING */ /* LISTING */
#listing { #listing {
display: -webkit-box;
display: -ms-flexbox;
display: flex; display: flex;
padding: 0 0.5em; padding: 0 0.5em;
-ms-flex-wrap: wrap;
flex-wrap: wrap; flex-wrap: wrap;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between; justify-content: space-between;
} }
#listing.list { #listing.list {
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column; flex-direction: column;
} }
#listing .item { #listing .item {
margin: 0 0.5em 1em; margin: 0 0.5em 1em;
padding: 0.5em; padding: 0.5em;
cursor: pointer; cursor: pointer;
-webkit-transition: 0.2s ease all;
transition: 0.2s ease all; transition: 0.2s ease all;
border: 0.2em solid #fff; border: 0.2em solid #fff;
border-radius: 0.2em; border-radius: 0.2em;
background-color: #fff; background-color: #fff;
box-shadow: 0 1px 3px rgba(0, 0, 0, .06), 0 1px 2px rgba(0, 0, 0, .12); box-shadow: 0 1px 3px rgba(0, 0, 0, .06), 0 1px 2px rgba(0, 0, 0, .12);
-webkit-box-flex: 1;
-ms-flex-positive: 1;
flex-grow: 1; flex-grow: 1;
} }
.item:hover { .item:hover {
@ -511,8 +534,15 @@ header form input {
/* ANIMATIONS */ /* ANIMATIONS */
i.spin { i.spin {
-webkit-animation: 1s spin linear infinite;
animation: 1s spin linear infinite; animation: 1s spin linear infinite;
} }
@-webkit-keyframes spin {
100% {
-webkit-transform: rotate(-360deg);
transform: rotate(-360deg);
}
}
@keyframes spin { @keyframes spin {
100% { 100% {
-webkit-transform: rotate(-360deg); -webkit-transform: rotate(-360deg);
@ -523,18 +553,27 @@ i.spin {
/* EDITOR */ /* EDITOR */
#editor .frontmatter { #editor .frontmatter {
-webkit-column-count: 2;
-moz-column-count: 2;
column-count: 2; column-count: 2;
-webkit-column-gap: 1em;
-moz-column-gap: 1em;
column-gap: 1em; column-gap: 1em;
margin-bottom: 1em; margin-bottom: 1em;
} }
#editor .group { #editor .group, #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); box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12);
display: block; display: block;
border-radius: .2em; border-radius: .2em;
padding: .5em; padding: .5em;
margin-bottom: 1em; margin-bottom: 1em;
-webkit-column-break-inside: avoid;
page-break-inside: avoid;
break-inside: avoid; break-inside: avoid;
background-color: #fff; background-color: #fff;
display: inline-block;
width: 100%;
break-inside: avoid-column;
} }
#editor .block { #editor .block {
border-bottom: 1px solid #eee; border-bottom: 1px solid #eee;
@ -560,7 +599,7 @@ i.spin {
#editor .block input, #editor .block .actions { #editor .block input, #editor .block .actions {
display: inline-block; display: inline-block;
} }
#editor .block input, #editor .block textarea { #editor .block input, #editor .block textarea, #editor fieldset input, #editor fieldset textarea {
border: 0; border: 0;
background-color: transparent; background-color: transparent;
overflow: hidden; overflow: hidden;
@ -574,13 +613,27 @@ i.spin {
font-size: .8em; font-size: .8em;
margin: 0; margin: 0;
} }
#editor .delete { #editor .delete, #editor .add {
color: #E53935; color: #ddd;
} }
#editor i { #editor i {
padding: 0; padding: 0;
} }
#editor .delete i:hover { #editor .add:hover i {
color: #B71C1C; color: #8BC34A;
}
#editor .delete:hover i {
color: #E53935;
}
#editor .add:hover i, #editor .delete:hover i {
background-color: transparent; background-color: transparent;
} }
#editor fieldset> .action {
opacity: 0;
}
#editor fieldset:hover> .action {
opacity: 1;
}
#editor textarea[name="content"] {
display: none;
}

View File

@ -429,9 +429,30 @@ document.addEventListener("DOMContentLoaded", function (event) {
handleEditorPage(); handleEditorPage();
} }
textareaAutoGrow();
return false; return false;
}); });
var textareaAutoGrow = function() {
let autogrow = function() {
this.style.height = '5px';
this.style.height = this.scrollHeight + 'px';
}
let textareas = document.getElementsByTagName('textarea');
let addAutoGrow = () => {
Array.from(textareas).forEach(textarea => {
autogrow.bind(textarea)();
textarea.addEventListener('keyup', autogrow);
});
}
addAutoGrow();
window.addEventListener('resize', addAutoGrow)
}
var handleEditorPage = function () { var handleEditorPage = function () {
let container = document.getElementById('editor'); let container = document.getElementById('editor');
let kind = container.dataset.kind; let kind = container.dataset.kind;

View File

@ -9,6 +9,8 @@
{{ end }} {{ end }}
{{ if or (eq .Class "content-only") (eq .Class "complete") }} {{ if or (eq .Class "content-only") (eq .Class "complete") }}
{{ if (eq .Class "complete")}}<h3>Body</h3>{{ end }}
<div class="content"> <div class="content">
<div id="editor-source" data-mode="{{ .Mode }}"></div> <div id="editor-source" data-mode="{{ .Mode }}"></div>
<textarea name="content">{{ .Content }}</textarea> <textarea name="content">{{ .Content }}</textarea>

View File

@ -5,7 +5,6 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/hacdias/caddy-filemanager/internal/frontmatter"
"github.com/spf13/hugo/parser" "github.com/spf13/hugo/parser"
) )
@ -14,7 +13,7 @@ type Editor struct {
Class string Class string
Mode string Mode string
Content string Content string
FrontMatter *frontmatter.Content FrontMatter *Content
} }
// GetEditor gets the editor based on a FileInfo struct // GetEditor gets the editor based on a FileInfo struct
@ -52,7 +51,7 @@ func (i *Info) GetEditor() (*Editor, error) {
// Parses the page content and the frontmatter // Parses the page content and the frontmatter
editor.Content = strings.TrimSpace(string(page.Content())) editor.Content = strings.TrimSpace(string(page.Content()))
editor.FrontMatter, _, err = frontmatter.Pretty(page.FrontMatter()) editor.FrontMatter, _, err = Pretty(page.FrontMatter())
editor.Class = "complete" editor.Class = "complete"
} else { } else {
// The editor will handle only content // The editor will handle only content
@ -65,9 +64,9 @@ func (i *Info) GetEditor() (*Editor, error) {
// Checks if the file already has the frontmatter rune and parses it // Checks if the file already has the frontmatter rune and parses it
if editor.hasFrontMatterRune(i.Raw) { if editor.hasFrontMatterRune(i.Raw) {
editor.FrontMatter, _, err = frontmatter.Pretty(i.Raw) editor.FrontMatter, _, err = Pretty(i.Raw)
} else { } else {
editor.FrontMatter, _, err = frontmatter.Pretty(editor.appendFrontMatterRune(i.Raw, editor.Mode)) editor.FrontMatter, _, err = Pretty(editor.appendFrontMatterRune(i.Raw, editor.Mode))
} }
// Check if there were any errors // Check if there were any errors

View File

@ -1,4 +1,4 @@
package frontmatter package file
import ( import (
"bytes" "bytes"