WIP: toolbars (try2)
This commit is contained in:
102
ace/index.html
102
ace/index.html
@@ -1,35 +1,42 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<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="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
|
||||||
<meta name="HandheldFriendly" content="True" />
|
<meta name="HandheldFriendly" content="True" />
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||||
<title>Editor</title>
|
<title>Editor</title>
|
||||||
<style type="text/css" media="screen">
|
<style type="text/css" media="screen">
|
||||||
body {
|
.ace_editor,
|
||||||
overflow: hidden;
|
.toolbar {
|
||||||
|
border: 1px solid lightgray;
|
||||||
|
margin: auto;
|
||||||
|
width: 80%;
|
||||||
}
|
}
|
||||||
|
|
||||||
#editor {
|
.ace_editor {
|
||||||
margin: 0;
|
height: 200px;
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
bottom: 0;
|
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<pre id="editor"></pre>
|
<script src="require.js"></script>
|
||||||
|
<script>
|
||||||
<script src="src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
|
// setup paths
|
||||||
<script>
|
require.config({
|
||||||
var editor = ace.edit("editor");
|
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({
|
editor.setOptions({
|
||||||
mode: "ace/mode/markdown",
|
mode: "ace/mode/text",
|
||||||
theme: "ace/theme/twilight",
|
theme: "ace/theme/twilight",
|
||||||
showPrintMargin: false,
|
showPrintMargin: false,
|
||||||
wrap: true,
|
wrap: true,
|
||||||
@@ -38,7 +45,14 @@
|
|||||||
showLineNumbers: true,
|
showLineNumbers: true,
|
||||||
showGutter: false,
|
showGutter: false,
|
||||||
autoScrollEditorIntoView: true
|
autoScrollEditorIntoView: true
|
||||||
})
|
});
|
||||||
|
var refs = {};
|
||||||
|
|
||||||
|
function updateToolbar() {
|
||||||
|
refs.undoButton.disabled = !editor.session.getUndoManager().hasUndo();
|
||||||
|
refs.redoButton.disabled = !editor.session.getUndoManager().hasRedo();
|
||||||
|
}
|
||||||
|
editor.on("input", updateToolbar);
|
||||||
|
|
||||||
if (localStorage.getItem("acetest") !== null) {
|
if (localStorage.getItem("acetest") !== null) {
|
||||||
editor.setValue(localStorage.getItem("acetest"));
|
editor.setValue(localStorage.getItem("acetest"));
|
||||||
@@ -48,7 +62,59 @@
|
|||||||
editor.getSession().on('change', function () {
|
editor.getSession().on('change', function () {
|
||||||
localStorage.setItem("acetest", editor.getSession().getValue());
|
localStorage.setItem("acetest", editor.getSession().getValue());
|
||||||
});
|
});
|
||||||
</script>
|
|
||||||
|
function save() {
|
||||||
|
alert("not yet implemented");
|
||||||
|
}
|
||||||
|
editor.commands.addCommand({
|
||||||
|
name: "save",
|
||||||
|
exec: save,
|
||||||
|
bindKey: {
|
||||||
|
win: "ctrl-s",
|
||||||
|
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>
|
||||||
Reference in New Issue
Block a user