mirror of https://github.com/shadowfacts/type.git
Load files from GitHub
This commit is contained in:
parent
6fedff4466
commit
3e7c2d2d3a
40
main.js
40
main.js
|
@ -1,6 +1,31 @@
|
||||||
let editor = new CodeMirror(document.body, {
|
// global vars
|
||||||
value: "function myScript() {\t\n\treturn 100;\n}",
|
var editor; // code mirror instance
|
||||||
mode: "javascript",
|
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,
|
readOnly: true,
|
||||||
autofocus: true,
|
autofocus: true,
|
||||||
extraKeys: {
|
extraKeys: {
|
||||||
|
@ -11,26 +36,24 @@ let editor = new CodeMirror(document.body, {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var incompleteMark = editor.doc.markText({ line: 0, ch: 0 }, getEndPos(), {
|
incompleteMark = editor.doc.markText({ line: 0, ch: 0 }, getEndPos(), {
|
||||||
className: "incomplete"
|
className: "incomplete"
|
||||||
});
|
});
|
||||||
|
|
||||||
var focused = true;
|
focused = true;
|
||||||
|
|
||||||
editor.on("focus", (instance, event) => {
|
editor.on("focus", (instance, event) => {
|
||||||
focused = true;
|
focused = true;
|
||||||
});
|
});
|
||||||
editor.on("blur", (instance, event) => {
|
editor.on("blur", (instance, event) => {
|
||||||
focused = false;
|
focused = false;
|
||||||
})
|
});
|
||||||
|
|
||||||
editor.on("mousedown", (instance, event) => {
|
editor.on("mousedown", (instance, event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
editor.focus();
|
editor.focus();
|
||||||
});
|
});
|
||||||
|
|
||||||
let invalids = [];
|
|
||||||
|
|
||||||
document.addEventListener("keypress", (event) => {
|
document.addEventListener("keypress", (event) => {
|
||||||
if (focused) {
|
if (focused) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
@ -102,6 +125,7 @@ document.addEventListener("keydown", (event) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function moveToEndOfPreviousLine() {
|
function moveToEndOfPreviousLine() {
|
||||||
let pos = editor.getCursor();
|
let pos = editor.getCursor();
|
||||||
|
|
Loading…
Reference in New Issue