mirror of
https://github.com/fastmail/Squire.git
synced 2025-01-03 13:16:31 -05:00
Treat pasted image as a drag-dropped image file.
This commit is contained in:
parent
a9a0ac6411
commit
50b7ad1e4e
2 changed files with 34 additions and 2 deletions
File diff suppressed because one or more lines are too long
|
@ -1205,8 +1205,39 @@
|
||||||
// again before our after paste function is called.
|
// again before our after paste function is called.
|
||||||
var awaitingPaste = false;
|
var awaitingPaste = false;
|
||||||
|
|
||||||
doc.addEventListener( isIE ? 'beforepaste' : 'paste', function () {
|
doc.addEventListener( isIE ? 'beforepaste' : 'paste', function ( event ) {
|
||||||
if ( awaitingPaste ) { return; }
|
if ( awaitingPaste ) { return; }
|
||||||
|
|
||||||
|
// Treat image paste as a drop of an image file.
|
||||||
|
var clipboardData = event.clipboardData,
|
||||||
|
items = clipboardData && clipboardData.items,
|
||||||
|
fireDrop = false,
|
||||||
|
l;
|
||||||
|
if ( items ) {
|
||||||
|
l = items.length;
|
||||||
|
while ( l-- ) {
|
||||||
|
if ( /^image\/.*/.test( items[l].type ) ) {
|
||||||
|
event.preventDefault();
|
||||||
|
fireEvent( 'dragover', {
|
||||||
|
type: 'dragover',
|
||||||
|
dataTransfer: clipboardData,
|
||||||
|
/*jshint loopfunc: true */
|
||||||
|
preventDefault: function () {
|
||||||
|
fireDrop = true;
|
||||||
|
}
|
||||||
|
/*jshint loopfunc: false */
|
||||||
|
});
|
||||||
|
if ( fireDrop ) {
|
||||||
|
fireEvent( 'drop', {
|
||||||
|
type: 'drop',
|
||||||
|
dataTransfer: clipboardData
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
awaitingPaste = true;
|
awaitingPaste = true;
|
||||||
|
|
||||||
var range = getSelection(),
|
var range = getSelection(),
|
||||||
|
@ -1728,6 +1759,7 @@
|
||||||
return getSelection().getTextContent();
|
return getSelection().getTextContent();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
insertElement: chain( insertElement ),
|
||||||
insertImage: function ( src ) {
|
insertImage: function ( src ) {
|
||||||
var img = createElement( 'IMG', {
|
var img = createElement( 'IMG', {
|
||||||
src: src
|
src: src
|
||||||
|
|
Loading…
Reference in a new issue