Caret/js/editor.js

39 lines
1.2 KiB
JavaScript
Raw Normal View History

2013-08-23 23:03:46 +00:00
define(["file", "command", "json!config/ace.json", "dom2"], function(File, command, cfg) {
2013-08-20 00:53:03 +00:00
/*
Module for loading the editor, adding window resizing and other events. Returns the editor straight from Ace.
*/
var editor = window.editor = ace.edit("editor");
var session = window.session = editor.getSession();
session.setMode("ace/mode/javascript");
editor.setTheme("ace/theme/chrome");
var container = document.body.query(".editor-container").pop();
var containerSize = container.getBoundingClientRect();
window.on("resize", function() {
var size = container.getBoundingClientRect();
var editorDiv = document.body.query("#editor").pop();
editorDiv.style.width = size.width + "px";
editorDiv.style.height = size.height + "px";
editor.resize();
});
window.dispatchEvent(new Event("resize"));
2013-08-23 23:03:46 +00:00
var themes = document.querySelector(".theme");
cfg.themes.forEach(function(theme) {
var option = document.createElement("option");
option.innerHTML = theme.alt || theme.label;
option.setAttribute("value", theme.name);
themes.append(option);
});
themes.value = "chrome";
command.on("editor:theme", function(theme) {
editor.setTheme("ace/theme/" + theme);
});
2013-08-20 00:53:03 +00:00
return editor;
});