Make WordPress Core

Ticket #31412: 31412.11.patch

File 31412.11.patch, 2.6 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                        }
     
    218229         * A Backbone-like View constructor intended for use when rendering a TinyMCE View.
    219230         * The main difference is that the TinyMCE View is not tied to a particular DOM node.
    220231         *
    221          * @param {Object} Options.
     232         * @param {Object} options Options.
    222233         */
    223234        wp.mce.View = function( options ) {
    224235                _.extend( this, options );
  • src/wp-includes/js/tinymce/plugins/wpview/plugin.js

     
    107107                clipboard = dom.create( 'div', {
    108108                        'class': 'wpview-clipboard',
    109109                        'contenteditable': 'true'
    110                 }, decodeURIComponent( editor.dom.getAttrib( viewNode, 'data-wpview-text' ) ) );
     110                }, wp.mce.views.getText( viewNode ) );
    111111
    112112                editor.dom.select( '.wpview-body', viewNode )[0].appendChild( clipboard );
    113113