mirror of
https://github.com/fastmail/Squire.git
synced 2024-12-22 07:13:08 -05:00
parent
cbde7a9198
commit
9aacad6e3c
4 changed files with 40 additions and 22 deletions
|
@ -2150,14 +2150,21 @@ var onCopy = function ( event ) {
|
|||
}
|
||||
};
|
||||
|
||||
// Need to monitor for shift key like this, as event.shiftKey is not available
|
||||
// in paste event.
|
||||
function monitorShiftKey ( event ) {
|
||||
this.isShiftDown = event.shiftKey;
|
||||
}
|
||||
|
||||
var onPaste = function ( event ) {
|
||||
var clipboardData = event.clipboardData,
|
||||
items = clipboardData && clipboardData.items,
|
||||
fireDrop = false,
|
||||
hasImage = false,
|
||||
plainItem = null,
|
||||
self = this,
|
||||
l, item, type, types, data;
|
||||
var clipboardData = event.clipboardData;
|
||||
var items = clipboardData && clipboardData.items;
|
||||
var choosePlain = this.isShiftDown;
|
||||
var fireDrop = false;
|
||||
var hasImage = false;
|
||||
var plainItem = null;
|
||||
var self = this;
|
||||
var l, item, type, types, data;
|
||||
|
||||
// Current HTML5 Clipboard interface
|
||||
// ---------------------------------
|
||||
|
@ -2170,7 +2177,7 @@ var onPaste = function ( event ) {
|
|||
while ( l-- ) {
|
||||
item = items[l];
|
||||
type = item.type;
|
||||
if ( type === 'text/html' ) {
|
||||
if ( !choosePlain && type === 'text/html' ) {
|
||||
/*jshint loopfunc: true */
|
||||
item.getAsString( function ( html ) {
|
||||
self.insertHTML( html, true );
|
||||
|
@ -2181,7 +2188,7 @@ var onPaste = function ( event ) {
|
|||
if ( type === 'text/plain' ) {
|
||||
plainItem = item;
|
||||
}
|
||||
if ( /^image\/.*/.test( type ) ) {
|
||||
if ( !choosePlain && /^image\/.*/.test( type ) ) {
|
||||
hasImage = true;
|
||||
}
|
||||
}
|
||||
|
@ -2233,7 +2240,7 @@ var onPaste = function ( event ) {
|
|||
// insert plain text instead. On iOS, Facebook (and possibly other
|
||||
// apps?) copy links as type text/uri-list, but also insert a **blank**
|
||||
// text/plain item onto the clipboard. Why? Who knows.
|
||||
if (( data = clipboardData.getData( 'text/html' ) )) {
|
||||
if ( !choosePlain && ( data = clipboardData.getData( 'text/html' ) ) ) {
|
||||
this.insertHTML( data, true );
|
||||
} else if (
|
||||
( data = clipboardData.getData( 'text/plain' ) ) ||
|
||||
|
@ -2434,6 +2441,8 @@ function Squire ( root, config ) {
|
|||
this._awaitingPaste = false;
|
||||
this.addEventListener( isIElt11 ? 'beforecut' : 'cut', onCut );
|
||||
this.addEventListener( 'copy', onCopy );
|
||||
this.addEventListener( 'keydown', monitorShiftKey );
|
||||
this.addEventListener( 'keyup', monitorShiftKey );
|
||||
this.addEventListener( isIElt11 ? 'beforepaste' : 'paste', onPaste );
|
||||
this.addEventListener( 'drop', onDrop );
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -71,14 +71,21 @@ var onCopy = function ( event ) {
|
|||
}
|
||||
};
|
||||
|
||||
// Need to monitor for shift key like this, as event.shiftKey is not available
|
||||
// in paste event.
|
||||
function monitorShiftKey ( event ) {
|
||||
this.isShiftDown = event.shiftKey;
|
||||
}
|
||||
|
||||
var onPaste = function ( event ) {
|
||||
var clipboardData = event.clipboardData,
|
||||
items = clipboardData && clipboardData.items,
|
||||
fireDrop = false,
|
||||
hasImage = false,
|
||||
plainItem = null,
|
||||
self = this,
|
||||
l, item, type, types, data;
|
||||
var clipboardData = event.clipboardData;
|
||||
var items = clipboardData && clipboardData.items;
|
||||
var choosePlain = this.isShiftDown;
|
||||
var fireDrop = false;
|
||||
var hasImage = false;
|
||||
var plainItem = null;
|
||||
var self = this;
|
||||
var l, item, type, types, data;
|
||||
|
||||
// Current HTML5 Clipboard interface
|
||||
// ---------------------------------
|
||||
|
@ -91,7 +98,7 @@ var onPaste = function ( event ) {
|
|||
while ( l-- ) {
|
||||
item = items[l];
|
||||
type = item.type;
|
||||
if ( type === 'text/html' ) {
|
||||
if ( !choosePlain && type === 'text/html' ) {
|
||||
/*jshint loopfunc: true */
|
||||
item.getAsString( function ( html ) {
|
||||
self.insertHTML( html, true );
|
||||
|
@ -102,7 +109,7 @@ var onPaste = function ( event ) {
|
|||
if ( type === 'text/plain' ) {
|
||||
plainItem = item;
|
||||
}
|
||||
if ( /^image\/.*/.test( type ) ) {
|
||||
if ( !choosePlain && /^image\/.*/.test( type ) ) {
|
||||
hasImage = true;
|
||||
}
|
||||
}
|
||||
|
@ -154,7 +161,7 @@ var onPaste = function ( event ) {
|
|||
// insert plain text instead. On iOS, Facebook (and possibly other
|
||||
// apps?) copy links as type text/uri-list, but also insert a **blank**
|
||||
// text/plain item onto the clipboard. Why? Who knows.
|
||||
if (( data = clipboardData.getData( 'text/html' ) )) {
|
||||
if ( !choosePlain && ( data = clipboardData.getData( 'text/html' ) ) ) {
|
||||
this.insertHTML( data, true );
|
||||
} else if (
|
||||
( data = clipboardData.getData( 'text/plain' ) ) ||
|
||||
|
|
|
@ -103,6 +103,8 @@ function Squire ( root, config ) {
|
|||
this._awaitingPaste = false;
|
||||
this.addEventListener( isIElt11 ? 'beforecut' : 'cut', onCut );
|
||||
this.addEventListener( 'copy', onCopy );
|
||||
this.addEventListener( 'keydown', monitorShiftKey );
|
||||
this.addEventListener( 'keyup', monitorShiftKey );
|
||||
this.addEventListener( isIElt11 ? 'beforepaste' : 'paste', onPaste );
|
||||
this.addEventListener( 'drop', onDrop );
|
||||
|
||||
|
|
Loading…
Reference in a new issue