diff --git a/src/wp-includes/js/mce-view.js b/src/wp-includes/js/mce-view.js index eab4560c82..b28eac4c50 100644 --- a/src/wp-includes/js/mce-view.js +++ b/src/wp-includes/js/mce-view.js @@ -93,8 +93,7 @@ window.wp = window.wp || {}; setMarkers: function( content ) { var pieces = [ { content: content } ], self = this, - instance, - current; + instance, current; _.each( views, function( view, type ) { current = pieces.slice(); @@ -102,7 +101,7 @@ window.wp = window.wp || {}; _.each( current, function( piece ) { var remaining = piece.content, - result; + result, text; // Ignore processed pieces, but retain their location. if ( piece.processed ) { @@ -119,10 +118,11 @@ window.wp = window.wp || {}; } instance = self.createInstance( type, result.content, result.options ); + text = instance.loader ? '.' : instance.text; // Add the processed piece for the match. pieces.push( { - content: '

' + instance.text + '

', + content: '

' + text + '

', processed: true } ); @@ -138,7 +138,8 @@ window.wp = window.wp || {}; } ); } ); - return _.pluck( pieces, 'content' ).join( '' ); + content = _.pluck( pieces, 'content' ).join( '' ); + return content.replace( /

\s*

' ); }, /** @@ -416,7 +417,7 @@ window.wp = window.wp || {}; */ replaceMarkers: function() { this.getMarkers( function( editor, node ) { - if ( $( node ).text() !== this.text ) { + if ( ! this.loader && $( node ).text() !== this.text ) { editor.dom.setAttrib( node, 'data-wpview-marker', null ); return; } diff --git a/src/wp-includes/js/media-audiovideo.js b/src/wp-includes/js/media-audiovideo.js index cf9d7550bf..8b598db691 100644 --- a/src/wp-includes/js/media-audiovideo.js +++ b/src/wp-includes/js/media-audiovideo.js @@ -704,7 +704,7 @@ VideoDetails = MediaDetails.extend({ if ( -1 === content.indexOf( attachment.get( 'url' ) ) ) { content += [ - '' ].join(''); diff --git a/src/wp-includes/js/media/views/frame/video-details.js b/src/wp-includes/js/media/views/frame/video-details.js index c46078fda0..6b2c5fa453 100644 --- a/src/wp-includes/js/media/views/frame/video-details.js +++ b/src/wp-includes/js/media/views/frame/video-details.js @@ -120,7 +120,7 @@ VideoDetails = MediaDetails.extend({ if ( -1 === content.indexOf( attachment.get( 'url' ) ) ) { content += [ - '' ].join(''); diff --git a/src/wp-includes/js/tinymce/plugins/wpview/plugin.js b/src/wp-includes/js/tinymce/plugins/wpview/plugin.js index 3a69af7538..104006a175 100644 --- a/src/wp-includes/js/tinymce/plugins/wpview/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wpview/plugin.js @@ -152,19 +152,20 @@ tinymce.PluginManager.add( 'wpview', function( editor ) { }; } - // Remove the content of view wrappers from HTML string - function emptyViews( content ) { - content = content.replace( /]+data-wpview-text="([^"]+)"[^>]*>[\s\S]+?wpview-selection-after[^>]+>[^<>]*<\/p>\s*<\/div>/g, function( all, match ) { - return '

' + window.decodeURIComponent( match ) + '

'; - }); + function resetViewsCallback( match, viewText ) { + return '

' + window.decodeURIComponent( viewText ) + '

'; + } - return content.replace( / data-wpview-marker="[^"]+"/g, '' ); + // Replace the view tags with the view string + function resetViews( content ) { + return content.replace( /]+data-wpview-text="([^"]+)"[^>]*>(?:[\s\S]+?wpview-selection-after[^>]+>[^<>]*<\/p>\s*|\.)<\/div>/g, resetViewsCallback ) + .replace( /

]*?data-wpview-marker="([^"]+)"[^>]*>[\s\S]*?<\/p>/g, resetViewsCallback ); } // Prevent adding undo levels on changes inside a view wrapper editor.on( 'BeforeAddUndo', function( event ) { if ( event.level.content ) { - event.level.content = emptyViews( event.level.content ); + event.level.content = resetViews( event.level.content ); } }); @@ -348,31 +349,29 @@ tinymce.PluginManager.add( 'wpview', function( editor ) { } }); - function resetViews( rootNode ) { - // Replace view nodes - $( 'div[data-wpview-text]', rootNode ).each( function( i, node ) { - var $node = $( node ), - text = window.decodeURIComponent( $node.attr( 'data-wpview-text' ) || '' ); - - if ( text && node.parentNode ) { - $node.replaceWith( $( editor.dom.create('p') ).text( text ) ); - } + // Empty the wpview wrap and marker nodes + function emptyViewNodes( rootNode ) { + $( 'div[data-wpview-text], p[data-wpview-marker]', rootNode ).each( function( i, node ) { + node.innerHTML = '.'; }); - - // Remove marker attributes - $( 'p[data-wpview-marker]', rootNode ).attr( 'data-wpview-marker', null ); } + // Run that before the DOM cleanup editor.on( 'PreProcess', function( event ) { - // Replace the view nodes with their text in the DOM clone. - resetViews( event.node ); + emptyViewNodes( event.node ); }, true ); editor.on( 'hide', function() { - // Replace the view nodes with their text directly in the editor body. wp.mce.views.unbind(); deselect(); - resetViews( editor.getBody() ); + emptyViewNodes(); + }); + + editor.on( 'PostProcess', function( event ) { + if ( event.content ) { + event.content = event.content.replace( /

]*?data-wpview-text="([^"]+)"[^>]*>[\s\S]*?<\/div>/g, resetViewsCallback ) + .replace( /

]*?data-wpview-marker="([^"]+)"[^>]*>[\s\S]*?<\/p>/g, resetViewsCallback ); + } }); // Excludes arrow keys, delete, backspace, enter, space bar.