From 76508ede28f45b04dd1d20130a72a189bb693f86 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Tue, 14 Jan 2014 05:45:53 +0000 Subject: [PATCH] TinyMCE: improve handling of Read More and Nextpage tags. See #24067, fixes #16239. git-svn-id: https://develop.svn.wordpress.org/trunk@26941 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/quicktags.js | 2 +- .../js/tinymce/plugins/wordpress/plugin.js | 40 +++++++++++++++++-- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/js/quicktags.js b/src/wp-includes/js/quicktags.js index da57be1abf..872f4c8682 100644 --- a/src/wp-includes/js/quicktags.js +++ b/src/wp-includes/js/quicktags.js @@ -643,7 +643,7 @@ function edButton(id, display, tagStart, tagEnd, access) { edButtons[90] = new qt.TagButton('ol','ol','
    \n','
\n\n','o'), edButtons[100] = new qt.TagButton('li','li','\t
  • ','
  • \n','l'), edButtons[110] = new qt.TagButton('code','code','','','c'), - edButtons[120] = new qt.TagButton('more','more','','','t'), + edButtons[120] = new qt.TagButton('more','more','\n\n\n\n','','t'), edButtons[140] = new qt.CloseButton(); })(); diff --git a/src/wp-includes/js/tinymce/plugins/wordpress/plugin.js b/src/wp-includes/js/tinymce/plugins/wordpress/plugin.js index 1fe5aae93e..1a2dda3d67 100644 --- a/src/wp-includes/js/tinymce/plugins/wordpress/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wordpress/plugin.js @@ -126,20 +126,43 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { } }); + // Make sure the "more" tag is in a separate paragraph + editor.on( 'PreProcess', function( event ) { + var more; + + if ( event.save ) { + more = editor.dom.select( 'img.wp-more-tag', event.node ); + + if ( more.length ) { + tinymce.each( more, function( node ) { + var parent = node.parentNode, p; + + if ( parent.nodeName === 'P' && parent.childNodes.length > 1 ) { + p = editor.dom.create('p'); + parent.parentNode.insertBefore( p, parent ); + p.appendChild( node ); + } + }); + } + } + }); + // Register commands editor.addCommand( 'WP_More', function( tag ) { - var parent, html, title, + var parent, html, title, p1, p2, classname = 'wp-more-tag', + spacer = tinymce.Env.ie ? '' : '
    ', dom = editor.dom, node = editor.selection.getNode(); tag = tag || 'more'; classname += ' mce-wp-' + tag; title = tag === 'more' ? 'More...' : 'Next Page'; - html = ''; + html = ''; if ( node.nodeName === 'BODY' ) { - editor.insertContent( '

    ' + html + '

    ' ); + editor.insertContent( '

    ' + html + '

    ' ); return; } @@ -153,7 +176,16 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { }, editor.getBody() ); if ( parent ) { - dom.insertAfter( dom.create( 'p', null, html ), parent ); + p1 = dom.create( 'p', null, html ); + dom.insertAfter( p1, parent ); + + if ( ! ( p2 = p1.nextSibling ) ) { + p2 = dom.create( 'p', null, spacer ); + dom.insertAfter( p2, p1 ); + } + + editor.nodeChanged(); + editor.selection.setCursorLocation( p2, 0 ); } });