From a08e89ed97b27fdb3709a394c7ad6d6d53d28846 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Tue, 26 Jul 2016 21:50:51 +0000 Subject: [PATCH] TinyMCE: fix selecting an image on touch in iOS Safari for TinyMCE 4.4.1. Fixes #37427. git-svn-id: https://develop.svn.wordpress.org/trunk@38156 602fd350-edb4-49c9-b593-d223f7449a82 --- .../js/tinymce/plugins/wpeditimage/plugin.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js b/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js index 50045e7950..890da1c2c8 100644 --- a/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js @@ -79,24 +79,27 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) { } } ); + function isNonEditable( node ) { + var parent = editor.$( node ).parents( '[contenteditable]' ); + return parent && parent.attr( 'contenteditable' ) === 'false'; + } + // Safari on iOS fails to select images in contentEditoble mode on touch. // Select them again. if ( iOS ) { editor.on( 'init', function() { editor.on( 'touchstart', function( event ) { - if ( event.target.nodeName === 'IMG' ) { + if ( event.target.nodeName === 'IMG' && ! isNonEditable( event.target ) ) { touchOnImage = true; } }); - editor.dom.bind( editor.getDoc(), 'touchmove', function( event ) { - if ( event.target.nodeName === 'IMG' ) { - touchOnImage = false; - } + editor.dom.bind( editor.getDoc(), 'touchmove', function() { + touchOnImage = false; }); editor.on( 'touchend', function( event ) { - if ( touchOnImage && event.target.nodeName === 'IMG' ) { + if ( touchOnImage && event.target.nodeName === 'IMG' && ! isNonEditable( event.target ) ) { var node = event.target; touchOnImage = false; @@ -104,7 +107,7 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) { window.setTimeout( function() { editor.selection.select( node ); editor.nodeChanged(); - }, 200 ); + }, 100 ); } else if ( toolbar ) { toolbar.hide(); }