2016-04-03 11:01:21 -04:00
|
|
|
"use strict";
|
|
|
|
|
2016-04-09 14:24:16 -04:00
|
|
|
//! {"require": ["ui"]}
|
|
|
|
|
2016-04-03 11:01:21 -04:00
|
|
|
terminal.setEcho(false);
|
2016-04-04 16:26:01 -04:00
|
|
|
terminal.setTitle("Live Markdeep Editor");
|
2016-04-03 11:01:21 -04:00
|
|
|
|
2016-04-09 14:24:16 -04:00
|
|
|
let gEditEvent = null;
|
2016-04-03 11:01:21 -04:00
|
|
|
|
2016-04-09 14:24:16 -04:00
|
|
|
function back() {
|
2016-04-04 16:26:01 -04:00
|
|
|
terminal.split([{name: "terminal"}]);
|
2016-04-09 14:24:16 -04:00
|
|
|
if (gEditEvent) {
|
|
|
|
gEditEvent.back();
|
2016-04-03 11:01:21 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
core.register("onWindowMessage", function(event) {
|
|
|
|
if (event.message.ready) {
|
2016-04-09 14:24:16 -04:00
|
|
|
terminal.postMessageToIframe("iframe", {title: gEditEvent.name, contents: gEditEvent.value});
|
2016-04-03 11:01:21 -04:00
|
|
|
} else if (event.message.index) {
|
2016-04-09 14:24:16 -04:00
|
|
|
back();
|
2016-04-03 11:01:21 -04:00
|
|
|
} else {
|
2016-04-09 14:24:16 -04:00
|
|
|
gEditEvent.save(event.message.title, event.message.contents).then(back);
|
2016-04-03 11:01:21 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-04-09 14:24:16 -04:00
|
|
|
function editPage(event) {
|
|
|
|
gEditEvent = event;
|
2016-04-04 16:26:01 -04:00
|
|
|
terminal.split([{name: "terminal", type: "vertical"}]);
|
2016-04-03 11:01:21 -04:00
|
|
|
terminal.clear();
|
|
|
|
terminal.print({iframe: `<html>
|
|
|
|
<head>
|
|
|
|
<script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.13.2/codemirror.min.js"></script>
|
|
|
|
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.13.2/codemirror.min.css"></link>
|
|
|
|
<style>
|
2016-04-04 16:26:01 -04:00
|
|
|
html {
|
|
|
|
height: 100%;
|
2016-04-03 11:01:21 -04:00
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
2016-04-04 16:26:01 -04:00
|
|
|
}
|
|
|
|
body {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
2016-04-03 11:01:21 -04:00
|
|
|
height: 100%;
|
2016-04-04 16:26:01 -04:00
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
|
|
|
}
|
|
|
|
#menu {
|
|
|
|
flex: 0 0 auto;
|
2016-04-03 11:01:21 -04:00
|
|
|
}
|
|
|
|
#container {
|
2016-04-04 16:26:01 -04:00
|
|
|
flex: 1 1 auto;
|
2016-04-03 11:01:21 -04:00
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
2016-04-04 16:26:01 -04:00
|
|
|
width: 100%;
|
|
|
|
background-color: white;
|
2016-04-03 11:01:21 -04:00
|
|
|
}
|
2016-04-04 16:26:01 -04:00
|
|
|
.CodeMirror {
|
|
|
|
width: 100%;
|
2016-04-03 11:01:21 -04:00
|
|
|
height: 100%;
|
|
|
|
}
|
2016-04-04 16:26:01 -04:00
|
|
|
.CodeMirror-scroll {
|
|
|
|
}
|
|
|
|
#edit { background-color: white }
|
|
|
|
#preview { background-color: white }
|
|
|
|
#edit, #preview {
|
|
|
|
display: flex;
|
2016-04-03 11:01:21 -04:00
|
|
|
overflow: auto;
|
2016-04-04 16:26:01 -04:00
|
|
|
flex: 0 0 50%;
|
2016-04-03 11:01:21 -04:00
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<script>
|
|
|
|
var gEditor;
|
|
|
|
function index() {
|
|
|
|
parent.postMessage({index: true}, "*");
|
|
|
|
}
|
|
|
|
function submit() {
|
|
|
|
parent.postMessage({
|
|
|
|
title: document.getElementById("title").value,
|
|
|
|
contents: gEditor.getValue(),
|
|
|
|
}, "*");
|
|
|
|
}
|
|
|
|
function textChanged() {
|
|
|
|
var preview = document.getElementById("preview");
|
2016-04-17 10:33:40 -04:00
|
|
|
preview.innerHTML = markdeep.format(gEditor.getValue() + "\\n", false);
|
2016-04-03 11:01:21 -04:00
|
|
|
}
|
|
|
|
window.markdeepOptions = {mode: 'script'};
|
|
|
|
</script>
|
|
|
|
<script src="https://casual-effects.com/markdeep/latest/markdeep.min.js"></script>
|
|
|
|
<script>
|
|
|
|
document.head.innerHTML += markdeep.stylesheet();
|
|
|
|
|
|
|
|
window.addEventListener("message", function(message) {
|
|
|
|
document.getElementById("title").value = message.data.title;
|
|
|
|
gEditor.setValue(message.data.contents);
|
|
|
|
textChanged();
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
window.addEventListener("load", function() {
|
|
|
|
gEditor = CodeMirror.fromTextArea(document.getElementById("contents"), {
|
|
|
|
lineNumbers: true
|
|
|
|
});
|
|
|
|
gEditor.on("change", textChanged);
|
|
|
|
});
|
|
|
|
|
|
|
|
parent.postMessage({ready: true}, "*");
|
|
|
|
</script>
|
|
|
|
</head>
|
|
|
|
<body>
|
2016-04-04 16:26:01 -04:00
|
|
|
<div id="menu">
|
|
|
|
<input type="button" value="Back" onclick="index()">
|
|
|
|
` + (core.user.credentials.permissions.authenticated ? `
|
|
|
|
<input type="button" value="Save" onclick="submit()">
|
|
|
|
` : "") +
|
|
|
|
` <a target="_top" href="https://casual-effects.com/markdeep/">Markdeep</a>
|
|
|
|
<input type="text" id="title" oninput="textChanged()">
|
|
|
|
</div>
|
2016-04-03 11:01:21 -04:00
|
|
|
<div id="container">
|
2016-04-04 16:26:01 -04:00
|
|
|
<div id="edit"><textarea id="contents" oninput="textChanged()"></textarea></div>
|
|
|
|
<div id="preview"></div>
|
2016-04-03 11:01:21 -04:00
|
|
|
</div>
|
|
|
|
</body>
|
2016-04-04 16:26:01 -04:00
|
|
|
</html>`, name: "iframe", style: "flex: 1 1 auto; border: 0; width: 100%"});
|
2016-04-03 11:01:21 -04:00
|
|
|
}
|
|
|
|
|
2016-04-09 14:36:43 -04:00
|
|
|
require("ui").fileList({
|
2016-04-09 14:24:16 -04:00
|
|
|
title: "Live Markdeep Editor",
|
|
|
|
edit: editPage,
|
|
|
|
});
|