Make WordPress Core

Changeset 27729


Ignore:
Timestamp:
03/26/2014 02:07:23 AM (13 years ago)
Author:
azaozz
Message:

TinyMCE: fix the More and Next Page tags behavior:

  • Append them inside top level <p> tags.
  • If the caret is not in a top level <p>, create new paragraph after the current top level tag.
  • Do not change placement when edited in the Text editor.

See #27378

Location:
trunk/src/wp-includes/js
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/quicktags.js

    r27131 r27729  
    644644        edButtons[100] = new qt.TagButton('li','li','\t<li>','</li>\n','l'),
    645645        edButtons[110] = new qt.TagButton('code','code','<code>','</code>','c'),
    646         edButtons[120] = new qt.TagButton('more','more','\n\n<!--more-->\n\n','','t'),
     646        edButtons[120] = new qt.TagButton('more','more','<!--more-->\n\n','','t'),
    647647        edButtons[140] = new qt.CloseButton();
    648648
  • trunk/src/wp-includes/js/tinymce/plugins/wordpress/plugin.js

    r27602 r27729  
    131131        });
    132132
    133         // Make sure the "more" tag is in a separate paragraph
    134         editor.on( 'PreProcess', function( event ) {
    135                 var more;
    136 
    137                 if ( event.save ) {
    138                         more = editor.dom.select( 'img.wp-more-tag', event.node );
    139 
    140                         if ( more.length ) {
    141                                 tinymce.each( more, function( node ) {
    142                                         var parent = node.parentNode, p;
    143 
    144                                         if ( parent.nodeName === 'P' && parent.childNodes.length > 1 ) {
    145                                                 p = editor.dom.create('p');
    146                                                 parent.parentNode.insertBefore( p, parent );
    147                                                 p.appendChild( node );
    148                                         }
    149                                 });
    150                         }
    151                 }
    152         });
    153 
    154133        // Register commands
    155134        editor.addCommand( 'WP_More', function( tag ) {
    156                 var parent, html, title, p1, p2,
     135                var parent, html, title,
    157136                        classname = 'wp-more-tag',
    158                         spacer = tinymce.Env.ie ? '' : '<br data-mce-bogus="1" />',
    159137                        dom = editor.dom,
    160138                        node = editor.selection.getNode();
    … …  
    166144                        'data-mce-resize="false" data-mce-placeholder="1" />';
    167145
    168                 if ( node.nodeName === 'BODY' ) {
    169                         editor.insertContent( '<p>' + html + '</p><p></p>' );
     146                // Most common case
     147                if ( node.nodeName === 'BODY' || ( node.nodeName === 'P' && node.parentNode.nodeName === 'BODY' ) ) {
     148                        editor.insertContent( html );
    170149                        return;
    171150                }
    … …  
    181160
    182161                if ( parent ) {
    183                         p1 = dom.create( 'p', null, html );
    184                         dom.insertAfter( p1, parent );
    185 
    186                         if ( ! ( p2 = p1.nextSibling ) ) {
    187                                 p2 = dom.create( 'p', null, spacer );
    188                                 dom.insertAfter( p2, p1 );
     162                        if ( parent.nodeName === 'P' ) {
     163                                parent.appendChild( dom.create( 'p', null, html ).firstChild );
     164                        } else {
     165                                dom.insertAfter( dom.create( 'p', null, html ), parent );
    189166                        }
    190167
    191168                        editor.nodeChanged();
    192                         editor.selection.setCursorLocation( p2, 0 );
    193169                }
    194170        });
Note: See TracChangeset for help on using the changeset viewer.