0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 07:13:08 -05:00

Treat pasted image as a drag-dropped image file.

This commit is contained in:
Neil Jenkins 2012-08-03 18:13:41 +10:00
parent a9a0ac6411
commit 50b7ad1e4e
2 changed files with 34 additions and 2 deletions

File diff suppressed because one or more lines are too long

View file

@ -1205,8 +1205,39 @@
// again before our after paste function is called.
var awaitingPaste = false;
doc.addEventListener( isIE ? 'beforepaste' : 'paste', function () {
doc.addEventListener( isIE ? 'beforepaste' : 'paste', function ( event ) {
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;
var range = getSelection(),
@ -1728,6 +1759,7 @@
return getSelection().getTextContent();
},
insertElement: chain( insertElement ),
insertImage: function ( src ) {
var img = createElement( 'IMG', {
src: src