Skip to content

Commit

Permalink
Merge branch 't/9856'
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Sep 2, 2015
2 parents a0c9b89 + 03d7bcb commit dc88a6c
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -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.
Expand Down
10 changes: 7 additions & 3 deletions core/dom/element.js
Expand Up @@ -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' );
}
},

/**
Expand Down
4 changes: 3 additions & 1 deletion plugins/divarea/plugin.js
Expand Up @@ -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( '<div class="cke_wysiwyg_div cke_reset" hidefocus="true"></div>' );
var editingBlock = CKEDITOR.dom.element.createFromHtml(
'<div class="cke_wysiwyg_div cke_reset cke_enable_context_menu" hidefocus="true"></div>'
);

var contentSpace = editor.ui.space( 'contents' );
contentSpace.append( editingBlock );
Expand Down
5 changes: 5 additions & 0 deletions tests/core/dom/element/element.html
Expand Up @@ -167,4 +167,9 @@ <h2>e<b>f</b></h2>
</table>

<input id="scrolled" style="position: absolute; top: 3000px; left: 3500px" value="You must scroll to reach me." />

<div id="disableContextMenu">
<p class="cke_enable_context_menu" id="disableContextMenu_1"><b id="disableContextMenu_2">foo</b></p>
<p><b id="disableContextMenu_3">foo</b></p>
</div>
</body>
48 changes: 48 additions & 0 deletions tests/core/dom/element/element.js
Expand Up @@ -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' );
}
}
) );
16 changes: 16 additions & 0 deletions tests/plugins/divarea/manual/contextmenu.html
@@ -0,0 +1,16 @@
<body>
<h1>Native context menu</h1>
<div id="editor1"><p>Foo</p><p>Foo</p><p>Foo</p><p>Foo</p><p>Foo</p></div>
<h1>Custom context menu</h1>
<div id="editor2"><p>Foo</p><p>Foo</p><p>Foo</p><p>Foo</p><p>Foo</p></div>

<script>
CKEDITOR.replace( 'editor1', {
// Without this the ctx menu plugin will be loaded when testing a build.
removePlugins: 'contextmenu,tabletools,liststyle'
} );
CKEDITOR.replace( 'editor2', {
extraPlugins: 'contextmenu'
} );
</script>
</body>
12 changes: 12 additions & 0 deletions 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.

0 comments on commit dc88a6c

Please sign in to comment.