diff --git a/CHANGES.md b/CHANGES.md index 2f538c59a1e..9be1eb61443 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ CKEditor 4 Changelog Fixed Issues: +* [#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. * [#13142](http://dev.ckeditor.com/ticket/13142): [Edge] Fixed: CTRL+A, backspace results in an empty div. * [#13599](http://dev.ckeditor.com/ticket/13599): Fixed: Cross-editor D&D of inline widget ends up in error/artifacts. * [#13640](http://dev.ckeditor.com/ticket/13640): [IE] Fixed: Dropping a widget outside body is not handled correctly. diff --git a/core/dom/element.js b/core/dom/element.js index 9c4f322640f..696cabaaf93 100644 --- a/core/dom/element.js +++ b/core/dom/element.js @@ -1846,11 +1846,15 @@ CKEDITOR.dom.element.clearMarkers = function( database, element, removeFromDatab * Disables browser's context menu in this element. */ disableContextMenu: function() { - this.on( 'contextmenu', function( event ) { + this.on( 'contextmenu', function( evt ) { // Cancel the browser context menu. - if ( !event.data.getTarget().hasClass( 'cke_enable_context_menu' ) ) - event.data.preventDefault(); + if ( !evt.data.getTarget().getAscendant( enablesContextMenu, true ) ) + evt.data.preventDefault(); } ); + + function enablesContextMenu( node ) { + return node.type == CKEDITOR.NODE_ELEMENT && node.hasClass( 'cke_enable_context_menu' ); + } }, /** diff --git a/plugins/divarea/plugin.js b/plugins/divarea/plugin.js index 430122ca67b..ab237672b24 100644 --- a/plugins/divarea/plugin.js +++ b/plugins/divarea/plugin.js @@ -14,7 +14,9 @@ CKEDITOR.plugins.add( 'divarea', { // Do that in the afterInit function, so it'll eventually overwrite // the mode defined by the wysiwygarea plugin. editor.addMode( 'wysiwyg', function( callback ) { - var editingBlock = CKEDITOR.dom.element.createFromHtml( '
' ); + var editingBlock = CKEDITOR.dom.element.createFromHtml( + '
' + ); var contentSpace = editor.ui.space( 'contents' ); contentSpace.append( editingBlock ); diff --git a/tests/core/dom/element/element.html b/tests/core/dom/element/element.html index e0f419712d9..ffa6e873e5c 100644 --- a/tests/core/dom/element/element.html +++ b/tests/core/dom/element/element.html @@ -167,4 +167,9 @@

ef

+ +
+

foo

+

foo

+
\ No newline at end of file diff --git a/tests/core/dom/element/element.js b/tests/core/dom/element/element.js index c7a9fe30ddb..4172bfda988 100644 --- a/tests/core/dom/element/element.js +++ b/tests/core/dom/element/element.js @@ -1034,6 +1034,54 @@ bender.test( appendDomObjectTests( el.forEach( recorder.fn, CKEDITOR.NODE_ELEMENT, true ); assert.areSame( 'p,i,div,h1,h2,b', recorder.tokens.join( ',' ) ); + }, + + 'test disableContextMenu - element with cke_enable_context_menu class': function() { + var target = doc.getById( 'disableContextMenu_1' ), + preventDefaultCalled = 0; + + target.disableContextMenu(); + + target.fire( 'contextmenu', new CKEDITOR.dom.event( { + target: target.$, + preventDefault: function() { + ++preventDefaultCalled; + } + } ) ); + + assert.areSame( 0, preventDefaultCalled, 'preventDefault was not called' ); + }, + + 'test disableContextMenu - ancestor with cke_enable_context_menu class': function() { + var target = doc.getById( 'disableContextMenu_2' ), + preventDefaultCalled = 0; + + target.disableContextMenu(); + + target.fire( 'contextmenu', new CKEDITOR.dom.event( { + target: target.$, + preventDefault: function() { + ++preventDefaultCalled; + } + } ) ); + + assert.areSame( 0, preventDefaultCalled, 'preventDefault was not called' ); + }, + + 'test disableContextMenu': function() { + var target = doc.getById( 'disableContextMenu_3' ), + preventDefaultCalled = 0; + + target.disableContextMenu(); + + target.fire( 'contextmenu', new CKEDITOR.dom.event( { + target: target.$, + preventDefault: function() { + ++preventDefaultCalled; + } + } ) ); + + assert.areSame( 1, preventDefaultCalled, 'preventDefault was called' ); } } ) ); \ No newline at end of file diff --git a/tests/plugins/divarea/manual/contextmenu.html b/tests/plugins/divarea/manual/contextmenu.html new file mode 100644 index 00000000000..ba524a020e7 --- /dev/null +++ b/tests/plugins/divarea/manual/contextmenu.html @@ -0,0 +1,16 @@ + +

Native context menu

+

Foo

Foo

Foo

Foo

Foo

+

Custom context menu

+

Foo

Foo

Foo

Foo

Foo

+ + + \ No newline at end of file diff --git a/tests/plugins/divarea/manual/contextmenu.md b/tests/plugins/divarea/manual/contextmenu.md new file mode 100644 index 00000000000..52f1a73bd06 --- /dev/null +++ b/tests/plugins/divarea/manual/contextmenu.md @@ -0,0 +1,12 @@ +@bender-ui: collapsed +@bender-tags: 4.5.4, tc +@bender-ckeditor-plugins: wysiwygarea, toolbar, undo, basicstyles, divarea, clipboard + +Test whether right-click opens correct context menu in the two editors. + +Note: + +* Right clicking within the editor should bring: + * native context menu in the first editor, + * custom context menu in the second editor. +* Right clicking on the editor chrome should not bring any context menu. \ No newline at end of file