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");
|
|
|
|
|
2013-09-01 18:09:09 +00:00
|
|
|
var container = document.body.find(".editor-container");
|
2013-08-20 00:53:03 +00:00
|
|
|
var containerSize = container.getBoundingClientRect();
|
|
|
|
|
|
|
|
window.on("resize", function() {
|
|
|
|
var size = container.getBoundingClientRect();
|
2013-09-01 18:09:09 +00:00
|
|
|
var editorDiv = document.body.find("#editor");
|
2013-08-20 00:53:03 +00:00
|
|
|
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");
|
|
|
|
|
2013-09-02 01:26:22 +00:00
|
|
|
//one-time startup
|
|
|
|
var init = function() {
|
|
|
|
cfg.themes.forEach(function(theme) {
|
|
|
|
var option = document.createElement("option");
|
|
|
|
option.innerHTML = theme.alt || theme.label;
|
|
|
|
option.setAttribute("value", theme.name);
|
|
|
|
themes.append(option);
|
|
|
|
});
|
|
|
|
reset();
|
|
|
|
};
|
|
|
|
|
|
|
|
//reloaded when settings change
|
|
|
|
var reset = function() {
|
|
|
|
themes.value = "chrome";
|
|
|
|
editor.setTheme("ace/theme/" + themes.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
command.on("init:startup", init);
|
|
|
|
command.on("init:restart", reset);
|
2013-08-23 23:03:46 +00:00
|
|
|
|
|
|
|
command.on("editor:theme", function(theme) {
|
|
|
|
editor.setTheme("ace/theme/" + theme);
|
|
|
|
});
|
|
|
|
|
2013-08-20 00:53:03 +00:00
|
|
|
return editor;
|
|
|
|
|
|
|
|
});
|