Ticket #29804: 29804.2.patch
File 29804.2.patch, 5.5 KB (added by , 10 years ago) |
---|
-
src/wp-includes/js/tinymce/plugins/wordpress/plugin.js
86 86 }); 87 87 88 88 // Replace Read More/Next Page tags with images 89 editor.on( 'BeforeSetContent', function( e ) {89 editor.on( 'BeforeSetContent', function( event ) { 90 90 var title; 91 91 92 if ( e .content ) {93 if ( e .content.indexOf( '<!--more' ) !== -1 ) {92 if ( event.content ) { 93 if ( event.content.indexOf( '<!--more' ) !== -1 ) { 94 94 title = editor.editorManager.i18n.translate( 'Read more...' ); 95 95 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 ) + '" />'; 99 98 }); 100 99 } 101 100 102 if ( e .content.indexOf( '<!--nextpage-->' ) !== -1 ) {101 if ( event.content.indexOf( '<!--nextpage-->' ) !== -1 ) { 103 102 title = editor.editorManager.i18n.translate( 'Page break' ); 104 103 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' ) + '" />' ); 108 105 } 109 106 } 110 107 }); … … 112 109 // Replace images with tags 113 110 editor.on( 'PostProcess', function( e ) { 114 111 if ( e.get ) { 115 e.content = e.content.replace(/< img[^>]+>/g, function( image ) {112 e.content = e.content.replace(/<hr[^>]+>/g, function( image ) { 116 113 var match, moretext = ''; 117 114 118 115 if ( image.indexOf( 'data-wp-more="more"' ) !== -1 ) { … … 134 131 editor.on( 'ResolveName', function( event ) { 135 132 var attr; 136 133 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' ) ) ) { 138 135 event.name = attr; 139 136 } 140 137 }); … … 142 139 // Register commands 143 140 editor.addCommand( 'WP_More', function( tag ) { 144 141 var parent, html, title, 145 classname = 'wp-more-tag',146 142 dom = editor.dom, 147 143 node = editor.selection.getNode(); 148 144 149 145 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 + '" />'; 155 148 156 149 // 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' ) ) ) { 158 151 editor.insertContent( html ); 159 152 return; 160 153 } 161 154 162 155 // Get the top level parent node 163 156 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'; 169 158 }, editor.getBody() ); 170 159 171 160 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 ); 178 162 editor.nodeChanged(); 179 163 } 180 164 }); -
src/wp-includes/js/tinymce/skins/wordpress/wp-content.css
136 136 padding: 0; 137 137 } 138 138 139 .mce-content-body img[data-wp-more] { 139 hr[data-wp-more] { 140 background: none; 140 141 border: 0; 141 142 -webkit-box-shadow: none; 142 143 box-shadow: none; 143 width: 96%; 144 height: 16px; 144 width: 100%; 145 height: 22px; 146 font-size: 14px; 147 line-height: 20px; 145 148 display: block; 146 margin: 15px auto0;149 margin: 20px 0; 147 150 outline: 0; 148 cursor: default; 151 cursor: pointer; 152 position: relative; 149 153 } 150 154 151 .mce-content-body img[data-wp-more][data-mce-selected] {152 outline: 1px dotted #888;155 hr[data-wp-more][data-mce-selected] { 156 outline: 1px dotted currentColor; 153 157 } 154 158 155 .mce-content-body img[data-wp-more="more"] { 156 background: transparent url( images/more.png ) repeat-y scroll center center; 159 hr[data-wp-more]:after { 160 content: ''; 161 position: absolute; 162 top: 20px; 163 border-bottom: 2px dashed currentColor; 164 width: 100%; 157 165 } 158 166 159 .mce-content-body img[data-wp-more="nextpage"] { 160 background: transparent url( images/pagebreak.png ) repeat-y scroll center center; 167 hr[data-wp-more]:before { 168 content: attr( title ); 169 position: absolute; 161 170 } 162 171 163 172 /* Gallery, audio, video placeholders */