From 017daba3d80661105658b8e108449687b1ef52fd Mon Sep 17 00:00:00 2001 From: Ella Iseulde Van Dorpe Date: Thu, 15 Oct 2015 15:19:04 +0000 Subject: [PATCH] TinyMCE: make captioned images draggable See #28003. git-svn-id: https://develop.svn.wordpress.org/trunk@35199 602fd350-edb4-49c9-b593-d223f7449a82 --- .../js/tinymce/plugins/wpeditimage/plugin.js | 39 ++++++++++++++----- 1 file changed, 30 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 11f8a7954c..0366c28544 100644 --- a/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js @@ -782,15 +782,6 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) { } }); - dom.bind( editor.getDoc(), 'dragstart', function( event ) { - var node = editor.selection.getNode(); - - // Prevent dragging images out of the caption elements - if ( node.nodeName === 'IMG' && dom.getParent( node, '.wp-caption' ) ) { - event.preventDefault(); - } - }); - // Prevent IE11 from making dl.wp-caption resizable if ( tinymce.Env.ie && tinymce.Env.ie > 10 ) { // The 'mscontrolselect' event is supported only in IE11+ @@ -964,6 +955,36 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) { } }); + ( function() { + var wrap; + + editor.on( 'dragstart', function() { + var node = editor.selection.getNode(); + + if ( node.nodeName === 'IMG' ) { + wrap = editor.dom.getParent( node, '.mceTemp' ); + } + } ); + + editor.on( 'drop', function( event ) { + var rng; + + if ( wrap && ( rng = tinymce.dom.RangeUtils.getCaretRangeFromPoint( event.clientX, event.clientY, editor.getDoc() ) ) ) { + 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 ); + } ); + } + } + + wrap = null; + } ); + } )(); + // Add to editor.wp editor.wp = editor.wp || {}; editor.wp.isPlaceholder = isPlaceholder;