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

View File

@ -71,6 +71,7 @@ module.exports = function(grunt) {
'node_modules/perfect-scrollbar/dist/js/perfect-scrollbar.jquery.js',
'node_modules/showdown/dist/showdown.js',
'node_modules/noty/js/noty/packaged/jquery.noty.packaged.js',
'node_modules/jquery-pjax/jquery.pjax.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

View File

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

View File

@ -63,7 +63,7 @@ notification = function(options) {
}
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);

View File

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

View File

@ -25,7 +25,7 @@ type Page struct {
// Render the page
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")
} else {
templates = append(templates, "base_full")

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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