WIP: toolbars (try2)

This commit is contained in:
2019-09-03 22:59:49 +03:00
parent 1787ae5f4e
commit 0548087b39

View File

@@ -1,54 +1,120 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
<meta name="HandheldFriendly" content="True" />
<title>Editor</title>
<style type="text/css" media="screen">
body {
overflow: hidden;
}
#editor { <head>
margin: 0; <meta charset="UTF-8">
position: absolute; <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
top: 0; <meta name="HandheldFriendly" content="True" />
bottom: 0; <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
left: 0; <title>Editor</title>
right: 0; <style type="text/css" media="screen">
} .ace_editor,
</style> .toolbar {
border: 1px solid lightgray;
margin: auto;
width: 80%;
}
.ace_editor {
height: 200px;
}
</style>
</head> </head>
<body> <body>
<pre id="editor"></pre> <script src="require.js"></script>
<script>
// setup paths
require.config({
paths: {
"ace": "src-min-noconflict"
}
});
// load ace and extensions
require(["ace/ace", "ace/ext-language_tools"], function(ace) {
var buildDom = ace.require("ace/lib/dom").buildDom;
var editor = ace.edit();
editor.setOptions({
mode: "ace/mode/text",
theme: "ace/theme/twilight",
showPrintMargin: false,
wrap: true,
indentedSoftWrap: true,
showFoldWidgets: false,
showLineNumbers: true,
showGutter: false,
autoScrollEditorIntoView: true
});
var refs = {};
<script src="src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script> function updateToolbar() {
<script> refs.undoButton.disabled = !editor.session.getUndoManager().hasUndo();
var editor = ace.edit("editor"); refs.redoButton.disabled = !editor.session.getUndoManager().hasRedo();
editor.setOptions({ }
mode: "ace/mode/markdown", editor.on("input", updateToolbar);
theme: "ace/theme/twilight",
showPrintMargin: false, if (localStorage.getItem("acetest") !== null) {
wrap: true, editor.setValue(localStorage.getItem("acetest"));
indentedSoftWrap: true, editor.clearSelection();
showFoldWidgets: false, }
showLineNumbers: true,
showGutter: false, editor.getSession().on('change', function () {
autoScrollEditorIntoView: true localStorage.setItem("acetest", editor.getSession().getValue());
}) });
if (localStorage.getItem("acetest") !== null) { function save() {
editor.setValue(localStorage.getItem("acetest")); alert("not yet implemented");
editor.clearSelection(); }
} editor.commands.addCommand({
name: "save",
editor.getSession().on('change', function () { exec: save,
localStorage.setItem("acetest", editor.getSession().getValue()); bindKey: {
}); win: "ctrl-s",
</script> mac: "cmd-s"
}
});
buildDom(["div", {
class: "toolbar"
},
["button", {
ref: "saveButton",
onclick: save
}, "save"],
["button", {
ref: "undoButton",
onclick: function() {
editor.undo();
}
}, "undo"],
["button", {
ref: "redoButton",
onclick: function() {
editor.redo();
}
}, "redo"],
["button", {
style: "font-weight: bold",
onclick: function() {
editor.insertSnippet("**${1:$SELECTION}**");
editor.renderer.scrollCursorIntoView()
}
}, "bold"],
["button", {
style: "font-style: italic",
onclick: function() {
editor.insertSnippet("*${1:$SELECTION}*");
editor.renderer.scrollCursorIntoView()
}
}, "Italic"],
], document.body, refs);
document.body.appendChild(editor.container)
window.editor = editor;
});
</script>
</body> </body>
</html> </html>