Make WordPress Core

Changeset 41092 for trunk


Ignore:
Timestamp:
07/19/2017 01:40:31 PM (9 years ago)
Author:
azaozz
Message:

TinyMCE: remove unused code from the wpeditimage plugin.

Fixes #41369.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js

    r40786 r41092  
    588588                dom.addClass( editor.getBody(), captionClass );
    589589
    590                 // Add caption field to the default image dialog
    591                 editor.on( 'wpLoadImageForm', function( event ) {
    592                         if ( editor.getParam( 'wpeditimage_disable_captions' ) ) {
    593                                 return;
    594                         }
    595 
    596                         var captionField = {
    597                                 type: 'textbox',
    598                                 flex: 1,
    599                                 name: 'wpcaption',
    600                                 minHeight: 60,
    601                                 multiline: true,
    602                                 scroll: true,
    603                                 label: 'Image caption'
    604                         };
    605 
    606                         event.data.splice( event.data.length - 1, 0, captionField );
    607                 });
    608 
    609                 // Fix caption parent width for images added from URL
    610                 editor.on( 'wpNewImageRefresh', function( event ) {
    611                         var parent, captionWidth;
    612 
    613                         if ( parent = dom.getParent( event.node, 'dl.wp-caption' ) ) {
    614                                 if ( ! parent.style.width ) {
    615                                         captionWidth = parseInt( event.node.clientWidth, 10 ) + 10;
    616                                         captionWidth = captionWidth ? captionWidth + 'px' : '50%';
    617                                         dom.setStyle( parent, 'width', captionWidth );
    618                                 }
    619                         }
    620                 });
    621 
    622                 editor.on( 'wpImageFormSubmit', function( event ) {
    623                         var data = event.imgData.data,
    624                                 imgNode = event.imgData.node,
    625                                 caption = event.imgData.wpcaption,
    626                                 captionId = '',
    627                                 captionAlign = '',
    628                                 captionWidth = '',
    629                                 imgId = null,
    630                                 wrap, parent, node, html;
    631 
    632                         // Temp image id so we can find the node later
    633                         data.id = '__wp-temp-img-id';
    634                         // Cancel the original callback
    635                         event.imgData.cancel = true;
    636 
    637                         if ( ! data.style ) {
    638                                 data.style = null;
    639                         }
    640 
    641                         if ( ! data.src ) {
    642                                 // Delete the image and the caption
    643                                 if ( imgNode ) {
    644                                         if ( wrap = dom.getParent( imgNode, 'div.mceTemp' ) ) {
    645                                                 dom.remove( wrap );
    646                                         } else if ( imgNode.parentNode.nodeName === 'A' ) {
    647                                                 dom.remove( imgNode.parentNode );
    648                                         } else {
    649                                                 dom.remove( imgNode );
    650                                         }
    651 
    652                                         editor.nodeChanged();
    653                                 }
    654                                 return;
    655                         }
    656 
    657                         if ( caption ) {
    658                                 caption = caption.replace( /\r\n|\r/g, '\n' ).replace( /<\/?[a-zA-Z0-9]+( [^<>]+)?>/g, function( a ) {
    659                                         // No line breaks inside HTML tags
    660                                         return a.replace( /[\r\n\t]+/, ' ' );
    661                                 });
    662 
    663                                 // Convert remaining line breaks to <br>
    664                                 caption = caption.replace( /(<br[^>]*>)\s*\n\s*/g, '$1' ).replace( /\s*\n\s*/g, '<br />' );
    665                                 caption = verifyHTML( caption );
    666                         }
    667 
    668                         if ( ! imgNode ) {
    669                                 // New image inserted
    670                                 html = dom.createHTML( 'img', data );
    671 
    672                                 if ( caption ) {
    673                                         node = editor.selection.getNode();
    674 
    675                                         if ( data.width ) {
    676                                                 captionWidth = parseInt( data.width, 10 );
    677 
    678                                                 if ( ! editor.getParam( 'wpeditimage_html5_captions' ) ) {
    679                                                         captionWidth += 10;
    680                                                 }
    681 
    682                                                 captionWidth = ' style="width: ' + captionWidth + 'px"';
    683                                         }
    684 
    685                                         html = '<dl class="wp-caption alignnone"' + captionWidth + '>' +
    686                                                 '<dt class="wp-caption-dt">'+ html +'</dt><dd class="wp-caption-dd">'+ caption +'</dd></dl>';
    687 
    688                                         if ( node.nodeName === 'P' ) {
    689                                                 parent = node;
    690                                         } else {
    691                                                 parent = dom.getParent( node, 'p' );
    692                                         }
    693 
    694                                         if ( parent && parent.nodeName === 'P' ) {
    695                                                 wrap = dom.create( 'div', { 'class': 'mceTemp' }, html );
    696                                                 parent.parentNode.insertBefore( wrap, parent );
    697                                                 editor.selection.select( wrap );
    698                                                 editor.nodeChanged();
    699 
    700                                                 if ( dom.isEmpty( parent ) ) {
    701                                                         dom.remove( parent );
    702                                                 }
    703                                         } else {
    704                                                 editor.selection.setContent( '<div class="mceTemp">' + html + '</div>' );
    705                                         }
    706                                 } else {
    707                                         editor.selection.setContent( html );
    708                                 }
    709                         } else {
    710                                 // Edit existing image
    711 
    712                                 // Store the original image id if any
    713                                 imgId = imgNode.id || null;
    714                                 // Update the image node
    715                                 dom.setAttribs( imgNode, data );
    716                                 wrap = dom.getParent( imgNode, 'dl.wp-caption' );
    717 
    718                                 if ( caption ) {
    719                                         if ( wrap ) {
    720                                                 if ( parent = dom.select( 'dd.wp-caption-dd', wrap )[0] ) {
    721                                                         parent.innerHTML = caption;
    722                                                 }
    723                                         } else {
    724                                                 if ( imgNode.className ) {
    725                                                         captionId = imgNode.className.match( /wp-image-([0-9]+)/ );
    726                                                         captionAlign = imgNode.className.match( /align(left|right|center|none)/ );
    727                                                 }
    728 
    729                                                 if ( captionAlign ) {
    730                                                         captionAlign = captionAlign[0];
    731                                                         imgNode.className = imgNode.className.replace( /align(left|right|center|none)/g, '' );
    732                                                 } else {
    733                                                         captionAlign = 'alignnone';
    734                                                 }
    735 
    736                                                 captionAlign = ' class="wp-caption ' + captionAlign + '"';
    737 
    738                                                 if ( captionId ) {
    739                                                         captionId = ' id="attachment_' + captionId[1] + '"';
    740                                                 }
    741 
    742                                                 captionWidth = data.width || imgNode.clientWidth;
    743 
    744                                                 if ( captionWidth ) {
    745                                                         captionWidth = parseInt( captionWidth, 10 );
    746 
    747                                                         if ( ! editor.getParam( 'wpeditimage_html5_captions' ) ) {
    748                                                                 captionWidth += 10;
    749                                                         }
    750 
    751                                                         captionWidth = ' style="width: '+ captionWidth +'px"';
    752                                                 }
    753 
    754                                                 if ( imgNode.parentNode && imgNode.parentNode.nodeName === 'A' ) {
    755                                                         node = imgNode.parentNode;
    756                                                 } else {
    757                                                         node = imgNode;
    758                                                 }
    759 
    760                                                 html = '<dl ' + captionId + captionAlign + captionWidth + '>' +
    761                                                         '<dt class="wp-caption-dt"></dt><dd class="wp-caption-dd">'+ caption +'</dd></dl>';
    762 
    763                                                 wrap = dom.create( 'div', { 'class': 'mceTemp' }, html );
    764 
    765                                                 if ( parent = dom.getParent( node, 'p' ) ) {
    766                                                         parent.parentNode.insertBefore( wrap, parent );
    767                                                 } else {
    768                                                         node.parentNode.insertBefore( wrap, node );
    769                                                 }
    770 
    771                                                 editor.$( wrap ).find( 'dt.wp-caption-dt' ).append( node );
    772 
    773                                                 if ( parent && dom.isEmpty( parent ) ) {
    774                                                         dom.remove( parent );
    775                                                 }
    776                                         }
    777                                 } else {
    778                                         if ( wrap ) {
    779                                                 // Remove the caption wrapper and place the image in new paragraph
    780                                                 if ( imgNode.parentNode.nodeName === 'A' ) {
    781                                                         html = dom.getOuterHTML( imgNode.parentNode );
    782                                                 } else {
    783                                                         html = dom.getOuterHTML( imgNode );
    784                                                 }
    785 
    786                                                 parent = dom.create( 'p', {}, html );
    787                                                 dom.insertAfter( parent, wrap.parentNode );
    788                                                 editor.selection.select( parent );
    789                                                 editor.nodeChanged();
    790                                                 dom.remove( wrap.parentNode );
    791                                         }
    792                                 }
    793                         }
    794 
    795                         imgNode = dom.get('__wp-temp-img-id');
    796                         dom.setAttrib( imgNode, 'id', imgId || null );
    797                         event.imgData.node = imgNode;
    798                 });
    799 
    800                 editor.on( 'wpLoadImageData', function( event ) {
    801                         var parent,
    802                                 data = event.imgData.data,
    803                                 imgNode = event.imgData.node;
    804 
    805                         if ( parent = dom.getParent( imgNode, 'dl.wp-caption' ) ) {
    806                                 parent = dom.select( 'dd.wp-caption-dd', parent )[0];
    807 
    808                                 if ( parent ) {
    809                                         data.wpcaption = editor.serializer.serialize( parent )
    810                                                 .replace( /<br[^>]*>/g, '$&\n' ).replace( /^<p>/, '' ).replace( /<\/p>$/, '' );
    811                                 }
    812                         }
    813                 });
    814 
    815590                // Prevent IE11 from making dl.wp-caption resizable
    816591                if ( tinymce.Env.ie && tinymce.Env.ie > 10 ) {
Note: See TracChangeset for help on using the changeset viewer.