TinyMCE: Drag and drop link with image

Make sure images don't loose their link after drag and drop.

Fixes #28272.


git-svn-id: https://develop.svn.wordpress.org/trunk@35261 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ella Iseulde Van Dorpe 2015-10-18 11:04:33 +00:00
parent 39c6a77617
commit 67ff09cf33
1 changed files with 15 additions and 9 deletions

View File

@ -963,22 +963,28 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) {
if ( node.nodeName === 'IMG' ) {
wrap = editor.dom.getParent( node, '.mceTemp' );
if ( ! wrap && node.parentNode.nodeName === 'A' && ! hasTextContent( node.parentNode ) ) {
wrap = node.parentNode;
}
}
} );
editor.on( 'drop', function( event ) {
var rng;
var dom = editor.dom,
rng = tinymce.dom.RangeUtils.getCaretRangeFromPoint( event.clientX, event.clientY, editor.getDoc() );
if ( wrap && ( rng = tinymce.dom.RangeUtils.getCaretRangeFromPoint( event.clientX, event.clientY, editor.getDoc() ) ) ) {
// Don't allow anything to be dropped in a captioned image.
if ( dom.getParent( rng.startContainer, '.mceTemp' ) ) {
event.preventDefault();
} else if ( wrap ) {
event.preventDefault();
if ( ! editor.dom.getParent( rng.startContainer, '.mceTemp' ) ) {
editor.undoManager.transact( function() {
editor.selection.setRng( rng );
editor.selection.setNode( wrap );
editor.dom.remove( wrap );
} );
}
editor.undoManager.transact( function() {
editor.selection.setRng( rng );
editor.selection.setNode( wrap );
dom.remove( wrap );
} );
}
wrap = null;