Make WordPress Core

Ticket #29804: 29804.2.patch

File 29804.2.patch, 5.5 KB (added by iseulde, 10 years ago)
  • src/wp-includes/js/tinymce/plugins/wordpress/plugin.js

     
    8686    });
    8787
    8888        // Replace Read More/Next Page tags with images
    89         editor.on( 'BeforeSetContent', function( e ) {
     89        editor.on( 'BeforeSetContent', function( event ) {
    9090                var title;
    9191
    92                 if ( e.content ) {
    93                         if ( e.content.indexOf( '<!--more' ) !== -1 ) {
     92                if ( event.content ) {
     93                        if ( event.content.indexOf( '<!--more' ) !== -1 ) {
    9494                                title = editor.editorManager.i18n.translate( 'Read more...' );
    9595
    96                                 e.content = e.content.replace( /<!--more(.*?)-->/g, function( match, moretext ) {
    97                                         return '<img src="' + tinymce.Env.transparentSrc + '" data-wp-more="more" data-wp-more-text="' + moretext + '" ' +
    98                                                 'class="wp-more-tag mce-wp-more" title="' + title + '" data-mce-resize="false" data-mce-placeholder="1" />';
     96                                event.content = event.content.replace( /<!--more(.*?)-->/g, function( match, moretext ) {
     97                                        return '<hr data-wp-more="more" data-wp-more-text="' + moretext + '" title="' + ( tinymce.trim( moretext ) || title ) + '" />';
    9998                                });
    10099                        }
    101100
    102                         if ( e.content.indexOf( '<!--nextpage-->' ) !== -1 ) {
     101                        if ( event.content.indexOf( '<!--nextpage-->' ) !== -1 ) {
    103102                                title = editor.editorManager.i18n.translate( 'Page break' );
    104103
    105                                 e.content = e.content.replace( /<!--nextpage-->/g,
    106                                         '<img src="' + tinymce.Env.transparentSrc + '" data-wp-more="nextpage" class="wp-more-tag mce-wp-nextpage" ' +
    107                                                 'title="' + title + '" data-mce-resize="false" data-mce-placeholder="1" />' );
     104                                event.content = event.content.replace( /<!--nextpage-->/g, '<hr data-wp-more="nextpage" title="' + editor.editorManager.i18n.translate( 'Page break' ) + '" />' );
    108105                        }
    109106                }
    110107        });
     
    112109        // Replace images with tags
    113110        editor.on( 'PostProcess', function( e ) {
    114111                if ( e.get ) {
    115                         e.content = e.content.replace(/<img[^>]+>/g, function( image ) {
     112                        e.content = e.content.replace(/<hr[^>]+>/g, function( image ) {
    116113                                var match, moretext = '';
    117114
    118115                                if ( image.indexOf( 'data-wp-more="more"' ) !== -1 ) {
     
    134131        editor.on( 'ResolveName', function( event ) {
    135132                var attr;
    136133
    137                 if ( event.target.nodeName === 'IMG' && ( attr = editor.dom.getAttrib( event.target, 'data-wp-more' ) ) ) {
     134                if ( event.target.nodeName === 'HR' && ( attr = editor.dom.getAttrib( event.target, 'data-wp-more' ) ) ) {
    138135                        event.name = attr;
    139136                }
    140137        });
     
    142139        // Register commands
    143140        editor.addCommand( 'WP_More', function( tag ) {
    144141                var parent, html, title,
    145                         classname = 'wp-more-tag',
    146142                        dom = editor.dom,
    147143                        node = editor.selection.getNode();
    148144
    149145                tag = tag || 'more';
    150                 classname += ' mce-wp-' + tag;
    151                 title = tag === 'more' ? 'Read more...' : 'Next page';
    152                 title = editor.editorManager.i18n.translate( title );
    153                 html = '<img src="' + tinymce.Env.transparentSrc + '" title="' + title + '" class="' + classname + '" ' +
    154                         'data-wp-more="' + tag + '" data-mce-resize="false" data-mce-placeholder="1" />';
     146                title = editor.editorManager.i18n.translate( tag === 'more' ? 'Read more...' : 'Page break' );
     147                html = '<hr title="' + title + '" data-wp-more="' + tag + '" />';
    155148
    156149                // Most common case
    157                 if ( node.nodeName === 'BODY' || ( node.nodeName === 'P' && node.parentNode.nodeName === 'BODY' ) ) {
     150                if ( node.nodeName === 'BODY' || ( node.parentNode.nodeName === 'BODY' && ( node.nodeName === 'P' ) ) ) {
    158151                        editor.insertContent( html );
    159152                        return;
    160153                }
    161154
    162155                // Get the top level parent node
    163156                parent = dom.getParent( node, function( found ) {
    164                         if ( found.parentNode && found.parentNode.nodeName === 'BODY' ) {
    165                                 return true;
    166                         }
    167 
    168                         return false;
     157                        return found.parentNode && found.parentNode.nodeName === 'BODY';
    169158                }, editor.getBody() );
    170159
    171160                if ( parent ) {
    172                         if ( parent.nodeName === 'P' ) {
    173                                 parent.appendChild( dom.create( 'p', null, html ).firstChild );
    174                         } else {
    175                                 dom.insertAfter( dom.create( 'p', null, html ), parent );
    176                         }
    177 
     161                        editor.$( parent ).after( html );
    178162                        editor.nodeChanged();
    179163                }
    180164        });
  • src/wp-includes/js/tinymce/skins/wordpress/wp-content.css

     
    136136        padding: 0;
    137137}
    138138
    139 .mce-content-body img[data-wp-more] {
     139hr[data-wp-more] {
     140        background: none;
    140141        border: 0;
    141142        -webkit-box-shadow: none;
    142143        box-shadow: none;
    143         width: 96%;
    144         height: 16px;
     144        width: 100%;
     145        height: 22px;
     146        font-size: 14px;
     147        line-height: 20px;
    145148        display: block;
    146         margin: 15px auto 0;
     149        margin: 20px 0;
    147150        outline: 0;
    148         cursor: default;
     151        cursor: pointer;
     152        position: relative;
    149153}
    150154
    151 .mce-content-body img[data-wp-more][data-mce-selected] {
    152         outline: 1px dotted #888;
     155hr[data-wp-more][data-mce-selected] {
     156        outline: 1px dotted currentColor;
    153157}
    154158
    155 .mce-content-body img[data-wp-more="more"] {
    156         background: transparent url( images/more.png ) repeat-y scroll center center;
     159hr[data-wp-more]:after {
     160        content: '';
     161        position: absolute;
     162        top: 20px;
     163        border-bottom: 2px dashed currentColor;
     164        width: 100%;
    157165}
    158166
    159 .mce-content-body img[data-wp-more="nextpage"] {
    160     background: transparent url( images/pagebreak.png ) repeat-y scroll center center;
     167hr[data-wp-more]:before {
     168        content: attr( title );
     169        position: absolute;
    161170}
    162171
    163172/* Gallery, audio, video placeholders */