Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/js/_enqueues/vendor/tinymce/plugins/wpeditimage/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,20 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) {
width = c.match( /width="([0-9]*)"/ );
width = ( width && width[1] ) ? width[1] : '';

if ( ! width ) {
width = b.match( /style="[^"]*width:\s*([0-9]+)px/ );

if ( width && width[1] ) {
width = parseInt( width[1], 10 );

if ( ! editor.getParam( 'wpeditimage_html5_captions' ) ) {
width -= 10;
}

width = width > 0 ? width : '';
}
}

classes = b.match( /class="([^"]*)"/ );
classes = ( classes && classes[1] ) ? classes[1] : '';
align = classes.match( /align[a-z]+/i ) || 'alignnone';
Expand Down
3 changes: 3 additions & 0 deletions tests/qunit/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2297,9 +2297,12 @@ <h2>Preview</h2>

</div><!-- end widget templates -->
<script src="../../build/wp-includes/js/tinymce/tinymce.min.js"></script>
<script src="../../build/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js"></script>
<script src="wp-includes/js/tinymce/plugins/wpeditimage/plugin.js"></script>
<script src="../../build/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js"></script>
<script src="wp-includes/js/tinymce/plugins/wptextpattern/plugin.js"></script>
<script src="wp-includes/js/tinymce/tinymce-obsolete.js"></script>
<script src="wp-admin/js/test-wpeditimage.js"></script>

<!-- Changeset locked notice template -->
<script type="text/html" id="tmpl-customize-changeset-locked-notice">
Expand Down
30 changes: 30 additions & 0 deletions tests/qunit/wp-admin/js/test-wpeditimage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* global tinymce */

QUnit.test( 'Caption is preserved when the image width attribute is missing', function( assert ) {
var done = assert.async();
var textarea = document.createElement( 'textarea' );
var shortcode = '[caption id="attachment_12345" align="alignnone" width="150"]<img class="wp-image-12345 size-thumbnail" src="https://example.org/image.png" alt="" height="150" /> My caption[/caption]';

document.body.appendChild( textarea );

tinymce.init( {
target: textarea,
plugins: 'wpeditimage',
menubar: false,
toolbar: false,
setup: function( editor ) {
editor.on( 'init', function() {
var content = editor.wpSetImgCaption( shortcode );
var output = editor.wpGetImgCaption( content );

assert.ok( output.indexOf( '[caption' ) !== -1, 'The caption shortcode is retained.' );
assert.ok( output.indexOf( 'width="150"' ) !== -1, 'The caption width is retained.' );
assert.ok( output.indexOf( 'My caption[/caption]' ) !== -1, 'The caption text is retained.' );

editor.remove();
textarea.remove();
done();
} );
}
} );
} );
Loading