Make WordPress Core

Ticket #46085: 46085.1.diff

File 46085.1.diff, 3.0 KB (added by azaozz, 6 years ago)
  • src/js/_enqueues/vendor/tinymce/plugins/wpeditimage/plugin.js

     
    347347                return serializer.serialize( editor.parser.parse( caption, { forced_root_block: false } ) );
    348348        }
    349349
    350         function updateImage( imageNode, imageData ) {
    351                 var classes, className, node, html, parent, wrap, linkNode,
     350        function updateImage( $imageNode, imageData ) {
     351                var classes, className, node, html, parent, wrap, linkNode, imageNode,
    352352                        captionNode, dd, dl, id, attrs, linkAttrs, width, height, align,
    353353                        $imageNode, srcset, src,
    354354                        dom = editor.dom;
    355355
     356                if ( ! $imageNode.length ) {
     357                        return;
     358                }
     359
     360                imageNode = $imageNode[0];
    356361                classes = tinymce.explode( imageData.extraClasses, ' ' );
    357362
    358363                if ( ! classes ) {
     
    389394                dom.setAttribs( imageNode, attrs );
    390395
    391396                // Preserve empty alt attributes.
    392                 editor.$( imageNode ).attr( 'alt', imageData.alt || '' );
     397                $imageNode.attr( 'alt', imageData.alt || '' );
    393398
    394399                linkAttrs = {
    395400                        href: imageData.linkUrl,
     
    513518        }
    514519
    515520        function editImage( img ) {
    516                 var frame, callback, metadata;
     521                var frame, callback, metadata, imageNode;
    517522
    518523                if ( typeof wp === 'undefined' || ! wp.media ) {
    519524                        editor.execCommand( 'mceImage' );
     
    522527
    523528                metadata = extractImageData( img );
    524529
     530                // Mark the image node so we can select it later.
     531                editor.$( img ).attr( 'data-wp-editing', 1 );
     532
    525533                // Manipulate the metadata by reference that is fed into the PostImage model used in the media modal
    526534                wp.media.events.trigger( 'editor:image-edit', {
    527535                        editor: editor,
     
    538546                wp.media.events.trigger( 'editor:frame-create', { frame: frame } );
    539547
    540548                callback = function( imageData ) {
    541                         editor.focus();
    542549                        editor.undoManager.transact( function() {
    543                                 updateImage( img, imageData );
     550                                updateImage( imageNode, imageData );
    544551                        } );
    545552                        frame.detach();
    546553                };
     
    550557                frame.on( 'close', function() {
    551558                        editor.focus();
    552559                        frame.detach();
     560
     561                        // `close` fires first...
     562                        // To be able to update the image node, we need to find it here,
     563                        // and use it in the callback.
     564                        imageNode = editor.$( 'img[data-wp-editing]' )
     565                        imageNode.removeAttr( 'data-wp-editing' );
    553566                });
    554567
    555568                frame.open();
     
    810823
    811824        editor.on( 'beforeGetContent', function( event ) {
    812825                if ( event.format !== 'raw' ) {
    813                         editor.$( 'img[id="__wp-temp-img-id"]' ).attr( 'id', null );
     826                        editor.$( 'img[id="__wp-temp-img-id"]' ).removeAttr( 'id' );
    814827                }
    815828        });
    816829
  • src/wp-includes/css/editor.css

     
    12111211        content: "\f104";
    12121212}
    12131213
     1214.mce-content-body dl.wp-caption {
     1215        max-width: 100%;
     1216}
     1217
    12141218/* Quicktags */
    12151219.quicktags-toolbar {
    12161220        padding: 3px;