"use strict"; terminal.setEcho(false); terminal.setTitle("Live TurtleScript"); core.register("onInput", function(input) { if (input == "new page") { editPage("new", ""); } else if (input == "submit") { submitNewPost().then(renderBlog); } else if (input == "home") { renderIndex(); } else if (input.substring(0, 5) == "open:") { var title = input.substring(5); database.get(title).then(function(contents) { editPage(title, contents); }); } else if (input.substring(0, 7) == "delete:") { terminal.clear(); var title = input.substring(7); terminal.print("Are you sure you want to delete page '", title, "'?"); terminal.print({command: "confirmDelete:" + title, value: "delete it"}); terminal.print({command: "home", value: "cancel"}); } else if (input.substring(0, 14) == "confirmDelete:") { var title = input.substring(14); database.remove(title).then(renderIndex); } }); function renderIndex() { terminal.split([{name: "terminal"}]); terminal.clear(); terminal.print("Live TurtleScript"); if (core.user.credentials.permissions.authenticated) { terminal.print({command: "new page"}); } database.getAll().then(function(entries) { for (var i = 0; i < entries.length; i++) { if (core.user.credentials.permissions.authenticated) { terminal.print( "* ", {style: "font-weight: bold", value: {command: "open:" + entries[i], value: entries[i]}}, " (", {command: "delete:" + entries[i], value: "x"}, ")"); } else { terminal.print( "* ", {style: "font-weight: bold", value: {command: "open:" + entries[i], value: entries[i]}}); } } }); } var gPage = null; core.register("hashChange", function(event) { var title = event.hash.substring(1); database.get(title).then(function(contents) { editPage(title, contents); }); }); core.register("onWindowMessage", function(event) { if (event.message.ready) { terminal.postMessageToIframe("iframe", {title: gPage.title, contents: gPage.contents}); } else if (event.message.index) { renderIndex(); } else { database.set(event.message.title, event.message.contents).then(function() { renderIndex(); }); } }); function editPage(title, contents) { gPage = {title: title, contents: contents}; terminal.split([{name: "terminal", type: "vertical"}]); terminal.clear(); terminal.print({iframe: `
'); iframe.setAttribute('style', 'width: 100vw; height: 100vh; border: 0'); preview.appendChild(iframe); } -->