Make WordPress Core

Ticket #31412: 31412.10.patch

File 31412.10.patch, 1.7 KB (added by iseulde, 10 years ago)
  • src/wp-includes/js/mce-view.js

     
    163163                /**
    164164                 * Get a view instance.
    165165                 *
     166                 * @param {(String|HTMLElement)} object The textual representation of the view or the view node.
     167                 */
     168                getInstance: function( object ) {
     169                        if ( typeof object === 'string' ) {
     170                                return instances[ encodeURIComponent( object ) ];
     171                        }
     172
     173                        return instances[ $( object ).data( 'wpview-text' ) ];
     174                },
     175
     176                /**
     177                 * Given a view node, get the view's text.
     178                 *
    166179                 * @param {String} text The textual representation of the view.
    167180                 */
    168                 getInstance: function( text ) {
    169                         return instances[ encodeURIComponent( text ) ];
     181                getText: function( node ) {
     182                        return decodeURIComponent( $( node ).data( 'wpview-text' ) || '' );
    170183                },
    171184
    172185                /**
     
    188201                 * @param {HTMLElement}    node   The view node to update.
    189202                 */
    190203                update: function( text, editor, node ) {
    191                         var oldText = decodeURIComponent( $( node ).data( 'wpview-text' ) ),
    192                                 instance = this.getInstance( oldText );
     204                        var instance = this.getInstance( node );
    193205
    194206                        if ( instance ) {
    195207                                instance.update( text, editor, node );
     
    203215                 * @param {HTMLElement}    node   The view node to edit.
    204216                 */
    205217                edit: function( editor, node ) {
    206                         var text = decodeURIComponent( $( node ).data( 'wpview-text' ) ),
    207                                 instance = this.getInstance( text );
     218                        var instance = this.getInstance( node );
    208219
    209220                        if ( instance && instance.edit ) {
    210                                 instance.edit( text, function( text ) {
     221                                instance.edit( instance.text, function( text ) {
    211222                                        instance.update( text, editor, node );
    212223                                } );
    213224                        }