mirror of
https://github.com/zulip/zulip.git
synced 2025-11-12 09:58:06 +00:00
Allow pasting images from the clipboard to upload an image
(imported from commit 0d0ebecdb35521819433691c2d3a07fb13572eb4)
This commit is contained in:
@@ -76,6 +76,8 @@
|
|||||||
caller = this;
|
caller = this;
|
||||||
|
|
||||||
this.on('drop', drop).on('dragstart', opts.dragStart).on('dragenter', dragEnter).on('dragover', dragOver).on('dragleave', dragLeave);
|
this.on('drop', drop).on('dragstart', opts.dragStart).on('dragenter', dragEnter).on('dragover', dragOver).on('dragleave', dragLeave);
|
||||||
|
this.on('paste', paste);
|
||||||
|
|
||||||
$(document).on('drop', docDrop).on('dragenter', docEnter).on('dragover', docOver).on('dragleave', docLeave);
|
$(document).on('drop', docDrop).on('dragenter', docEnter).on('dragover', docOver).on('dragleave', docLeave);
|
||||||
|
|
||||||
$('#' + opts.fallback_id).change(function(e) {
|
$('#' + opts.fallback_id).change(function(e) {
|
||||||
@@ -107,6 +109,38 @@
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function paste(event) {
|
||||||
|
// Take the first image pasted in the clipboard
|
||||||
|
var match_re = /image.*/;
|
||||||
|
var item;
|
||||||
|
$.each(event.originalEvent.clipboardData.items, function (idx, this_event) {
|
||||||
|
if (this_event.type.match(match_re)) {
|
||||||
|
item = this_event;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (item === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call the user callback to initialize the drop event
|
||||||
|
if( opts.drop.call(this, event) === false ) return false;
|
||||||
|
|
||||||
|
// Read the data of the drop in as binary data, and send it to the server
|
||||||
|
var data = item.getAsFile();
|
||||||
|
var reader = new FileReader();
|
||||||
|
reader.onload = function(event) {
|
||||||
|
function finished_callback(serverResponse, timeDiff, xhr) {
|
||||||
|
return opts.uploadFinished(-1, undefined, serverResponse, timeDiff, xhr);
|
||||||
|
}
|
||||||
|
|
||||||
|
var url_params = "?mimetype=" + encodeURIComponent(data.type);
|
||||||
|
do_xhr("pasted_image", event.target.result, data.type, {}, url_params, finished_callback, function () {});
|
||||||
|
};
|
||||||
|
reader.readAsBinaryString(data);
|
||||||
|
}
|
||||||
|
|
||||||
function getBuilder(filename, filedata, mime, boundary) {
|
function getBuilder(filename, filedata, mime, boundary) {
|
||||||
var dashdash = '--',
|
var dashdash = '--',
|
||||||
crlf = '\r\n',
|
crlf = '\r\n',
|
||||||
|
|||||||
Reference in New Issue
Block a user