Update text editor

This commit is contained in:
2020-10-19 18:10:54 +02:00
parent 9825535637
commit 55c2f66709
9 changed files with 811 additions and 171 deletions

View File

@@ -31,7 +31,7 @@ function Modal(parent, closeCallback, title, width, height) {
this.btnClose = document.createElement("button")
this.btnClose.classList = "modal_btn_close button_red"
this.btnClose.innerHTML = '<i class="icon small">close</i>'
this.btnClose.innerHTML = '<i class="icon">close</i>'
this.btnClose.addEventListener("click", e => { this.close() })
this.body = document.createElement("div")

View File

@@ -1,58 +0,0 @@
function uploadText() {
var text = document.getElementById("textarea").value;
var blob = new Blob([text], {type: "text/plain"});
var filename = prompt("What do you want to call this piece of textual art?\n\n"
+ "Please add your own file extension, if you want.",
"Pixeldrain_Text_File.txt");
if(filename === null){
return;
}
new UploadManager(apiEndpoint+"/file", null).addFile(
blob,
filename,
null,
function (id){
addUploadHistory(id);
setTimeout(window.location.href = "/u/" + id, 100);
},
function (response, error) { alert("File upload failed! The server told us this: " + response); }
)
}
// Upload the file when ctrl + s is pressed
document.addEventListener("keydown", function(event) {
if ((event.ctrlKey || event.metaKey) && event.keyCode === 83) {
event.preventDefault();
uploadText();
return false;
}
});
/**
* Prevent the Tab key from moving the cursor outside of the text area
*/
document.getElementById("textarea").addEventListener(
'keydown',
function(e) {
if(e.keyCode === 9) { // tab was pressed
// get caret position/selection
var start = this.selectionStart;
var end = this.selectionEnd;
var target = e.target;
var value = target.value;
// set textarea value to: text before caret + tab + text after caret
target.value = value.substring(0, start) + "\t" + value.substring(end);
// put caret at right position again (add one for the tab)
this.selectionStart = this.selectionEnd = start + 1;
// prevent the focus lose
e.preventDefault();
}
},
false
);