mirror of
https://github.com/fastmail/Squire.git
synced 2024-12-22 15:23:29 -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 onPaste = function ( event ) {
|
||||||
var clipboardData = event.clipboardData,
|
var clipboardData = event.clipboardData;
|
||||||
items = clipboardData && clipboardData.items,
|
var items = clipboardData && clipboardData.items;
|
||||||
fireDrop = false,
|
var choosePlain = this.isShiftDown;
|
||||||
hasImage = false,
|
var fireDrop = false;
|
||||||
plainItem = null,
|
var hasImage = false;
|
||||||
self = this,
|
var plainItem = null;
|
||||||
l, item, type, types, data;
|
var self = this;
|
||||||
|
var l, item, type, types, data;
|
||||||
|
|
||||||
// Current HTML5 Clipboard interface
|
// Current HTML5 Clipboard interface
|
||||||
// ---------------------------------
|
// ---------------------------------
|
||||||
|
@ -2170,7 +2177,7 @@ var onPaste = function ( event ) {
|
||||||
while ( l-- ) {
|
while ( l-- ) {
|
||||||
item = items[l];
|
item = items[l];
|
||||||
type = item.type;
|
type = item.type;
|
||||||
if ( type === 'text/html' ) {
|
if ( !choosePlain && type === 'text/html' ) {
|
||||||
/*jshint loopfunc: true */
|
/*jshint loopfunc: true */
|
||||||
item.getAsString( function ( html ) {
|
item.getAsString( function ( html ) {
|
||||||
self.insertHTML( html, true );
|
self.insertHTML( html, true );
|
||||||
|
@ -2181,7 +2188,7 @@ var onPaste = function ( event ) {
|
||||||
if ( type === 'text/plain' ) {
|
if ( type === 'text/plain' ) {
|
||||||
plainItem = item;
|
plainItem = item;
|
||||||
}
|
}
|
||||||
if ( /^image\/.*/.test( type ) ) {
|
if ( !choosePlain && /^image\/.*/.test( type ) ) {
|
||||||
hasImage = true;
|
hasImage = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2233,7 +2240,7 @@ var onPaste = function ( event ) {
|
||||||
// insert plain text instead. On iOS, Facebook (and possibly other
|
// insert plain text instead. On iOS, Facebook (and possibly other
|
||||||
// apps?) copy links as type text/uri-list, but also insert a **blank**
|
// apps?) copy links as type text/uri-list, but also insert a **blank**
|
||||||
// text/plain item onto the clipboard. Why? Who knows.
|
// 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 );
|
this.insertHTML( data, true );
|
||||||
} else if (
|
} else if (
|
||||||
( data = clipboardData.getData( 'text/plain' ) ) ||
|
( data = clipboardData.getData( 'text/plain' ) ) ||
|
||||||
|
@ -2434,6 +2441,8 @@ function Squire ( root, config ) {
|
||||||
this._awaitingPaste = false;
|
this._awaitingPaste = false;
|
||||||
this.addEventListener( isIElt11 ? 'beforecut' : 'cut', onCut );
|
this.addEventListener( isIElt11 ? 'beforecut' : 'cut', onCut );
|
||||||
this.addEventListener( 'copy', onCopy );
|
this.addEventListener( 'copy', onCopy );
|
||||||
|
this.addEventListener( 'keydown', monitorShiftKey );
|
||||||
|
this.addEventListener( 'keyup', monitorShiftKey );
|
||||||
this.addEventListener( isIElt11 ? 'beforepaste' : 'paste', onPaste );
|
this.addEventListener( isIElt11 ? 'beforepaste' : 'paste', onPaste );
|
||||||
this.addEventListener( 'drop', onDrop );
|
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 onPaste = function ( event ) {
|
||||||
var clipboardData = event.clipboardData,
|
var clipboardData = event.clipboardData;
|
||||||
items = clipboardData && clipboardData.items,
|
var items = clipboardData && clipboardData.items;
|
||||||
fireDrop = false,
|
var choosePlain = this.isShiftDown;
|
||||||
hasImage = false,
|
var fireDrop = false;
|
||||||
plainItem = null,
|
var hasImage = false;
|
||||||
self = this,
|
var plainItem = null;
|
||||||
l, item, type, types, data;
|
var self = this;
|
||||||
|
var l, item, type, types, data;
|
||||||
|
|
||||||
// Current HTML5 Clipboard interface
|
// Current HTML5 Clipboard interface
|
||||||
// ---------------------------------
|
// ---------------------------------
|
||||||
|
@ -91,7 +98,7 @@ var onPaste = function ( event ) {
|
||||||
while ( l-- ) {
|
while ( l-- ) {
|
||||||
item = items[l];
|
item = items[l];
|
||||||
type = item.type;
|
type = item.type;
|
||||||
if ( type === 'text/html' ) {
|
if ( !choosePlain && type === 'text/html' ) {
|
||||||
/*jshint loopfunc: true */
|
/*jshint loopfunc: true */
|
||||||
item.getAsString( function ( html ) {
|
item.getAsString( function ( html ) {
|
||||||
self.insertHTML( html, true );
|
self.insertHTML( html, true );
|
||||||
|
@ -102,7 +109,7 @@ var onPaste = function ( event ) {
|
||||||
if ( type === 'text/plain' ) {
|
if ( type === 'text/plain' ) {
|
||||||
plainItem = item;
|
plainItem = item;
|
||||||
}
|
}
|
||||||
if ( /^image\/.*/.test( type ) ) {
|
if ( !choosePlain && /^image\/.*/.test( type ) ) {
|
||||||
hasImage = true;
|
hasImage = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -154,7 +161,7 @@ var onPaste = function ( event ) {
|
||||||
// insert plain text instead. On iOS, Facebook (and possibly other
|
// insert plain text instead. On iOS, Facebook (and possibly other
|
||||||
// apps?) copy links as type text/uri-list, but also insert a **blank**
|
// apps?) copy links as type text/uri-list, but also insert a **blank**
|
||||||
// text/plain item onto the clipboard. Why? Who knows.
|
// 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 );
|
this.insertHTML( data, true );
|
||||||
} else if (
|
} else if (
|
||||||
( data = clipboardData.getData( 'text/plain' ) ) ||
|
( data = clipboardData.getData( 'text/plain' ) ) ||
|
||||||
|
|
|
@ -103,6 +103,8 @@ function Squire ( root, config ) {
|
||||||
this._awaitingPaste = false;
|
this._awaitingPaste = false;
|
||||||
this.addEventListener( isIElt11 ? 'beforecut' : 'cut', onCut );
|
this.addEventListener( isIElt11 ? 'beforecut' : 'cut', onCut );
|
||||||
this.addEventListener( 'copy', onCopy );
|
this.addEventListener( 'copy', onCopy );
|
||||||
|
this.addEventListener( 'keydown', monitorShiftKey );
|
||||||
|
this.addEventListener( 'keyup', monitorShiftKey );
|
||||||
this.addEventListener( isIElt11 ? 'beforepaste' : 'paste', onPaste );
|
this.addEventListener( isIElt11 ? 'beforepaste' : 'paste', onPaste );
|
||||||
this.addEventListener( 'drop', onDrop );
|
this.addEventListener( 'drop', onDrop );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue