mirror of https://github.com/shadowfacts/type.git
Load files from GitHub
This commit is contained in:
parent
6fedff4466
commit
3e7c2d2d3a
66
main.js
66
main.js
|
@ -1,6 +1,31 @@
|
|||
let editor = new CodeMirror(document.body, {
|
||||
value: "function myScript() {\t\n\treturn 100;\n}",
|
||||
mode: "javascript",
|
||||
// global vars
|
||||
var editor; // code mirror instance
|
||||
var incompleteMark;
|
||||
var focused = false;
|
||||
let invalids = [];
|
||||
|
||||
let extensions = {
|
||||
js: "javascript",
|
||||
kt: "kotlin"
|
||||
};
|
||||
|
||||
// fetch file and setup
|
||||
let file = window.location.hash.substring(1);
|
||||
$.get({
|
||||
url: `https://raw.githubusercontent.com/${file}`,
|
||||
success: (data) => {
|
||||
let parts = file.split(".");
|
||||
let fileExtension = parts[parts.length - 1];
|
||||
let extension = extensions.hasOwnProperty(fileExtension) ? extensions[fileExtension] : fileExtension;
|
||||
setup(data, extension);
|
||||
}
|
||||
});
|
||||
|
||||
// setup
|
||||
function setup(data, extension) {
|
||||
editor = new CodeMirror(document.body, {
|
||||
value: data,
|
||||
mode: extension,
|
||||
readOnly: true,
|
||||
autofocus: true,
|
||||
extraKeys: {
|
||||
|
@ -9,29 +34,27 @@ let editor = new CodeMirror(document.body, {
|
|||
Left: () => {},
|
||||
Right: () => {}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var incompleteMark = editor.doc.markText({ line: 0, ch: 0 }, getEndPos(), {
|
||||
incompleteMark = editor.doc.markText({ line: 0, ch: 0 }, getEndPos(), {
|
||||
className: "incomplete"
|
||||
});
|
||||
});
|
||||
|
||||
var focused = true;
|
||||
|
||||
editor.on("focus", (instance, event) => {
|
||||
focused = true;
|
||||
});
|
||||
editor.on("blur", (instance, event) => {
|
||||
focused = false;
|
||||
})
|
||||
|
||||
editor.on("mousedown", (instance, event) => {
|
||||
editor.on("focus", (instance, event) => {
|
||||
focused = true;
|
||||
});
|
||||
editor.on("blur", (instance, event) => {
|
||||
focused = false;
|
||||
});
|
||||
|
||||
editor.on("mousedown", (instance, event) => {
|
||||
event.preventDefault();
|
||||
editor.focus();
|
||||
});
|
||||
});
|
||||
|
||||
let invalids = [];
|
||||
|
||||
document.addEventListener("keypress", (event) => {
|
||||
document.addEventListener("keypress", (event) => {
|
||||
if (focused) {
|
||||
event.preventDefault();
|
||||
|
||||
|
@ -48,9 +71,9 @@ document.addEventListener("keypress", (event) => {
|
|||
editor.setCursor({ line: pos.line, ch: pos.ch + 1 });
|
||||
updateIncompleteMark();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
document.addEventListener("keydown", (event) => {
|
||||
document.addEventListener("keydown", (event) => {
|
||||
if (focused) {
|
||||
var result = false;
|
||||
|
||||
|
@ -101,7 +124,8 @@ document.addEventListener("keydown", (event) => {
|
|||
event.preventDefault();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function moveToEndOfPreviousLine() {
|
||||
let pos = editor.getCursor();
|
||||
|
|
Loading…
Reference in New Issue