Skip to content

Commit 7bf898b

Browse files
FlowIT-JITComandeer
authored andcommitted
Allow built-in image paste handling to be disabled (ckeditor#4874).
This will allow 3rd party plugins to handle images being pasted.
1 parent b14851c commit 7bf898b

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

plugins/clipboard/plugin.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
// Convert image file (if present) to base64 string for modern browsers except IE<10, as it does not support
150150
// custom MIME types in clipboard (#4612).
151151
// Do it as the first step as the conversion is asynchronous and should hold all further paste processing.
152-
if ( CKEDITOR.plugins.clipboard.isCustomDataTypesSupported || CKEDITOR.plugins.clipboard.isFileApiSupported ) {
152+
if ( ( CKEDITOR.plugins.clipboard.isCustomDataTypesSupported || CKEDITOR.plugins.clipboard.isFileApiSupported ) && editor.config.clipboard_handleImagePasting !== false ) {
153153
var supportedImageTypes = [ 'image/png', 'image/jpeg', 'image/gif' ],
154154
unsupportedTypeMsg = createNotificationMessage( supportedImageTypes ),
155155
latestId;
@@ -3471,3 +3471,13 @@
34713471
* @member CKEDITOR.config
34723472
*/
34733473
CKEDITOR.config.clipboard_notificationDuration = 10000;
3474+
3475+
/**
3476+
* Whether to use clipboard plugin to handle image pasting, turning
3477+
* images into base64 strings on browsers supporting the File API.
3478+
*
3479+
* @since 4.7.0
3480+
* @cfg {Number} [clipboard_handleImagePasting=true]
3481+
* @member CKEDITOR.config
3482+
*/
3483+
CKEDITOR.config.clipboard_handleImagePasting = true;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<div id="editor">
2+
<p>Paste image here</p>
3+
<p></p>
4+
</div>
5+
6+
<br><br>
7+
8+
<button id="button"> Disable built-in image paste handling </button>
9+
10+
<br><br>
11+
12+
<div id="log">Log output:</div>
13+
14+
<script>
15+
( function() {
16+
if ( !window.FileReader ) {
17+
return bender.ignore();
18+
}
19+
20+
CKEDITOR.plugins.add( 'customImagePasteHandlerPlugin', {
21+
init: function( editor ) {
22+
editor.on( 'paste', function( event ) {
23+
var log = document.querySelector( '#log' );
24+
var msg = '<br>Custom image paste handling: image data received';
25+
log.innerHTML += msg;
26+
} );
27+
}
28+
} );
29+
30+
CKEDITOR.replace( 'editor' );
31+
32+
var button = document.querySelector( '#button' );
33+
button.onclick = function() {
34+
CKEDITOR.instances.editor.destroy();
35+
CKEDITOR.replace( 'editor', {
36+
// Allow 3rd party plugins to handle image pasting
37+
clipboard_handleImagePasting: false,
38+
extraPlugins: "customImagePasteHandlerPlugin"
39+
} );
40+
}
41+
} )();
42+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@bender-ui: collapsed
2+
@bender-tags: 4.17.0, clipboard, 4874
3+
@bender-ckeditor-plugins: wysiwygarea, toolbar, undo, basicstyles, image, clipboard, sourcearea
4+
5+
1. Paste an image into the editor.
6+
7+
Observe that the image is inserted and that no "Custom image paste handling" entry is written to "log output" on the page.
8+
9+
2. Click the "Disable built-in image paste handling" button.
10+
11+
3. Paste an image into the editor.
12+
13+
Observe that the image is not inserted, and that "log output" now shows "Custom image paste handling: image data received".
14+
15+
**Expected** No image is inserted in step 3 but instead produces log output as described.
16+
17+
**Unexpected** Image pasting is not suppressed in step 3 and/or no log output is produced.

0 commit comments

Comments
 (0)