Skip to content

Commit dc88a6c

Browse files
committed
Merge branch 't/9856'
2 parents a0c9b89 + 03d7bcb commit dc88a6c

File tree

7 files changed

+92
-4
lines changed

7 files changed

+92
-4
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CKEditor 4 Changelog
55

66
Fixed Issues:
77

8+
* [#9856](http://dev.ckeditor.com/ticket/9856): Fixed: Cannot use the native context menu together with the [Div Editing Area](http://ckeditor.com/addon/divarea) plugin.
89
* [#13142](http://dev.ckeditor.com/ticket/13142): [Edge] Fixed: CTRL+A, backspace results in an empty div.
910
* [#13599](http://dev.ckeditor.com/ticket/13599): Fixed: Cross-editor D&D of inline widget ends up in error/artifacts.
1011
* [#13640](http://dev.ckeditor.com/ticket/13640): [IE] Fixed: Dropping a widget outside body is not handled correctly.

core/dom/element.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,11 +1846,15 @@ CKEDITOR.dom.element.clearMarkers = function( database, element, removeFromDatab
18461846
* Disables browser's context menu in this element.
18471847
*/
18481848
disableContextMenu: function() {
1849-
this.on( 'contextmenu', function( event ) {
1849+
this.on( 'contextmenu', function( evt ) {
18501850
// Cancel the browser context menu.
1851-
if ( !event.data.getTarget().hasClass( 'cke_enable_context_menu' ) )
1852-
event.data.preventDefault();
1851+
if ( !evt.data.getTarget().getAscendant( enablesContextMenu, true ) )
1852+
evt.data.preventDefault();
18531853
} );
1854+
1855+
function enablesContextMenu( node ) {
1856+
return node.type == CKEDITOR.NODE_ELEMENT && node.hasClass( 'cke_enable_context_menu' );
1857+
}
18541858
},
18551859

18561860
/**

plugins/divarea/plugin.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ CKEDITOR.plugins.add( 'divarea', {
1414
// Do that in the afterInit function, so it'll eventually overwrite
1515
// the mode defined by the wysiwygarea plugin.
1616
editor.addMode( 'wysiwyg', function( callback ) {
17-
var editingBlock = CKEDITOR.dom.element.createFromHtml( '<div class="cke_wysiwyg_div cke_reset" hidefocus="true"></div>' );
17+
var editingBlock = CKEDITOR.dom.element.createFromHtml(
18+
'<div class="cke_wysiwyg_div cke_reset cke_enable_context_menu" hidefocus="true"></div>'
19+
);
1820

1921
var contentSpace = editor.ui.space( 'contents' );
2022
contentSpace.append( editingBlock );

tests/core/dom/element/element.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,9 @@ <h2>e<b>f</b></h2>
167167
</table>
168168

169169
<input id="scrolled" style="position: absolute; top: 3000px; left: 3500px" value="You must scroll to reach me." />
170+
171+
<div id="disableContextMenu">
172+
<p class="cke_enable_context_menu" id="disableContextMenu_1"><b id="disableContextMenu_2">foo</b></p>
173+
<p><b id="disableContextMenu_3">foo</b></p>
174+
</div>
170175
</body>

tests/core/dom/element/element.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,54 @@ bender.test( appendDomObjectTests(
10341034

10351035
el.forEach( recorder.fn, CKEDITOR.NODE_ELEMENT, true );
10361036
assert.areSame( 'p,i,div,h1,h2,b', recorder.tokens.join( ',' ) );
1037+
},
1038+
1039+
'test disableContextMenu - element with cke_enable_context_menu class': function() {
1040+
var target = doc.getById( 'disableContextMenu_1' ),
1041+
preventDefaultCalled = 0;
1042+
1043+
target.disableContextMenu();
1044+
1045+
target.fire( 'contextmenu', new CKEDITOR.dom.event( {
1046+
target: target.$,
1047+
preventDefault: function() {
1048+
++preventDefaultCalled;
1049+
}
1050+
} ) );
1051+
1052+
assert.areSame( 0, preventDefaultCalled, 'preventDefault was not called' );
1053+
},
1054+
1055+
'test disableContextMenu - ancestor with cke_enable_context_menu class': function() {
1056+
var target = doc.getById( 'disableContextMenu_2' ),
1057+
preventDefaultCalled = 0;
1058+
1059+
target.disableContextMenu();
1060+
1061+
target.fire( 'contextmenu', new CKEDITOR.dom.event( {
1062+
target: target.$,
1063+
preventDefault: function() {
1064+
++preventDefaultCalled;
1065+
}
1066+
} ) );
1067+
1068+
assert.areSame( 0, preventDefaultCalled, 'preventDefault was not called' );
1069+
},
1070+
1071+
'test disableContextMenu': function() {
1072+
var target = doc.getById( 'disableContextMenu_3' ),
1073+
preventDefaultCalled = 0;
1074+
1075+
target.disableContextMenu();
1076+
1077+
target.fire( 'contextmenu', new CKEDITOR.dom.event( {
1078+
target: target.$,
1079+
preventDefault: function() {
1080+
++preventDefaultCalled;
1081+
}
1082+
} ) );
1083+
1084+
assert.areSame( 1, preventDefaultCalled, 'preventDefault was called' );
10371085
}
10381086
}
10391087
) );
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<body>
2+
<h1>Native context menu</h1>
3+
<div id="editor1"><p>Foo</p><p>Foo</p><p>Foo</p><p>Foo</p><p>Foo</p></div>
4+
<h1>Custom context menu</h1>
5+
<div id="editor2"><p>Foo</p><p>Foo</p><p>Foo</p><p>Foo</p><p>Foo</p></div>
6+
7+
<script>
8+
CKEDITOR.replace( 'editor1', {
9+
// Without this the ctx menu plugin will be loaded when testing a build.
10+
removePlugins: 'contextmenu,tabletools,liststyle'
11+
} );
12+
CKEDITOR.replace( 'editor2', {
13+
extraPlugins: 'contextmenu'
14+
} );
15+
</script>
16+
</body>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@bender-ui: collapsed
2+
@bender-tags: 4.5.4, tc
3+
@bender-ckeditor-plugins: wysiwygarea, toolbar, undo, basicstyles, divarea, clipboard
4+
5+
Test whether right-click opens correct context menu in the two editors.
6+
7+
Note:
8+
9+
* Right clicking within the editor should bring:
10+
* native context menu in the first editor,
11+
* custom context menu in the second editor.
12+
* Right clicking on the editor chrome should not bring any context menu.

0 commit comments

Comments
 (0)