1
0
mirror of https://github.com/writeas/htmlhouse synced 2025-07-18 21:08:16 +00:00
htmlhouse/templates/editor.html

164 lines
5.3 KiB
HTML
Raw Normal View History

2015-10-12 04:24:26 +00:00
{{define "editor"}}<!DOCTYPE HTML>
2015-10-10 20:44:12 +00:00
<html>
<head>
<title>HTMLhouse</title>
<link rel="stylesheet" type="text/css" href="/css/house.css" />
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="icon" type="image/png" href="/img/favicon-chrome.png" sizes="192x192">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#888888" />
<meta name="description" content="Publish HTML with HTMLhouse.">
<meta name="application-name" content="HTMLhouse">
<meta name="application-url" content="https://html.house">
<meta itemprop="name" content="HTMLhouse">
<meta itemprop="description" content="Publish HTML with HTMLhouse.">
<meta name="twitter:card" content="summary_large_image">
2016-03-09 02:34:55 +00:00
<meta name="twitter:site" content="@HTMLhouse">
2015-10-10 20:44:12 +00:00
<meta name="twitter:title" content="HTMLhouse">
<meta name="twitter:description" content="Publish HTML with HTMLhouse.">
<meta property="og:title" content="HTMLhouse" />
<meta property="og:site_name" content="HTMLhouse" />
<meta property="og:type" content="object" />
<meta property="og:url" content="https://html.house/" />
<meta property="og:description" content="Publish HTML with HTMLhouse." />
</head>
<body>
<header>
<h1>HTMLhouse</h1>
<nav>
2015-10-12 04:24:26 +00:00
{{if .ID}}<a class="home" href="/">&lt;&#8962;/&gt;</a>{{end}}
<a href="/browse">browse</a>
2015-10-11 12:27:43 +00:00
<a href="/about.html">about</a>
2016-01-02 17:44:08 +00:00
<a href="/contact.html">contact</a>
2015-10-10 20:44:12 +00:00
</nav>
2015-10-12 04:24:26 +00:00
{{if .ID}}<a href="/{{.ID}}.html">view</a>{{end}}
{{if .AllowPublish}}
<a id="publish" href="#">{{if .ID}}update{{else}}publish{{end}}</a>
<input type="checkbox" name="public" id="public"{{if .Public}} checked="checked"{{end}} /><label for="public">public</label>
{{end}}
2015-10-10 20:44:12 +00:00
</header>
2015-10-12 04:24:26 +00:00
<pre id="editor">{{.Content}}</pre>
2015-10-10 20:44:12 +00:00
<div id="preview-wrap">
<iframe id="preview"></iframe>
</div>
2018-01-05 00:14:59 +00:00
<script src="/js/jquery-2.1.4.min.js" type="text/javascript" charset="utf-8"></script>
2015-10-10 20:44:12 +00:00
<script src="/js/ace.js" type="text/javascript" charset="utf-8"></script>
<script src="/js/h.js"></script>
2015-10-10 20:44:12 +00:00
<script>
2016-09-11 13:50:42 +00:00
(function() {
var publishing = false;
var $publishBtn = $("#publish");
var $publicCheck = document.getElementById("public");
{{if .ID}}{{else}}var orig = "{{.Content}}";
$publishBtn.addClass("no");{{end}}
2016-09-11 13:50:42 +00:00
var houses = JSON.parse(H.get('neighborhood', '[]'));
var hasBuilt = houses.length > 0;
function updatePreview() {
var val = editor.getSession().getValue();
2017-06-08 00:27:41 +00:00
try {
$view.contents().find("body").html(val);
} catch (err) {
console.error(err);
}
2016-09-11 13:50:42 +00:00
{{if .ID}}{{else}}if (val != orig) {
publishing = false;
$publishBtn.removeClass("no");
$publishBtn.text("publish");
} else {
publishing = true;
$publishBtn.addClass("no");
$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}}
2016-09-11 13:50:42 +00:00
updatePreview();
2015-10-11 12:10:28 +00:00
2016-09-11 13:50:42 +00:00
{{if .ID}}{{else}}window.addEventListener('beforeunload', function(e) {
if (!justPublished) {
H.set('constructionSite', editor.getSession().getValue());
}
return null;
});{{end}}
2015-10-25 19:04:09 +00:00
2016-09-11 13:50:42 +00:00
if (hasBuilt) {
$('header').append('<a href="/houses.html">my pages</a>');
}
2016-09-11 13:50:42 +00:00
{{if .ID}}var token;
for (var i=0; i<houses.length; i++) {
if (houses[i].id == "{{.ID}}") {
token = houses[i].token;
break;
}
2015-10-12 04:24:26 +00:00
}
2016-09-11 13:50:42 +00:00
if (typeof token === "undefined") {
$publishBtn.addClass("no");
}{{else}}
{{end}}
$publishBtn.on('click', function(e) {
e.preventDefault();
if (publishing) {
return;
2015-10-11 12:10:28 +00:00
}
2016-09-11 13:50:42 +00:00
publishing = true;
$.ajax({
type: "POST",
url: "/⌂/{{if .ID}}{{.ID}}{{else}}create{{end}}",{{if .ID}}
beforeSend: function (request) {
request.setRequestHeader("Authorization", token);
},{{end}}
data: {html: editor.getSession().getValue(), public: $publicCheck.checked ? "true" : ""},
success: function(data, status, xhr) {
publishing = false;
{{if .ID}}if (data.code == 200) { {{else}}if (data.code == 201) {
2016-09-11 13:50:42 +00:00
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.error_msg);
2016-09-11 13:50:42 +00:00
}
},
error: function(jqXHR, status, error) {
publishing = false;
alert(error);
}
});
2015-10-11 12:10:28 +00:00
});
var _paq = _paq || [];
_paq.push(["setCookieDomain", "*.html.house"]);
_paq.push(["setDomains", ["*.html.house"]]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//analytics.write.as/";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', 3]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();
2016-09-11 13:50:42 +00:00
})();
2015-10-10 20:44:12 +00:00
</script>
<noscript><p><img src="//analytics.write.as/piwik.php?idsite=3" style="border:0;" alt="" /></p></noscript>
2015-10-10 20:44:12 +00:00
</body>
2015-10-12 04:24:26 +00:00
</html>{{end}}