fix some stuff
parent
64ec1da64b
commit
58f5e4b1d9
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -317,7 +317,7 @@ fieldset input {
|
||||||
margin: 0.5em 0;
|
margin: 0.5em 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.editor.complete .block[data-content="title"] {
|
.complete .block[data-content="title"] {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,66 @@
|
||||||
$(document).on('page:editor', function() {
|
$(document).on('page:editor', function() {
|
||||||
// Setup ace editor
|
var container = $('.editor');
|
||||||
var mode = $("#editor-source").data('mode');
|
var preview = $('#editor-preview');
|
||||||
var textarea = $('textarea[name="content"]').hide();
|
var editor = $('#editor-source');
|
||||||
var aceEditor = ace.edit('editor-source');
|
|
||||||
aceEditor.getSession().setMode("ace/mode/" + mode);
|
if (container.hasClass('complete')) {
|
||||||
aceEditor.getSession().setValue(textarea.val());
|
// Change title field when editing the header
|
||||||
aceEditor.getSession().on('change', function(){
|
$('#site-title').keyup(function() {
|
||||||
textarea.val(aceEditor.getSession().getValue());
|
$('.frontmatter #title').val($(this).val());
|
||||||
});
|
});
|
||||||
aceEditor.setOptions({
|
}
|
||||||
wrap: true,
|
|
||||||
maxLines: Infinity,
|
if (!container.hasClass('frontmatter-only')) {
|
||||||
theme: "ace/theme/github",
|
// Setup ace editor
|
||||||
showPrintMargin: false,
|
var mode = $("#editor-source").data('mode');
|
||||||
fontSize: "1em"
|
var textarea = $('textarea[name="content"]').hide();
|
||||||
});
|
var aceEditor = ace.edit('editor-source');
|
||||||
|
aceEditor.getSession().setMode("ace/mode/" + mode);
|
||||||
|
aceEditor.getSession().setValue(textarea.val());
|
||||||
|
aceEditor.getSession().on('change', function() {
|
||||||
|
textarea.val(aceEditor.getSession().getValue());
|
||||||
|
});
|
||||||
|
aceEditor.setOptions({
|
||||||
|
wrap: true,
|
||||||
|
maxLines: Infinity,
|
||||||
|
theme: "ace/theme/github",
|
||||||
|
showPrintMargin: false,
|
||||||
|
fontSize: "1em"
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#see-source").off('click').click(function(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
preview.hide();
|
||||||
|
editor.fadeIn();
|
||||||
|
$("#see-preview").data("previewing", "false");
|
||||||
|
})
|
||||||
|
|
||||||
|
// Toggles between preview and editing mode
|
||||||
|
$("#see-preview").off('click').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();
|
||||||
|
editor.fadeIn();
|
||||||
|
$(this).data("previewing", "false");
|
||||||
|
} else {
|
||||||
|
// If it's in editing mode, convert the markdown to html
|
||||||
|
// and show it
|
||||||
|
var converter = new showdown.Converter(),
|
||||||
|
text = aceEditor.getValue(),
|
||||||
|
html = converter.makeHtml(text);
|
||||||
|
|
||||||
|
// Hide the editor and show the preview
|
||||||
|
editor.hide();
|
||||||
|
preview.html(html).fadeIn();
|
||||||
|
$(this).data("previewing", "true");
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
$('body').off('keypress', 'input').on('keypress', 'input', function(event) {
|
$('body').off('keypress', 'input').on('keypress', 'input', function(event) {
|
||||||
if (event.keyCode == 13) {
|
if (event.keyCode == 13) {
|
||||||
|
@ -24,57 +70,17 @@ $(document).on('page:editor', function() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Change title field when editing the header
|
|
||||||
$('#site-title').keyup(function() {
|
|
||||||
$('.frontmatter #title').val($(this).val());
|
|
||||||
});
|
|
||||||
|
|
||||||
var preview = $('#editor-preview');
|
|
||||||
var editor = $('#editor-source');
|
|
||||||
|
|
||||||
$("#see-source").off('click').click(function(event) {
|
|
||||||
event.preventDefault();
|
|
||||||
preview.hide();
|
|
||||||
editor.fadeIn();
|
|
||||||
$("#see-preview").data("previewing", "false");
|
|
||||||
})
|
|
||||||
|
|
||||||
// Toggles between preview and editing mode
|
|
||||||
$("#see-preview").off('click').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();
|
|
||||||
editor.fadeIn();
|
|
||||||
$(this).data("previewing", "false");
|
|
||||||
} else {
|
|
||||||
// If it's in editing mode, convert the markdown to html
|
|
||||||
// and show it
|
|
||||||
var converter = new showdown.Converter(),
|
|
||||||
text = aceEditor.getValue(),
|
|
||||||
html = converter.makeHtml(text);
|
|
||||||
|
|
||||||
// Hide the editor and show the preview
|
|
||||||
editor.hide();
|
|
||||||
preview.html(html).fadeIn();
|
|
||||||
$(this).data("previewing", "true");
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
//TODO: reform this
|
|
||||||
// Submites any form in the page in JSON format
|
// Submites any form in the page in JSON format
|
||||||
$('form').submit(function(event) {
|
$('form').submit(function(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
// Reset preview area and button to make sure it will
|
if (!container.hasClass('frontmatter-only')) {
|
||||||
// not serialize any form inside the preview
|
// Reset preview area and button to make sure it will
|
||||||
preview.html('').fadeOut();
|
// not serialize any form inside the preview
|
||||||
$("#see-preview").data("previewing", "false");
|
preview.html('').fadeOut();
|
||||||
editor.fadeIn();
|
$("#see-preview").data("previewing", "false");
|
||||||
|
editor.fadeIn();
|
||||||
|
}
|
||||||
|
|
||||||
var data = JSON.stringify($(this).serializeJSON()),
|
var data = JSON.stringify($(this).serializeJSON()),
|
||||||
button = $(this).find("input[type=submit]:focus");
|
button = $(this).find("input[type=submit]:focus");
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
{{ define "content" }}
|
{{ define "content" }}
|
||||||
|
<div class="editor container {{ .Class }}">
|
||||||
<div class="editor {{ .Class }} container">
|
|
||||||
{{ if eq .Class "complete" }}
|
{{ if eq .Class "complete" }}
|
||||||
<h1><textarea id="site-title">{{ .Name }}</textarea></h1>
|
<h1><textarea id="site-title">{{ .Name }}</textarea></h1>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
@ -19,7 +18,8 @@
|
||||||
</div>
|
</div>
|
||||||
{{ else if eq .Class "content-only" }}
|
{{ else if eq .Class "content-only" }}
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<textarea id="editor-source" name="content" data-mode="{{ .Mode }}">{{ .Content }}</textarea>
|
<div id="editor-source" data-mode="{{ .Mode }}"></div>
|
||||||
|
<textarea name="content">{{ .Content }}</textarea>
|
||||||
</div>
|
</div>
|
||||||
{{ else }}
|
{{ else }}
|
||||||
<div class="frontmatter">
|
<div class="frontmatter">
|
||||||
|
|
Loading…
Reference in New Issue