1
0
mirror of https://github.com/schollz/cowyo.git synced 2023-08-10 21:13:00 +03:00

Implement file upload / download, fix #77

This commit is contained in:
Daniel Heath
2018-02-16 10:50:32 +11:00
parent 4ebf9e02ef
commit efd4cfb0d1
8 changed files with 4094 additions and 14 deletions

View File

@@ -353,3 +353,36 @@ $(window).load(function() {
event.target.classList.add('deleting');
});
});
// TODO: Avoid uploading the same thing twice (check if it's already present while allowing failed uploads to be overwritten?)
function onUploadFinished(file) {
this.removeFile(file);
var cursorPos = $('#userInput').prop('selectionStart');
var cursorEnd = $('#userInput').prop('selectionEnd');
var v = $('#userInput').val();
var textBefore = v.substring(0, cursorPos);
var textAfter = v.substring(cursorPos, v.length);
var message = 'uploaded file';
if (cursorEnd > cursorPos) {
message = v.substring(cursorPos, cursorEnd);
textAfter = v.substring(cursorEnd, v.length);
}
var prefix = '';
if (file.type.startsWith("image")) {
prefix = '!';
}
var extraText = prefix+'['+message+'](' +
file.xhr.getResponseHeader("Location") +
')';
$('#userInput').val(
textBefore +
extraText +
textAfter
);
// Select the newly-inserted link
$('#userInput').prop('selectionStart', cursorPos);
$('#userInput').prop('selectionEnd', cursorPos + extraText.length);
$('#userInput').trigger('keyup'); // trigger a save
}

3504
static/js/dropzone.js Normal file

File diff suppressed because it is too large Load Diff