X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/7f1521bf193b382565eb753043c161f4cb3fcda7..b22765f41bf0b2021b9beb9120ee0ac91fa89292:/wp-includes/js/mce-view.js?ds=sidebyside diff --git a/wp-includes/js/mce-view.js b/wp-includes/js/mce-view.js index eab4560c..3d2616d7 100644 --- a/wp-includes/js/mce-view.js +++ b/wp-includes/js/mce-view.js @@ -1,7 +1,5 @@ /* global tinymce */ -window.wp = window.wp || {}; - /* * The TinyMCE view API. * @@ -24,7 +22,7 @@ window.wp = window.wp || {}; * |- registered view * | |- ... */ -( function( window, wp, $ ) { +( function( window, wp, shortcode, $ ) { 'use strict'; var views = {}, @@ -93,8 +91,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 +99,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 +116,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: instance.ignore ? text : '' + text + '
', processed: true } ); @@ -138,31 +136,37 @@ window.wp = window.wp || {}; } ); } ); - 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 ); + text = tinymce.DOM.decode( text ); - if ( instance ) { - return instance; + if ( ! force ) { + instance = this.getInstance( text ); + + if ( instance ) { + return instance; + } } + encodedText = encodeURIComponent( text ); + options = _.extend( options || {}, { text: text, encodedText: encodedText @@ -214,12 +218,13 @@ window.wp = window.wp || {}; * @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 +238,8 @@ window.wp = window.wp || {}; 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 ); } ); } }, @@ -300,8 +305,8 @@ window.wp = window.wp || {}; /** * 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 +327,9 @@ window.wp = window.wp || {}; 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 +351,8 @@ window.wp = window.wp || {}; * 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 +393,7 @@ window.wp = window.wp || {}; 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 +420,18 @@ window.wp = window.wp || {}; */ replaceMarkers: function() { this.getMarkers( function( editor, node ) { - if ( $( node ).text() !== this.text ) { + var $viewNode; + + if ( ! this.loader && $( node ).text() !== this.text ) { editor.dom.setAttrib( node, 'data-wpview-marker', null ); return; } - editor.dom.replace( - editor.dom.createFragment( - '
\u00a0
' + - '\u00a0
' + - '