Procházet zdrojové kódy

Automatically save new page drafts

tags/v1.0
Matt Baer před 8 roky
rodič
revize
eacfe0f815
1 změnil soubory, kde provedl 14 přidání a 0 odebrání
  1. +14
    -0
      templates/editor.html

+ 14
- 0
templates/editor.html Zobrazit soubor

@@ -69,13 +69,25 @@ function updatePreview() {
$publishBtn.text("publish" + (!hasBuilt ? " (edit first)" : ""));
}{{end}}
}
var justPublished = false;
var editor = ace.edit("editor");
var $view = $('#preview');
editor.setTheme("ace/theme/chrome");
editor.session.setMode("ace/mode/html");
editor.getSession().on('change', updatePreview);
{{if .ID}}{{else}}var saved = H.get('constructionSite', '');
if (saved !== '') {
editor.setValue(saved);
}{{end}}
updatePreview();

{{if .ID}}{{else}}window.addEventListener('beforeunload', function(e) {
if (!justPublished) {
H.set('constructionSite', editor.getSession().getValue());
}
return null;
});{{end}}

if (hasBuilt) {
$('header').append('<a href="/houses.html">my pages</a>');
}
@@ -109,6 +121,8 @@ $publishBtn.on('click', function(e) {
var houses = JSON.parse(H.get('neighborhood', '[]'));
houses.push({id: data.data.id, token: xhr.getResponseHeader('Authorization')});
H.set('neighborhood', JSON.stringify(houses));{{end}}
justPublished = true;
{{if .ID}}{{else}}H.remove('constructionSite');{{end}}
window.location = '/' + data.data.id + '.html';
} else {
alert(data.meta.error_msg);


Načítá se…
Zrušit
Uložit