|
|
@@ -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); |
|
|
|