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:
@@ -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
3504
static/js/dropzone.js
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user