mirror of
https://github.com/fastmail/Squire.git
synced 2025-01-18 04:32:28 -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
|
// 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
|
// 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.
|
// 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 body = node.ownerDocument.body;
|
||||||
|
var willCutCopy = config.willCutCopy;
|
||||||
var html, text;
|
var html, text;
|
||||||
|
|
||||||
// Firefox will add an extra new line for BRs at the end of block when
|
// 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;
|
html = node.innerHTML;
|
||||||
text = node.innerText || node.textContent;
|
text = node.innerText || node.textContent;
|
||||||
|
|
||||||
|
if ( willCutCopy ) {
|
||||||
|
html = willCutCopy( html );
|
||||||
|
}
|
||||||
|
|
||||||
// Firefox (and others?) returns unix line endings (\n) even on Windows.
|
// Firefox (and others?) returns unix line endings (\n) even on Windows.
|
||||||
// If on Windows, normalise to \r\n, since Notepad and some other crappy
|
// If on Windows, normalise to \r\n, since Notepad and some other crappy
|
||||||
// apps do not understand just \n.
|
// apps do not understand just \n.
|
||||||
|
@ -2203,7 +2208,7 @@ var onCut = function ( event ) {
|
||||||
// Set clipboard data
|
// Set clipboard data
|
||||||
node = this.createElement( 'div' );
|
node = this.createElement( 'div' );
|
||||||
node.appendChild( contents );
|
node.appendChild( contents );
|
||||||
setClipboardData( clipboardData, node, root );
|
setClipboardData( clipboardData, node, root, this._config );
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
} else {
|
} else {
|
||||||
setTimeout( function () {
|
setTimeout( function () {
|
||||||
|
@ -2255,7 +2260,7 @@ var onCopy = function ( event ) {
|
||||||
// Set clipboard data
|
// Set clipboard data
|
||||||
node = this.createElement( 'div' );
|
node = this.createElement( 'div' );
|
||||||
node.appendChild( contents );
|
node.appendChild( contents );
|
||||||
setClipboardData( clipboardData, node, root );
|
setClipboardData( clipboardData, node, root, this._config );
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -2647,8 +2652,8 @@ proto.setConfig = function ( config ) {
|
||||||
isSetHTMLSanitized: true,
|
isSetHTMLSanitized: true,
|
||||||
sanitizeToDOMFragment:
|
sanitizeToDOMFragment:
|
||||||
typeof DOMPurify !== 'undefined' && DOMPurify.isSupported ?
|
typeof DOMPurify !== 'undefined' && DOMPurify.isSupported ?
|
||||||
sanitizeToDOMFragment : null
|
sanitizeToDOMFragment : null,
|
||||||
|
willCutCopy: null
|
||||||
}, config, true );
|
}, config, true );
|
||||||
|
|
||||||
// Users may specify block tag in lower case
|
// 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
|
// 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
|
// 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.
|
// 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 body = node.ownerDocument.body;
|
||||||
|
var willCutCopy = config.willCutCopy;
|
||||||
var html, text;
|
var html, text;
|
||||||
|
|
||||||
// Firefox will add an extra new line for BRs at the end of block when
|
// 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;
|
html = node.innerHTML;
|
||||||
text = node.innerText || node.textContent;
|
text = node.innerText || node.textContent;
|
||||||
|
|
||||||
|
if ( willCutCopy ) {
|
||||||
|
html = willCutCopy( html );
|
||||||
|
}
|
||||||
|
|
||||||
// Firefox (and others?) returns unix line endings (\n) even on Windows.
|
// Firefox (and others?) returns unix line endings (\n) even on Windows.
|
||||||
// If on Windows, normalise to \r\n, since Notepad and some other crappy
|
// If on Windows, normalise to \r\n, since Notepad and some other crappy
|
||||||
// apps do not understand just \n.
|
// apps do not understand just \n.
|
||||||
|
@ -72,7 +77,7 @@ var onCut = function ( event ) {
|
||||||
// Set clipboard data
|
// Set clipboard data
|
||||||
node = this.createElement( 'div' );
|
node = this.createElement( 'div' );
|
||||||
node.appendChild( contents );
|
node.appendChild( contents );
|
||||||
setClipboardData( clipboardData, node, root );
|
setClipboardData( clipboardData, node, root, this._config );
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
} else {
|
} else {
|
||||||
setTimeout( function () {
|
setTimeout( function () {
|
||||||
|
@ -124,7 +129,7 @@ var onCopy = function ( event ) {
|
||||||
// Set clipboard data
|
// Set clipboard data
|
||||||
node = this.createElement( 'div' );
|
node = this.createElement( 'div' );
|
||||||
node.appendChild( contents );
|
node.appendChild( contents );
|
||||||
setClipboardData( clipboardData, node, root );
|
setClipboardData( clipboardData, node, root, this._config );
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -186,8 +186,8 @@ proto.setConfig = function ( config ) {
|
||||||
isSetHTMLSanitized: true,
|
isSetHTMLSanitized: true,
|
||||||
sanitizeToDOMFragment:
|
sanitizeToDOMFragment:
|
||||||
typeof DOMPurify !== 'undefined' && DOMPurify.isSupported ?
|
typeof DOMPurify !== 'undefined' && DOMPurify.isSupported ?
|
||||||
sanitizeToDOMFragment : null
|
sanitizeToDOMFragment : null,
|
||||||
|
willCutCopy: null
|
||||||
}, config, true );
|
}, config, true );
|
||||||
|
|
||||||
// Users may specify block tag in lower case
|
// Users may specify block tag in lower case
|
||||||
|
|
Loading…
Add table
Reference in a new issue