39 lines
1.5 KiB
JavaScript
39 lines
1.5 KiB
JavaScript
require.config({paths: {'vs': 'https://unpkg.com/monaco-editor@latest/min/vs'}});
|
|
|
|
// Before loading vs/editor/editor.main, define a global MonacoEnvironment that overwrites
|
|
// the default worker url location (used when creating WebWorkers). The problem here is that
|
|
// HTML5 does not allow cross-domain web workers, so we need to proxy the instantiation of
|
|
// a web worker through a same-domain script
|
|
window.MonacoEnvironment = {
|
|
getWorkerUrl: function (workerId, label) {
|
|
return `data:text/javascript;charset=utf-8,${encodeURIComponent(`
|
|
self.MonacoEnvironment = {
|
|
baseUrl: 'https://unpkg.com/monaco-editor@latest/min/'
|
|
};
|
|
importScripts('https://unpkg.com/monaco-editor@latest/min/vs/base/worker/workerMain.js');`
|
|
)}`;
|
|
}
|
|
};
|
|
|
|
let editors = [];
|
|
|
|
require(["vs/editor/editor.main"], function () {
|
|
let $filenames = document.querySelectorAll(".monaco-filename");
|
|
document.querySelectorAll('.monaco-editor').forEach((elem, idx) => {
|
|
let $editor = monaco.editor.create(elem, {
|
|
language: 'text',
|
|
theme: 'vs-dark',
|
|
});
|
|
elem.classList.remove("loading", "loading-lg");
|
|
let $filename = $filenames[idx];
|
|
editors.push({
|
|
"filename": $filename,
|
|
"editor": $editor
|
|
});
|
|
$filename.addEventListener('change', () => {
|
|
monaco.editor.setModelLanguage($editor.getModel(), $filename.value.split(".").pop());
|
|
});
|
|
})
|
|
|
|
//monaco.editor.setModelLanguage($editor.getModel(), "go");
|
|
}); |