This repository has been archived by the owner on Mar 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
editor-setup.js
56 lines (49 loc) · 1.53 KB
/
editor-setup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* This file is not here to stay!!!
* This is a temporary kludge to get stuff rolling for TPAC, the editor will be a cleaner directive later on
*/
function loadDefinition(url, name) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (xhttp.readyState == 4 && xhttp.status == 200) {
monaco.languages.typescript.javascriptDefaults.addExtraLib(xhttp.responseText, name ? name : url);
}
};
xhttp.open("GET", url, true);
xhttp.send();
}
var promise_dts = "";
function loadWoTEditor() {
if (!angular.isDefined(window.monaco))
editorSetup();
else
placeEditor();
}
function placeEditor() {
var elm = document.getElementById('container');
if (elm === null) {
console.warn("WTF? why is my dom not there on re-activate");
} else {
return window.woteditor = monaco.editor.create(elm, {
value: '//enter the script to run here\n',
language: 'javascript'
});
}
}
function loadDefinitions() {
// compiler options
monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
target: monaco.languages.typescript.ScriptTarget.ES6,
allowNonTsExtensions: true
});
loadDefinition('wot-all.d.ts');
placeEditor();
}
function editorSetup() {
require.config({ paths: { 'vs': 'node_modules/monaco-editor/min/vs' } });
if (!angular.isDefined(window.monaco)) {
require(['vs/editor/editor.main'], loadDefinitions);
} else {
loadDefinitions();
}
}