From 67ff09cf3310b2dbc750d32e476c96ef0373d036 Mon Sep 17 00:00:00 2001 From: Ella Iseulde Van Dorpe Date: Sun, 18 Oct 2015 11:04:33 +0000 Subject: [PATCH] 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 --- .../js/tinymce/plugins/wpeditimage/plugin.js | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js b/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js index 0366c28544..4a81ca9ef8 100644 --- a/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js @@ -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;