mirror of
https://github.com/fastmail/Squire.git
synced 2024-12-22 07:13:08 -05:00
Add config.willCutCopy option
Is an optional function that transforms the HTML being cut/copied before placing it on the clipboard.
This commit is contained in:
parent
f0594091c5
commit
e3e7c17315
4 changed files with 22 additions and 12 deletions
|
@ -2134,8 +2134,9 @@ var cleanupBRs = function ( node, root, keepForBlankLine ) {
|
|||
// The (non-standard but supported enough) innerText property is based on the
|
||||
// render tree in Firefox and possibly other browsers, so we must insert the
|
||||
// DOM node into the document to ensure the text part is correct.
|
||||
var setClipboardData = function ( clipboardData, node, root ) {
|
||||
var setClipboardData = function ( clipboardData, node, root, config ) {
|
||||
var body = node.ownerDocument.body;
|
||||
var willCutCopy = config.willCutCopy;
|
||||
var html, text;
|
||||
|
||||
// Firefox will add an extra new line for BRs at the end of block when
|
||||
|
@ -2149,6 +2150,10 @@ var setClipboardData = function ( clipboardData, node, root ) {
|
|||
html = node.innerHTML;
|
||||
text = node.innerText || node.textContent;
|
||||
|
||||
if ( willCutCopy ) {
|
||||
html = willCutCopy( html );
|
||||
}
|
||||
|
||||
// Firefox (and others?) returns unix line endings (\n) even on Windows.
|
||||
// If on Windows, normalise to \r\n, since Notepad and some other crappy
|
||||
// apps do not understand just \n.
|
||||
|
@ -2203,7 +2208,7 @@ var onCut = function ( event ) {
|
|||
// Set clipboard data
|
||||
node = this.createElement( 'div' );
|
||||
node.appendChild( contents );
|
||||
setClipboardData( clipboardData, node, root );
|
||||
setClipboardData( clipboardData, node, root, this._config );
|
||||
event.preventDefault();
|
||||
} else {
|
||||
setTimeout( function () {
|
||||
|
@ -2255,7 +2260,7 @@ var onCopy = function ( event ) {
|
|||
// Set clipboard data
|
||||
node = this.createElement( 'div' );
|
||||
node.appendChild( contents );
|
||||
setClipboardData( clipboardData, node, root );
|
||||
setClipboardData( clipboardData, node, root, this._config );
|
||||
event.preventDefault();
|
||||
}
|
||||
};
|
||||
|
@ -2647,8 +2652,8 @@ proto.setConfig = function ( config ) {
|
|||
isSetHTMLSanitized: true,
|
||||
sanitizeToDOMFragment:
|
||||
typeof DOMPurify !== 'undefined' && DOMPurify.isSupported ?
|
||||
sanitizeToDOMFragment : null
|
||||
|
||||
sanitizeToDOMFragment : null,
|
||||
willCutCopy: null
|
||||
}, config, true );
|
||||
|
||||
// Users may specify block tag in lower case
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -3,8 +3,9 @@
|
|||
// The (non-standard but supported enough) innerText property is based on the
|
||||
// render tree in Firefox and possibly other browsers, so we must insert the
|
||||
// DOM node into the document to ensure the text part is correct.
|
||||
var setClipboardData = function ( clipboardData, node, root ) {
|
||||
var setClipboardData = function ( clipboardData, node, root, config ) {
|
||||
var body = node.ownerDocument.body;
|
||||
var willCutCopy = config.willCutCopy;
|
||||
var html, text;
|
||||
|
||||
// Firefox will add an extra new line for BRs at the end of block when
|
||||
|
@ -18,6 +19,10 @@ var setClipboardData = function ( clipboardData, node, root ) {
|
|||
html = node.innerHTML;
|
||||
text = node.innerText || node.textContent;
|
||||
|
||||
if ( willCutCopy ) {
|
||||
html = willCutCopy( html );
|
||||
}
|
||||
|
||||
// Firefox (and others?) returns unix line endings (\n) even on Windows.
|
||||
// If on Windows, normalise to \r\n, since Notepad and some other crappy
|
||||
// apps do not understand just \n.
|
||||
|
@ -72,7 +77,7 @@ var onCut = function ( event ) {
|
|||
// Set clipboard data
|
||||
node = this.createElement( 'div' );
|
||||
node.appendChild( contents );
|
||||
setClipboardData( clipboardData, node, root );
|
||||
setClipboardData( clipboardData, node, root, this._config );
|
||||
event.preventDefault();
|
||||
} else {
|
||||
setTimeout( function () {
|
||||
|
@ -124,7 +129,7 @@ var onCopy = function ( event ) {
|
|||
// Set clipboard data
|
||||
node = this.createElement( 'div' );
|
||||
node.appendChild( contents );
|
||||
setClipboardData( clipboardData, node, root );
|
||||
setClipboardData( clipboardData, node, root, this._config );
|
||||
event.preventDefault();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -186,8 +186,8 @@ proto.setConfig = function ( config ) {
|
|||
isSetHTMLSanitized: true,
|
||||
sanitizeToDOMFragment:
|
||||
typeof DOMPurify !== 'undefined' && DOMPurify.isSupported ?
|
||||
sanitizeToDOMFragment : null
|
||||
|
||||
sanitizeToDOMFragment : null,
|
||||
willCutCopy: null
|
||||
}, config, true );
|
||||
|
||||
// Users may specify block tag in lower case
|
||||
|
|
Loading…
Reference in a new issue