Ticket #46085: 46085.diff
File 46085.diff, 3.3 KB (added by , 6 years ago) |
---|
-
src/js/_enqueues/vendor/tinymce/plugins/wpeditimage/plugin.js
347 347 return serializer.serialize( editor.parser.parse( caption, { forced_root_block: false } ) ); 348 348 } 349 349 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, 352 352 captionNode, dd, dl, id, attrs, linkAttrs, width, height, align, 353 353 $imageNode, srcset, src, 354 354 dom = editor.dom; 355 355 356 if ( ! $imageNode.length ) { 357 return; 358 } 359 360 imageNode = $imageNode[0]; 356 361 classes = tinymce.explode( imageData.extraClasses, ' ' ); 357 362 358 363 if ( ! classes ) { … … 373 378 width = imageData.width; 374 379 height = imageData.height; 375 380 381 if ( editor.settings.classic_block_editor ) { 382 // The width coming from the media modal is wrong. 383 // It is the "old" `$content_width` from the theme. 384 var editorBody = editor.getBody(); 385 var maxWidth = editorBody.clientWidth; 386 387 if ( width && maxWidth && width > maxWidth ) { 388 if ( height ) { 389 var ratio = maxWidth / width; 390 height = parseInt( height * ratio, 10 ); 391 } 392 393 width = maxWidth; 394 } 395 } 396 376 397 if ( imageData.size === 'custom' ) { 377 398 width = imageData.customWidth; 378 399 height = imageData.customHeight; … … 389 410 dom.setAttribs( imageNode, attrs ); 390 411 391 412 // Preserve empty alt attributes. 392 editor.$( imageNode ).attr( 'alt', imageData.alt || '' );413 $imageNode.attr( 'alt', imageData.alt || '' ); 393 414 394 415 linkAttrs = { 395 416 href: imageData.linkUrl, … … 513 534 } 514 535 515 536 function editImage( img ) { 516 var frame, callback, metadata ;537 var frame, callback, metadata, imageNode; 517 538 518 539 if ( typeof wp === 'undefined' || ! wp.media ) { 519 540 editor.execCommand( 'mceImage' ); … … 522 543 523 544 metadata = extractImageData( img ); 524 545 546 // Mark the image node so we can select it later. 547 editor.$( img ).attr( 'data-wp-editing', 1 ); 548 525 549 // Manipulate the metadata by reference that is fed into the PostImage model used in the media modal 526 550 wp.media.events.trigger( 'editor:image-edit', { 527 551 editor: editor, … … 538 562 wp.media.events.trigger( 'editor:frame-create', { frame: frame } ); 539 563 540 564 callback = function( imageData ) { 541 editor.focus();542 565 editor.undoManager.transact( function() { 543 updateImage( im g, imageData );566 updateImage( imageNode, imageData ); 544 567 } ); 545 568 frame.detach(); 546 569 }; … … 550 573 frame.on( 'close', function() { 551 574 editor.focus(); 552 575 frame.detach(); 576 577 // `close` fires first... 578 // To be able to update the image node, we need to select it here first, 579 // and pass it to the callback. 580 imageNode = editor.$( 'img[data-wp-editing]' ) 581 imageNode.removeAttr( 'data-wp-editing' ); 553 582 }); 554 583 555 584 frame.open(); … … 810 839 811 840 editor.on( 'beforeGetContent', function( event ) { 812 841 if ( event.format !== 'raw' ) { 813 editor.$( 'img[id="__wp-temp-img-id"]' ). attr( 'id', null);842 editor.$( 'img[id="__wp-temp-img-id"]' ).removeAttr( 'id' ); 814 843 } 815 844 }); 816 845