From 10c893027812a4241ed38db8aaa9a35c183f1065 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Fri, 22 Jan 2016 01:18:30 +0000 Subject: [PATCH] TinyMCE: remove the `srcset` and `sizes` attributes (if any) after replacing or editing an image. See #35434. git-svn-id: https://develop.svn.wordpress.org/trunk@36376 602fd350-edb4-49c9-b593-d223f7449a82 --- .../js/tinymce/plugins/wpeditimage/plugin.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js b/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js index 3d8540fa86..979ddaf496 100644 --- a/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js @@ -353,6 +353,7 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) { function updateImage( imageNode, imageData ) { var classes, className, node, html, parent, wrap, linkNode, captionNode, dd, dl, id, attrs, linkAttrs, width, height, align, + $imageNode, srcset, src, dom = editor.dom; classes = tinymce.explode( imageData.extraClasses, ' ' ); @@ -488,6 +489,19 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) { dom.remove( captionNode ); } + $imageNode = editor.$( imageNode ); + srcset = $imageNode.attr( 'srcset' ); + src = $imageNode.attr( 'src' ); + + // Remove srcset and sizes if the image file was edited or the image was replaced. + if ( srcset && src ) { + src = src.replace( /[?#].*/, '' ); + + if ( srcset.indexOf( src ) === -1 ) { + $imageNode.attr( 'srcset', null ).attr( 'sizes', null ); + } + } + if ( wp.media.events ) { wp.media.events.trigger( 'editor:image-update', { editor: editor,