Make WordPress Core

Changeset 38796


Ignore:
Timestamp:
10/14/2016 09:37:41 PM (10 years ago)
Author:
azaozz
Message:

TinyMCE:

  • Prevent applying Indent and Outdent while an image with a caption is selected. It doesn't do anything and breaks the caption elements.
  • Keep all of the text when a caption <dl> was somehow changed.

Fixes #38313.

File:
1 edited

Legend:

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

    r38756 r38796  
    182182                        var out = '';
    183183
    184                         if ( dl.indexOf('<img ') === -1 ) {
    185                                 // Broken caption. The user managed to drag the image out?
    186                                 // Try to return the caption text as a paragraph.
    187                                 out = dl.match( /<dd [^>]+>([\s\S]+?)<\/dd>/i );
    188 
    189                                 if ( out && out[1] ) {
    190                                         return '<p>' + out[1] + '</p>';
    191                                 }
    192 
    193                                 return '';
     184                        if ( dl.indexOf('<img ') === -1 || dl.indexOf('</p>') !== -1 ) {
     185                                // Broken caption. The user managed to drag the image out or type in the wrapper div?
     186                                // Remove the <dl>, <dd> and <dt> and return the remaining text.
     187                                return dl.replace( /<d[ldt]( [^>]+)?>/g, '' ).replace( /<\/d[ldt]>/g, '' );
    194188                        }
    195189
    … …  
    897891                        dom = editor.dom;
    898892
    899                 if ( cmd === 'mceInsertContent' ) {
     893                if ( cmd === 'mceInsertContent' || cmd === 'Indent' || cmd === 'Outdent' ) {
    900894                        node = editor.selection.getNode();
    901895                        captionParent = dom.getParent( node, 'div.mceTemp' );
    902896
    903897                        if ( captionParent ) {
    904                                 if ( pasteInCaption ) {
    905                                         pasteInCaption = false;
    906                                         // We are in the caption element, and in 'paste' context,
    907                                         // and the pasted HTML was cleaned up on 'pastePostProcess' above.
    908                                         // Let it be pasted in the caption.
    909                                         return;
    910                                 }
    911 
    912                                 // The paste is somewhere else in the caption DL element.
    913                                 // Prevent pasting in there as it will break the caption.
    914                                 // Make new paragraph under the caption DL and move the caret there.
    915                                 p = dom.create( 'p' );
    916                                 dom.insertAfter( p, captionParent );
    917                                 editor.selection.setCursorLocation( p, 0 );
    918                                 editor.nodeChanged();
     898                                if ( cmd === 'mceInsertContent' ) {
     899                                        if ( pasteInCaption ) {
     900                                                pasteInCaption = false;
     901                                                // We are in the caption element, and in 'paste' context,
     902                                                // and the pasted HTML was cleaned up on 'pastePostProcess' above.
     903                                                // Let it be pasted in the caption.
     904                                                return;
     905                                        }
     906
     907                                        // The paste is somewhere else in the caption DL element.
     908                                        // Prevent pasting in there as it will break the caption.
     909                                        // Make new paragraph under the caption DL and move the caret there.
     910                                        p = dom.create( 'p' );
     911                                        dom.insertAfter( p, captionParent );
     912                                        editor.selection.setCursorLocation( p, 0 );
     913                                        editor.nodeChanged();
     914                                } else {
     915                                        // Clicking Indent or Outdent while an image with a caption is selected breaks the caption.
     916                                        // See #38313.
     917                                        event.preventDefault();
     918                                        event.stopImmediatePropagation();
     919                                        return false;
     920                                }
    919921                        }
    920922                } else if ( cmd === 'JustifyLeft' || cmd === 'JustifyRight' || cmd === 'JustifyCenter' || cmd === 'wpAlignNone' ) {
Note: See TracChangeset for help on using the changeset viewer.