diff -r 490d5cc509ed -r cf61fcea0001 wp/wp-includes/js/mce-view.js --- a/wp/wp-includes/js/mce-view.js Tue Jun 09 11:14:17 2015 +0000 +++ b/wp/wp-includes/js/mce-view.js Mon Oct 14 17:39:30 2019 +0200 @@ -1,7 +1,5 @@ /* global tinymce */ -window.wp = window.wp || {}; - /* * The TinyMCE view API. * @@ -24,7 +22,7 @@ * |- registered view * | |- ... */ -( function( window, wp, $ ) { +( function( window, wp, shortcode, $ ) { 'use strict'; var views = {}, @@ -87,14 +85,14 @@ * and creates a new instance for every match. * * @param {String} content The string to scan. + * @param {tinymce.Editor} editor The editor. * * @return {String} The string with markers. */ - setMarkers: function( content ) { + setMarkers: function( content, editor ) { var pieces = [ { content: content } ], self = this, - instance, - current; + instance, current; _.each( views, function( view, type ) { current = pieces.slice(); @@ -102,7 +100,7 @@ _.each( current, function( piece ) { var remaining = piece.content, - result; + result, text; // Ignore processed pieces, but retain their location. if ( piece.processed ) { @@ -118,11 +116,13 @@ pieces.push( { content: remaining.substring( 0, result.index ) } ); } + result.options.editor = editor; 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: instance.ignore ? text : '' + text + '
', processed: true } ); @@ -138,31 +138,43 @@ } ); } ); - return _.pluck( pieces, 'content' ).join( '' ); + content = _.pluck( pieces, 'content' ).join( '' ); + return content.replace( /\s*
' ); }, /** * Create a view instance. * - * @param {String} type The view type. - * @param {String} text The textual representation of the view. - * @param {Object} options Options. + * @param {String} type The view type. + * @param {String} text The textual representation of the view. + * @param {Object} options Options. + * @param {Boolean} force Recreate the instance. Optional. * * @return {wp.mce.View} The view instance. */ - createInstance: function( type, text, options ) { + createInstance: function( type, text, options, force ) { var View = this.get( type ), encodedText, instance; - text = tinymce.DOM.decode( text ), - encodedText = encodeURIComponent( text ), - instance = this.getInstance( encodedText ); + if ( text.indexOf( '[' ) !== -1 && text.indexOf( ']' ) !== -1 ) { + // Looks like a shortcode? Remove any line breaks from inside of shortcodes + // or autop will replace them with
and
later and the string won't match.
+ text = text.replace( /\[[^\]]+\]/g, function( match ) {
+ return match.replace( /[\r\n]/g, '' );
+ });
+ }
- if ( instance ) {
- return instance;
+ if ( ! force ) {
+ instance = this.getInstance( text );
+
+ if ( instance ) {
+ return instance;
+ }
}
+ encodedText = encodeURIComponent( text );
+
options = _.extend( options || {}, {
text: text,
encodedText: encodedText
@@ -204,7 +216,7 @@
*/
render: function( force ) {
_.each( instances, function( instance ) {
- instance.render( force );
+ instance.render( null, force );
} );
},
@@ -214,12 +226,13 @@
* @param {String} text The new text.
* @param {tinymce.Editor} editor The TinyMCE editor instance the view node is in.
* @param {HTMLElement} node The view node to update.
+ * @param {Boolean} force Recreate the instance. Optional.
*/
- update: function( text, editor, node ) {
+ update: function( text, editor, node, force ) {
var instance = this.getInstance( node );
if ( instance ) {
- instance.update( text, editor, node );
+ instance.update( text, editor, node, force );
}
},
@@ -233,8 +246,8 @@
var instance = this.getInstance( node );
if ( instance && instance.edit ) {
- instance.edit( instance.text, function( text ) {
- instance.update( text, editor, node );
+ instance.edit( instance.text, function( text, force ) {
+ instance.update( text, editor, node, force );
} );
}
},
@@ -267,7 +280,7 @@
wp.mce.View.extend = Backbone.View.extend;
- _.extend( wp.mce.View.prototype, {
+ _.extend( wp.mce.View.prototype, /** @lends wp.mce.View.prototype */{
/**
* The content.
@@ -289,7 +302,7 @@
initialize: function() {},
/**
- * Retuns the content to render in the view node.
+ * Returns the content to render in the view node.
*
* @return {*}
*/
@@ -300,8 +313,8 @@
/**
* Renders all view nodes tied to this view instance that are not yet rendered.
*
- * @param {String} content The content to render. Optional.
- * @param {Boolean} force Rerender all view nodes tied to this view instance.
+ * @param {String} content The content to render. Optional.
+ * @param {Boolean} force Rerender all view nodes tied to this view instance. Optional.
*/
render: function( content, force ) {
if ( content != null ) {
@@ -322,9 +335,9 @@
this.replaceMarkers();
if ( content ) {
- this.setContent( content, function( editor, node, contentNode ) {
+ this.setContent( content, function( editor, node ) {
$( node ).data( 'rendered', true );
- this.bindNode.call( this, editor, node, contentNode );
+ this.bindNode.call( this, editor, node );
}, force ? null : false );
} else {
this.setLoader();
@@ -346,9 +359,8 @@
* Runs before their content is removed from the DOM.
*/
unbind: function() {
- this.getNodes( function( editor, node, contentNode ) {
- this.unbindNode.call( this, editor, node, contentNode );
- $( node ).trigger( 'wp-mce-view-unbind' );
+ this.getNodes( function( editor, node ) {
+ this.unbindNode.call( this, editor, node );
}, true );
},
@@ -389,7 +401,7 @@
return rendered ? data : ! data;
} )
.each( function() {
- callback.call( self, editor, this, $( this ).find( '.wpview-content' ).get( 0 ) );
+ callback.call( self, editor, this, this /* back compat */ );
} );
} );
},
@@ -416,23 +428,26 @@
*/
replaceMarkers: function() {
this.getMarkers( function( editor, node ) {
- if ( $( node ).text() !== this.text ) {
+ var selected = node === editor.selection.getNode();
+ var $viewNode;
+
+ if ( ! this.loader && $( node ).text() !== tinymce.DOM.decode( this.text ) ) {
editor.dom.setAttrib( node, 'data-wpview-marker', null );
return;
}
- editor.dom.replace(
- editor.dom.createFragment(
- '
\u00a0
' + - '\u00a0
' + - '