TinyMCE: views: make sure gallery captions update

Part props dmsnell.
Fixes #32779.


git-svn-id: https://develop.svn.wordpress.org/trunk@33338 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ella Iseulde Van Dorpe 2015-07-20 23:55:46 +00:00
parent 8768541ce5
commit 6da15e0528
1 changed files with 25 additions and 18 deletions

View File

@ -148,20 +148,24 @@ window.wp = window.wp || {};
* @param {String} type The view type. * @param {String} type The view type.
* @param {String} text The textual representation of the view. * @param {String} text The textual representation of the view.
* @param {Object} options Options. * @param {Object} options Options.
* @param {Boolean} force Recreate the instance. Optional.
* *
* @return {wp.mce.View} The view instance. * @return {wp.mce.View} The view instance.
*/ */
createInstance: function( type, text, options ) { createInstance: function( type, text, options, force ) {
var View = this.get( type ), var View = this.get( type ),
encodedText, encodedText,
instance; instance;
text = tinymce.DOM.decode( text ); text = tinymce.DOM.decode( text );
if ( ! force ) {
instance = this.getInstance( text ); instance = this.getInstance( text );
if ( instance ) { if ( instance ) {
return instance; return instance;
} }
}
encodedText = encodeURIComponent( text ); encodedText = encodeURIComponent( text );
@ -216,12 +220,13 @@ window.wp = window.wp || {};
* @param {String} text The new text. * @param {String} text The new text.
* @param {tinymce.Editor} editor The TinyMCE editor instance the view node is in. * @param {tinymce.Editor} editor The TinyMCE editor instance the view node is in.
* @param {HTMLElement} node The view node to update. * @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 ); var instance = this.getInstance( node );
if ( instance ) { if ( instance ) {
instance.update( text, editor, node ); instance.update( text, editor, node, force );
} }
}, },
@ -235,8 +240,8 @@ window.wp = window.wp || {};
var instance = this.getInstance( node ); var instance = this.getInstance( node );
if ( instance && instance.edit ) { if ( instance && instance.edit ) {
instance.edit( instance.text, function( text ) { instance.edit( instance.text, function( text, force ) {
instance.update( text, editor, node ); instance.update( text, editor, node, force );
} ); } );
} }
}, },
@ -303,7 +308,7 @@ window.wp = window.wp || {};
* Renders all view nodes tied to this view instance that are not yet rendered. * Renders all view nodes tied to this view instance that are not yet rendered.
* *
* @param {String} content The content to render. Optional. * @param {String} content The content to render. Optional.
* @param {Boolean} force Rerender all view nodes tied to this view instance. * @param {Boolean} force Rerender all view nodes tied to this view instance. Optional.
*/ */
render: function( content, force ) { render: function( content, force ) {
if ( content != null ) { if ( content != null ) {
@ -647,7 +652,7 @@ window.wp = window.wp || {};
* Sets an error for all view nodes tied to this view instance. * Sets an error for all view nodes tied to this view instance.
* *
* @param {String} message The error message to set. * @param {String} message The error message to set.
* @param {String} dashicon A dashicon ID (optional). {@link https://developer.wordpress.org/resource/dashicons/} * @param {String} dashicon A dashicon ID. Optional. {@link https://developer.wordpress.org/resource/dashicons/}
*/ */
setError: function( message, dashicon ) { setError: function( message, dashicon ) {
this.setContent( this.setContent(
@ -685,15 +690,16 @@ window.wp = window.wp || {};
* @param {String} text The new text. * @param {String} text The new text.
* @param {tinymce.Editor} editor The TinyMCE editor instance the view node is in. * @param {tinymce.Editor} editor The TinyMCE editor instance the view node is in.
* @param {HTMLElement} node The view node to update. * @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 ) {
_.find( views, function( view, type ) { _.find( views, function( view, type ) {
var match = view.prototype.match( text ); var match = view.prototype.match( text );
if ( match ) { if ( match ) {
$( node ).data( 'rendered', false ); $( node ).data( 'rendered', false );
editor.dom.setAttrib( node, 'data-wpview-text', encodeURIComponent( text ) ); editor.dom.setAttrib( node, 'data-wpview-text', encodeURIComponent( text ) );
wp.mce.views.createInstance( type, text, match.options ).render(); wp.mce.views.createInstance( type, text, match.options, force ).render();
editor.focus(); editor.focus();
return true; return true;
@ -729,14 +735,15 @@ window.wp = window.wp || {};
state: [], state: [],
edit: function( text, update ) { edit: function( text, update ) {
var media = wp.media[ this.type ], var type = this.type,
media = wp.media[ type ],
frame = media.edit( text ); frame = media.edit( text );
this.pausePlayers && this.pausePlayers(); this.pausePlayers && this.pausePlayers();
_.each( this.state, function( state ) { _.each( this.state, function( state ) {
frame.state( state ).on( 'update', function( selection ) { frame.state( state ).on( 'update', function( selection ) {
update( media.shortcode( selection ).string() ); update( media.shortcode( selection ).string(), type === 'gallery' );
} ); } );
} ); } );