This commit is contained in:
Henrique Dias 2015-09-16 21:48:08 +01:00
parent 65041f9d70
commit d061c26caf
14 changed files with 991 additions and 42 deletions

@ -71,6 +71,7 @@ module.exports = function(grunt) {
'node_modules/perfect-scrollbar/dist/js/perfect-scrollbar.jquery.js', 'node_modules/perfect-scrollbar/dist/js/perfect-scrollbar.jquery.js',
'node_modules/showdown/dist/showdown.js', 'node_modules/showdown/dist/showdown.js',
'node_modules/noty/js/noty/packaged/jquery.noty.packaged.js', 'node_modules/noty/js/noty/packaged/jquery.noty.packaged.js',
'node_modules/jquery-pjax/jquery.pjax.js',
'assets/js/src/**/*.js' 'assets/js/src/**/*.js'
] ]
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -1,4 +1,5 @@
$(document).ready(function() { $(document).ready(function() {
$(document).pjax('a', '#container');
$('.scroll').perfectScrollbar(); $('.scroll').perfectScrollbar();
$("#preview").click(function(e) { $("#preview").click(function(e) {
@ -7,10 +8,16 @@ $(document).ready(function() {
var preview = $("#preview-area"), var preview = $("#preview-area"),
editor = $('.editor textarea'); editor = $('.editor textarea');
if ($(this).attr("previewing") == "true") { if ($(this).data("previewing") == "true") {
preview.hide(); preview.hide();
editor.fadeIn(); editor.fadeIn();
$(this).attr("previewing", "false"); $(this).data("previewing", "false");
notification({
text: "You've gone into editing mode.",
type: 'information',
timeout: 2000
});
} else { } else {
var converter = new showdown.Converter(), var converter = new showdown.Converter(),
text = editor.val(), text = editor.val(),
@ -18,18 +25,23 @@ $(document).ready(function() {
editor.hide(); editor.hide();
preview.html(html).fadeIn(); preview.html(html).fadeIn();
$(this).attr("previewing", "true"); $(this).data("previewing", "true");
notification({
text: "You've gone into preview mode.",
type: 'information',
timeout: 2000
});
} }
return false; return false;
}); });
$('form').submit(function(event) { $('form').submit(function(event) {
var data = JSON.stringify($(this).serializeForm()) var data = JSON.stringify($(this).serializeForm()),
var url = $(this).attr('action') url = $(this).attr('action'),
var action = $(this).find("input[type=submit]:focus").val(); button = $(this).find("input[type=submit]:focus"),
action = button.val();
console.log(data);
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
@ -41,21 +53,17 @@ $(document).ready(function() {
dataType: 'json', dataType: 'json',
encode: true, encode: true,
}).done(function(data) { }).done(function(data) {
if (action == "Save") {
var word = "saved";
} else {
var word = "published";
}
notification({ notification({
text: 'The post was ' + word + '.', text: button.data("message"),
type: 'success' type: 'success',
timeout: 5000
}); });
}).fail(function(data) { }).fail(function(data) {
notification({ notification({
text: 'Something went wrong.', text: 'Something went wrong.',
type: 'error' type: 'error'
}); });
console.log(data);
}); });
event.preventDefault(); event.preventDefault();

@ -63,7 +63,7 @@ notification = function(options) {
} }
var defaults = { var defaults = {
template: '<div class="noty_message"><span class="noty_icon">' + icon + '</span><span class="noty_text"></span><div class="noty_close"></div></div>' template: '<div class="noty_message"><span class="noty_icon">' + icon + '</span><span class="noty_text"></span></div>'
} }
options = $.extend({}, defaults, options); options = $.extend({}, defaults, options);

@ -13,6 +13,9 @@
"url": "https://github.com/hacdias/caddy-hugo/issues" "url": "https://github.com/hacdias/caddy-hugo/issues"
}, },
"homepage": "https://github.com/hacdias/caddy-hugo#readme", "homepage": "https://github.com/hacdias/caddy-hugo#readme",
"scripts": {
"install": "napa defunkt/jquery-pjax"
},
"dependencies": { "dependencies": {
"animate.css": "^3.4.0", "animate.css": "^3.4.0",
"font-awesome": "^4.4.0", "font-awesome": "^4.4.0",
@ -29,6 +32,7 @@
"grunt-contrib-cssmin": "^0.14.0", "grunt-contrib-cssmin": "^0.14.0",
"grunt-contrib-sass": "^0.9.2", "grunt-contrib-sass": "^0.9.2",
"grunt-contrib-uglify": "^0.9.2", "grunt-contrib-uglify": "^0.9.2",
"grunt-contrib-watch": "^0.6.1" "grunt-contrib-watch": "^0.6.1",
"napa": "^1.2.0"
} }
} }

@ -25,7 +25,7 @@ type Page struct {
// Render the page // Render the page
func (p *Page) Render(w http.ResponseWriter, r *http.Request, templates ...string) (int, error) { func (p *Page) Render(w http.ResponseWriter, r *http.Request, templates ...string) (int, error) {
if r.URL.Query().Get("minimal") == "true" { if r.Header.Get("X-PJAX") == "true" {
templates = append(templates, "base_minimal") templates = append(templates, "base_minimal")
} else { } else {
templates = append(templates, "base_full") templates = append(templates, "base_full")

@ -48,7 +48,7 @@ func Execute(w http.ResponseWriter, r *http.Request) (int, error) {
w.Write([]byte("{}")) w.Write([]byte("{}"))
if r.Header.Get("X-Save-Mode") == "publish" { if r.Header.Get("X-Save-Mode") == "publish" {
go commands.Execute() commands.Execute()
} }
} else { } else {
content, err := ioutil.ReadFile("config." + language) content, err := ioutil.ReadFile("config." + language)

@ -25,7 +25,9 @@
</ul> </ul>
</nav> </nav>
</header> </header>
<div id="container">
{{ template "content" . }} {{ template "content" . }}
</div>
<footer> <footer>
</footer> </footer>
</body> </body>

@ -1,3 +1,5 @@
{{ define "content" }} {{ define "content" }}
<main>
<a href="/admin/settings">Settings</a>
</main>
{{ end }} {{ end }}

@ -2,7 +2,7 @@
<main class="editor"> <main class="editor">
<form method="POST" action=""> <form method="POST" action="">
<div class="sidebar data scroll"> <div class="sidebar scroll data">
<h2>Metadata</h2> <h2>Metadata</h2>
{{ template "frontmatter" .FrontMatter }} {{ template "frontmatter" .FrontMatter }}
</div> </div>
@ -14,8 +14,8 @@
<div class="action-bar"> <div class="action-bar">
<button id="preview" class="left">Preview</button> <button id="preview" class="left">Preview</button>
<input type="submit" value="Save"> <input type="submit" data-message="Post saved." value="Save">
<input type="submit" class="default" value="Publish"> <input type="submit" data-message="Post published successfully." class="default" value="Publish">
</div> </div>
</form> </form>
</main> </main>

@ -1,15 +1,15 @@
{{ define "frontmatter" }} {{ define "frontmatter" }}
{{ range $key, $value := . }} {{ range $key, $value := . }}
{{ if or (eq $value.Type "object") (eq $value.Type "array") }} {{ if or (eq $value.Type "object") (eq $value.Type "array") }}
<fieldset name="{{ $value.Name }}" type="{{ $value.Type }}"> <fieldset name="{{ $value.Name }}" type="{{ $value.Type }}">
<h3>{{ splitCapitalize $value.Name }} <button class="add"><i class="fa fa-plus"></i></button></h3> <h3>{{ splitCapitalize $value.Name }} <button class="add"><i class="fa fa-plus"></i></button></h3>
{{ template "frontmatter" $value.Content }} {{ template "frontmatter" $value.Content }}
</fieldset> </fieldset>
{{ else }} {{ else }}
{{ if not (eq $value.Parent "array") }} {{ if not (eq $value.Parent "array") }}
<label for="{{ $value.Name }}">{{ splitCapitalize $value.Name }}</label> <label for="{{ $value.Name }}">{{ splitCapitalize $value.Name }}</label>
{{ end }} {{ end }}
<input name="{{ $value.Name }}" id="{{ $value.Name }}" value="{{ $value.Content }}"></input><br> <input name="{{ $value.Name }}" id="{{ $value.Name }}" value="{{ $value.Content }}"></input><br>
{{ end }}
{{ end }} {{ end }}
{{ end }} {{ end }}
{{ end }}

@ -4,8 +4,10 @@
<div class="content"> <div class="content">
<h1>Settings</h1> <h1>Settings</h1>
<form method="POST" action="/admin/settings"> <form method="POST" action="/admin/settings">
{{ template "frontmatter" . }} <div class="data">
<input type="submit" value="Save"> {{ template "frontmatter" . }}
</div>
<input type="submit" data-message="Settings updated." value="Save">
</form> </form>
</div> </div>
{{ end }} {{ end }}