Skip to content

Commit 0f7494b

Browse files
committed
Merge branch 't/13879'
2 parents 0f9d081 + a27c239 commit 0f7494b

File tree

5 files changed

+97
-19
lines changed

5 files changed

+97
-19
lines changed

CHANGES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CKEditor 4 Changelog
1+
CKEditor 4 Changelog
22
====================
33

44
## CKEditor 4.5.5
@@ -12,6 +12,7 @@ Fixed Issues:
1212
* [#13887](https://dev.ckeditor.com/ticket/13887): Fixed: Link target now supports wider ASCII character range. Thanks to [SamZiemer](https://github.com/SamZiemer)!
1313
* [#13790](https://dev.ckeditor.com/ticket/13790): Fixed: Allow for the iframe having been removed already. Thanks to [Stefan Rijnhart](https://github.com/StefanRijnhart)!
1414
* [#13803](https://dev.ckeditor.com/ticket/13803): Fixed: Allow the editor to be destroyed before being fully initialized. Thanks to [Cyril Fluck](https://github.com/cyril-sf)!
15+
* [#13879](http://dev.ckeditor.com/ticket/13879): Fixed: Preventing [`editor.drop`](http://docs.ckeditor.com/#!/api/CKEDITOR.editor-event-drop) event.
1516
* [#12848](http://dev.ckeditor.com/ticket/12848): Fixed: Opening find dialog in [read-only](http://docs.ckeditor.com/#!/api/CKEDITOR.editor-property-readOnly) mode will no longer throw an exception.
1617
* [#12189](http://dev.ckeditor.com/ticket/12189): Fixed: Link plugin dialog does not display subject of email links if subject parameter is not lowercase.
1718
* [#13361](http://dev.ckeditor.com/ticket/13361): Fixed: Images fail when site path includes parentheses because background-image path needs single-quotes around URL value.

plugins/clipboard/plugin.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/**
22
* @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
33
* For licensing, see LICENSE.md or http://ckeditor.com/license
44
*/
@@ -1340,6 +1340,11 @@
13401340
// -------------- DROP --------------
13411341

13421342
editable.attachListener( dropTarget, 'drop', function( evt ) {
1343+
// Do nothing if event was already prevented. (#13879)
1344+
if ( evt.data.$.defaultPrevented ) {
1345+
return;
1346+
}
1347+
13431348
// Cancel native drop.
13441349
evt.data.preventDefault();
13451350

@@ -1364,7 +1369,7 @@
13641369

13651370
// Fire drop.
13661371
fireDragEvent( evt, dragRange, dropRange );
1367-
} );
1372+
}, null, null, 9999 );
13681373

13691374
// Create dataTransfer or get it, if it was created before.
13701375
editable.attachListener( editor, 'drop', clipboard.initDragDataTransfer, clipboard, null, 1 );

tests/plugins/clipboard/drop.js

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,26 @@ function drop( editor, evt, config, onDrop, onFinish ) {
9090

9191
finishListener = function() {
9292
resume( function() {
93-
// Drop event asserts
94-
assert.areSame( 1, values.dropEventCounter, 'There should be always one drop.' );
95-
assert.isTrue( values.dropInstanceOfDataTransfer, 'On drop: dropEvt.data.dataTransfer should be instance of dataTransfer.' );
96-
if ( config.expectedText && isCustomDataTypesSupported ) {
97-
assert.areSame( config.expectedText, values.dropDataText, 'On drop: text data should match.' );
98-
}
99-
if ( config.expectedHtml ) {
100-
// isInnerHtmlMatching remove space from the end of strings we compare, adding 'x' fix this problem.
101-
assert.isInnerHtmlMatching( 'x' + config.expectedHtml + 'x', 'x' + values.dropDataHtml + 'x', 'On drop: HTML data should match.' );
102-
}
103-
assert.isTrue( values.dropRangeStartContainerMatch, 'On drop: drop range start container should match.' );
104-
assert.isTrue( values.dropRangeStartContainerMatch, 'On drop: drop range start offset should match.' );
93+
if ( !config.expectedDropPrevented ) {
94+
// Drop event asserts
95+
assert.areSame( 1, values.dropEventCounter, 'There should be always one drop.' );
96+
97+
assert.isTrue( values.dropInstanceOfDataTransfer, 'On drop: dropEvt.data.dataTransfer should be instance of dataTransfer.' );
98+
if ( config.expectedText && isCustomDataTypesSupported ) {
99+
assert.areSame( config.expectedText, values.dropDataText, 'On drop: text data should match.' );
100+
}
101+
if ( config.expectedHtml ) {
102+
// isInnerHtmlMatching remove space from the end of strings we compare, adding 'x' fix this problem.
103+
assert.isInnerHtmlMatching( 'x' + config.expectedHtml + 'x', 'x' + values.dropDataHtml + 'x', 'On drop: HTML data should match.' );
104+
}
105+
assert.isTrue( values.dropRangeStartContainerMatch, 'On drop: drop range start container should match.' );
106+
assert.isTrue( values.dropRangeStartContainerMatch, 'On drop: drop range start offset should match.' );
105107

106-
assert.isTrue( values.dropNativeEventMatch, 'On drop: native event should match.' );
107-
// Check that it's the mocked drop target created by the mockDropEvent().
108-
assert.areSame( CKEDITOR.NODE_TEXT, values.dropTarget.type, 'On drop: drop target node type should match.' );
109-
assert.areSame( 'targetMock', values.dropTarget.getText(), 'On drop: drop target should match.' );
108+
assert.isTrue( values.dropNativeEventMatch, 'On drop: native event should match.' );
109+
// Check that it's the mocked drop target created by the mockDropEvent().
110+
assert.areSame( CKEDITOR.NODE_TEXT, values.dropTarget.type, 'On drop: drop target node type should match.' );
111+
assert.areSame( 'targetMock', values.dropTarget.getText(), 'On drop: drop target should match.' );
112+
}
110113

111114
// Paste event asserts
112115
assert.areSame( expectedBeforePasteEventCount, values.beforePasteEventCounter, 'Before paste event should be called ' + expectedBeforePasteEventCount + ' time(s).' );
@@ -630,6 +633,30 @@ var testsForMultipleEditor = {
630633
}, function() {
631634
assert.areSame( '<p class="p">^foo</p>', bender.tools.getHtmlWithSelection( editor ), 'after drop' );
632635
} );
636+
},
637+
638+
// #13879
639+
'test prevent drop': function( editor, bot ) {
640+
var evt = bender.tools.mockDropEvent();
641+
642+
// Simulate calling evt.data.preventDefault.
643+
evt.$.defaultPrevented = true;
644+
645+
bot.setHtmlWithSelection( '<p class="p">^foo</p>' );
646+
editor.resetUndo();
647+
648+
drag( editor, evt );
649+
650+
drop( editor, evt, {
651+
dropContainer: editor.editable().findOne( '.p' ).getChild( 0 ),
652+
dropOffset: 0,
653+
expectedPasteEventCount: 0,
654+
expectedDropPrevented: true
655+
}, function() {
656+
return true;
657+
}, function() {
658+
assert.areSame( '<p class="p">^foo</p>', bender.tools.getHtmlWithSelection( editor ), 'after drop' );
659+
} );
633660
}
634661
},
635662
testsForOneEditor = {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<head>
2+
<style type="text/css">
3+
h2 {
4+
margin: 10px 0px 4px 0px;
5+
padding: 0;
6+
font-size: 14px;
7+
}
8+
</style>
9+
</head>
10+
<div>
11+
<h2>Helpers</h2>
12+
<div id="helpers">
13+
<textarea style="width:49%; height:50px; float: left;">Lorem ipsum dolor sit amet, consectetur adipiscing elit. In commodo vulputate tempor. Sed <b>at</b> elit.</textarea>
14+
<div style="width:49%; height:50px; float: right;">
15+
<img height="40" alt="CKEditor logo" src="%BASE_PATH%_assets/logo.png" />
16+
</div>
17+
<div style="clear:both;"></div>
18+
</div>
19+
</div>
20+
<div>
21+
<h2>Editor</h2>
22+
<div id="editor">
23+
<p>I'm working!</p>
24+
</div>
25+
</div>
26+
<script>
27+
CKEDITOR.replace( 'editor', {
28+
on: {
29+
instanceReady: function( evt ) {
30+
evt.editor.document.on( 'drop', function( evt ) {
31+
evt.data.preventDefault();
32+
} );
33+
}
34+
}
35+
} );
36+
</script>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@bender-ui: collapsed
2+
@bender-tags: 4.5.5, tc, 13879, clipboard
3+
@bender-ckeditor-plugins: clipboard, wysiwygarea, toolbar, image2
4+
5+
1. Drag and drop text into the editor.
6+
2. Drag and drop image into the editor.
7+
8+
**Expected:**
9+
* Text and image aren't pasted into the editor.

0 commit comments

Comments
 (0)