322 lines
No EOL
7.8 KiB
HTML
322 lines
No EOL
7.8 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
|
"http://www.w3.org/TR/html4/strict.dtd">
|
|
|
|
<html lang="en">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<title>Editor</title>
|
|
<meta name="author" content="Fabian Jakobs">
|
|
|
|
<style type="text/css" media="screen">
|
|
|
|
html {
|
|
height: 100%;
|
|
overflow: hidden;
|
|
}
|
|
|
|
body {
|
|
overflow: hidden;
|
|
margin: 0;
|
|
padding: 0;
|
|
font: sans-serif;
|
|
height: 100%;
|
|
width: 100%;
|
|
font-family: Arial, Helvetica, sans-serif, Tahoma, Verdana;
|
|
font-size: 12px;
|
|
background: rgb(14, 98, 165);
|
|
color: white;
|
|
}
|
|
|
|
#editor {
|
|
top: 55px;
|
|
left: 0px;
|
|
background: white;
|
|
}
|
|
|
|
#controls {
|
|
width: 100%;
|
|
height: 55px;
|
|
}
|
|
|
|
#jump {
|
|
position: absolute;
|
|
width: 10px;
|
|
height: 10px;
|
|
border: 1px solid red;
|
|
z-index: 10000;
|
|
display: none;
|
|
}
|
|
|
|
</style>
|
|
<script src="demo/require.js" type="text/javascript" charset="utf-8"></script>
|
|
</head>
|
|
<body>
|
|
<div id="jump"></div>
|
|
|
|
<table id="controls">
|
|
<tr>
|
|
<td>
|
|
<label for="doc">Document:</label>
|
|
<select id="doc" size="1">
|
|
<option value="js">JS Document</option>
|
|
<option value="html">HTML Document</option>
|
|
<option value="css">CSS Document</option>
|
|
</select>
|
|
</td>
|
|
<td>
|
|
<label for="mode">Mode:</label>
|
|
<select id="mode" size="1">
|
|
<option value="text">Plain Text</option>
|
|
<option value="javascript">JavaScript</option>
|
|
<option value="xml">XML</option>
|
|
<option value="html">HTML</option>
|
|
<option value="css">CSS</option>
|
|
</select>
|
|
</td>
|
|
<td>
|
|
<label for="theme">Theme:</label>
|
|
<select id="theme" size="1">
|
|
<option value="ace/theme/textmate">TextMate</option>
|
|
<option value="ace/theme/eclipse">Eclipse</option>
|
|
<option value="ace/theme/dawn">Dawn</option>
|
|
<option value="ace/theme/idle_fingers">idleFingers</option>
|
|
<option value="ace/theme/twilight">Twilight</option>
|
|
</select>
|
|
</td>
|
|
<td>
|
|
<label for="select_style">Full line selections</label>
|
|
<input type="checkbox" name="select_style" id="select_style" checked>
|
|
</td>
|
|
<td>
|
|
<label for="highlight_active">Highlight active line</label>
|
|
<input type="checkbox" name="highlight_active" id="highlight_active" checked>
|
|
</td>
|
|
<td align="right">
|
|
<img src="demo/logo.png">
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<div id="editor">
|
|
</div>
|
|
|
|
<script type="text/editor" id="jstext">function foo(items) {
|
|
for (var i=0; i<items.length; i++) {
|
|
alert(items[i] + "juhu");
|
|
}
|
|
}</script>
|
|
|
|
<script type="text/editor" id="csstext">.text-layer {
|
|
font-family: Monaco, "Courier New", monospace;
|
|
font-size: 12px;
|
|
cursor: text;
|
|
}
|
|
</script>
|
|
|
|
<script type="text/editor" id="htmltext"><html>
|
|
<head>
|
|
|
|
<style type="text/css">
|
|
.text-layer {
|
|
font-family: Monaco, "Courier New", monospace;
|
|
font-size: 12px;
|
|
cursor: text;
|
|
}
|
|
</style>
|
|
|
|
</head>
|
|
<body>
|
|
<h1 style="color:red">Juhu Kinners</h1>
|
|
</body>
|
|
</html>
|
|
</script>
|
|
|
|
<script type="text/javascript" charset="utf-8">
|
|
|
|
require(
|
|
{ baseUrl: "lib" },
|
|
[
|
|
"ace/lib/event",
|
|
"ace/editor",
|
|
"ace/virtual_renderer",
|
|
"ace/theme/textmate",
|
|
"ace/document",
|
|
"ace/mode/javascript",
|
|
"ace/mode/css",
|
|
"ace/mode/html",
|
|
"ace/mode/xml",
|
|
"ace/mode/text",
|
|
"ace/undomanager"
|
|
], function(
|
|
eventMod,
|
|
editorMod,
|
|
Renderer,
|
|
theme,
|
|
docMod,
|
|
jsMod,
|
|
cssMod,
|
|
htmlMod,
|
|
xmlMod,
|
|
textMod,
|
|
UndoManager
|
|
) {
|
|
|
|
var event = eventMod.event;
|
|
var Editor = editorMod.Editor;
|
|
|
|
|
|
var Document = docMod.Document;
|
|
var JavaScriptMode = jsMod.JavaScript;
|
|
var CssMode = cssMod.Css;
|
|
var HtmlMode = htmlMod.Html;
|
|
var XmlMode = xmlMod.Xml;
|
|
var TextMode = textMod.Text;
|
|
|
|
|
|
var docs = {}
|
|
|
|
docs.js = new Document(document.getElementById("jstext").innerHTML);
|
|
docs.js.setMode(new JavaScriptMode());
|
|
docs.js.setUndoManager(new UndoManager());
|
|
|
|
docs.css = new Document(document.getElementById("csstext").innerHTML);
|
|
docs.css.setMode(new CssMode());
|
|
docs.css.setUndoManager(new UndoManager());
|
|
|
|
docs.html = new Document(document.getElementById("htmltext").innerHTML);
|
|
docs.html.setMode(new HtmlMode());
|
|
docs.html.setUndoManager(new UndoManager());
|
|
|
|
var docEl = document.getElementById("doc");
|
|
|
|
function onDocChange() {
|
|
var doc = getDoc();
|
|
editor.setDocument(doc);
|
|
|
|
var mode = doc.getMode();
|
|
if (mode instanceof JavaScriptMode) {
|
|
modeEl.value = "javascript"
|
|
}
|
|
else if (mode instanceof CssMode) {
|
|
modeEl.value = "css"
|
|
}
|
|
else if (mode instanceof HtmlMode) {
|
|
modeEl.value = "html"
|
|
}
|
|
else if (mode instanceof XmlMode) {
|
|
modeEl.value = "xml"
|
|
}
|
|
else {
|
|
modeEl.value = "text"
|
|
}
|
|
|
|
editor.focus();
|
|
}
|
|
docEl.onchange = onDocChange;
|
|
|
|
function getDoc() {
|
|
return docs[docEl.value];
|
|
}
|
|
|
|
var modeEl = document.getElementById("mode");
|
|
modeEl.onchange = function() {
|
|
editor.getDocument().setMode(modes[modeEl.value] || modes.text);
|
|
};
|
|
|
|
var modes = {
|
|
text: new TextMode(),
|
|
xml: new XmlMode(),
|
|
html: new HtmlMode(),
|
|
css: new CssMode(),
|
|
javascript: new JavaScriptMode()
|
|
};
|
|
|
|
function getMode() {
|
|
return modes[modeEl.value];
|
|
}
|
|
|
|
var themeEl = document.getElementById("theme");
|
|
themeEl.onchange = function() {
|
|
editor.setTheme(themeEl.value);
|
|
};
|
|
|
|
var selectEl = document.getElementById("select_style");
|
|
selectEl.onchange = function() {
|
|
if (selectEl.checked) {
|
|
editor.setSelectionStyle("line");
|
|
} else {
|
|
editor.setSelectionStyle("text");
|
|
}
|
|
};
|
|
|
|
var activeEl = document.getElementById("highlight_active");
|
|
activeEl.onchange = function() {
|
|
editor.setHighlightActiveLine(!!activeEl.checked);
|
|
};
|
|
|
|
var container = document.getElementById("editor");
|
|
var editor = new Editor(new Renderer(container, theme));
|
|
onDocChange();
|
|
|
|
window.jump = function() {
|
|
var jump = document.getElementById("jump")
|
|
var cursor = editor.getCursorPosition()
|
|
var pos = editor.renderer.textToScreenCoordinates(cursor.row, cursor.column);
|
|
jump.style.left = pos.pageX + "px";
|
|
jump.style.top = pos.pageY + "px";
|
|
jump.style.display = "block";
|
|
}
|
|
|
|
function onResize() {
|
|
container.style.width = (document.documentElement.clientWidth - 4) + "px";
|
|
container.style.height = (document.documentElement.clientHeight - 55 - 4) + "px";
|
|
editor.resize();
|
|
};
|
|
|
|
window.onresize = onResize;
|
|
onResize();
|
|
|
|
event.addListener(container, "dragover", function(e) {
|
|
return event.preventDefault(e);
|
|
});
|
|
|
|
event.addListener(container, "drop", function(e) {
|
|
try {
|
|
var file = e.dataTransfer.files[0];
|
|
} catch(e) {
|
|
return event.stopEvent();
|
|
}
|
|
|
|
if (window.FileReader) {
|
|
var reader = new FileReader();
|
|
reader.onload = function(e) {
|
|
editor.getSelection().selectAll();
|
|
|
|
var mode = "text";
|
|
if (/^.*\.js$/i.test(file.name)) {
|
|
mode = "javascript";
|
|
} else if (/^.*\.xml$/i.test(file.name)) {
|
|
mode = "xml";
|
|
} else if (/^.*\.html$/i.test(file.name)) {
|
|
mode = "html";
|
|
} else if (/^.*\.css$/i.test(file.name)) {
|
|
mode = "css";
|
|
}
|
|
|
|
editor.onTextInput(reader.result);
|
|
|
|
modeEl.value = mode;
|
|
editor.getDocument().setMode(modes[mode]);
|
|
}
|
|
reader.readAsText(file);
|
|
}
|
|
|
|
return event.preventDefault(e);
|
|
});
|
|
|
|
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
</html> |