|
- {{define "editor"}}<!DOCTYPE HTML>
- <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">
- <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>
- {{if .ID}}<a class="home" href="/"><⌂/></a>{{end}}
- <a href="/browse">browse</a>
- <a href="/about.html">about</a>
- <a href="/contact.html">contact</a>
- </nav>
- {{if .ID}}<a href="/{{.ID}}.html">view</a>{{end}}
- <a id="publish" href="#">{{if .ID}}update{{else}}publish{{end}}</a>
- </header>
-
- <pre id="editor">{{.Content}}</pre>
-
- <div id="preview-wrap">
- <iframe id="preview"></iframe>
- </div>
-
- <script src="https://code.jquery.com/jquery-2.1.4.min.js" type="text/javascript" charset="utf-8"></script>
- <script src="/js/ace.js" type="text/javascript" charset="utf-8"></script>
- <script src="https://write.as/js/h.js"></script>
- <script>
- var publishing = false;
- var $publishBtn = $("#publish");
- {{if .ID}}{{else}}var orig = "{{.Content}}";
- $publishBtn.addClass("no");{{end}}
-
- var houses = JSON.parse(H.get('neighborhood', '[]'));
- var hasBuilt = houses.length > 0;
- function updatePreview() {
- var val = editor.getSession().getValue();
- $view.contents().find('body').html(val);
- {{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}}
- 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>');
- }
- {{if .ID}}var token;
- for (var i=0; i<houses.length; i++) {
- if (houses[i].id == "{{.ID}}") {
- token = houses[i].token;
- break;
- }
- }
- if (typeof token === "undefined") {
- $publishBtn.addClass("no");
- }{{else}}
- {{end}}
- $publishBtn.on('click', function(e) {
- e.preventDefault();
- if (publishing) {
- return;
- }
- 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()},
- success: function(data, status, xhr) {
- publishing = false;
- {{if .ID}}if (data.meta.code == 200) { {{else}}if (data.meta.code == 201) {
- 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);
- }
- },
- error: function(jqXHR, status, error) {
- publishing = false;
- alert(error);
- }
- });
- });
- </script>
- <script type="text/javascript">
- (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
- (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
- m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
- })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
-
- ga('create', 'UA-47877053-8', 'auto');
- ga('send', 'pageview');
- </script>
- </body>
- </html>{{end}}
|