Make WordPress Core

Ticket #29841: 29841.2.patch

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

     
    4343                        return '';
    4444                },
    4545                loadingPlaceholder: function() {
    46                         return '' +
     46                        return (
    4747                                '<div class="loading-placeholder">' +
    4848                                        '<div class="dashicons dashicons-admin-media"></div>' +
    4949                                        '<div class="wpview-loading"><ins></ins></div>' +
    50                                 '</div>';
     50                                '</div>'
     51                        );
    5152                },
    5253                render: function( force ) {
    53                         if ( force || ! this.rendered() ) {
     54                        var self = this;
     55
     56                        if ( ( ! this.loadingPlaceholder || ! this.loadingPlaceholder() ) && ! this.getHtml() ) {
     57                                return;
     58                        }
     59
     60                        if ( force ) {
    5461                                this.unbind();
     62                                this.setContent( this.getHtml() || this.loadingPlaceholder() );
     63                        }
    5564
    56                                 this.setContent(
    57                                         '<p class="wpview-selection-before">\u00a0</p>' +
    58                                         '<div class="wpview-body" contenteditable="false">' +
    59                                                 '<div class="toolbar mce-arrow-down">' +
    60                                                         ( _.isFunction( views[ this.type ].edit ) ? '<div class="dashicons dashicons-edit edit"></div>' : '' ) +
    61                                                         '<div class="dashicons dashicons-no remove"></div>' +
    62                                                 '</div>' +
    63                                                 '<div class="wpview-content wpview-type-' + this.type + '">' +
    64                                                         ( this.getHtml() || this.loadingPlaceholder() ) +
    65                                                 '</div>' +
    66                                                 ( this.overlay ? '<div class="wpview-overlay"></div>' : '' ) +
    67                                         '</div>' +
    68                                         '<p class="wpview-selection-after">\u00a0</p>',
    69                                         'wrap'
    70                                 );
     65                        this.getEditors( function( editor ) {
     66                                $( editor.getBody() )
     67                                .find( '[data-wpview-marked="' + self.encodedText + '"]' )
     68                                .each( function ( i, node ) {
     69                                        if ( $( node ).text() !== decodeURIComponent( self.encodedText ) ) {
     70                                                editor.dom.setAttrib( 'data-wpview-marked', null );
     71                                        }
    7172
    72                                 $( this ).trigger( 'ready' );
     73                                        editor.dom.replace(
     74                                                editor.dom.createFragment(
     75                                                        '<div class="wpview-wrap" data-wpview-text="' + self.encodedText + '" data-wpview-type="' + self.type + '">' +
     76                                                                '<p class="wpview-selection-before">\u00a0</p>' +
     77                                                                '<div class="wpview-body" contenteditable="false">' +
     78                                                                        '<div class="toolbar mce-arrow-down">' +
     79                                                                                ( _.isFunction( views[ self.type ].edit ) ? '<div class="dashicons dashicons-edit edit"></div>' : '' ) +
     80                                                                                '<div class="dashicons dashicons-no remove"></div>' +
     81                                                                        '</div>' +
     82                                                                        '<div class="wpview-content wpview-type-' + self.type + '">' +
     83                                                                                ( self.getHtml() || self.loadingPlaceholder() ) +
     84                                                                        '</div>' +
     85                                                                        ( self.overlay ? '<div class="wpview-overlay"></div>' : '' ) +
     86                                                                '</div>' +
     87                                                                '<p class="wpview-selection-after">\u00a0</p>' +
     88                                                        '</div>'
     89                                                ),
     90                                                node
     91                                        );
     92                                } );
     93                        } );
    7394
    74                                 this.rendered( true );
    75                         }
     95                        $( this ).trigger( 'ready' );
    7696                },
    7797                unbind: function() {},
    7898                getEditors: function( callback ) {
     
    110130                },
    111131                setContent: function( html, option ) {
    112132                        this.getNodes( function ( editor, node, content ) {
    113                                 var el = ( option === 'wrap' || option === 'replace' ) ? node : content,
    114                                         insert = html;
    115 
    116                                 if ( _.isString( insert ) ) {
    117                                         insert = editor.dom.createFragment( insert );
    118                                 }
    119 
    120                                 if ( option === 'replace' ) {
    121                                         editor.dom.replace( insert, el );
    122                                 } else {
    123                                         el.innerHTML = '';
    124                                         el.appendChild( insert );
    125                                 }
     133                                content.innerHTML = '';
     134                                content.appendChild( _.isString( html ) ? editor.dom.createFragment( html ) : html );
    126135                        } );
    127136                },
    128137                /* jshint scripturl: true */
     
    254263                                        '<p>' + message + '</p>' +
    255264                                '</div>'
    256265                        );
    257                 },
    258                 rendered: function( value ) {
    259                         var notRendered;
    260 
    261                         this.getNodes( function( editor, node ) {
    262                                 if ( value != null ) {
    263                                         $( node ).data( 'rendered', value === true );
    264                                 } else {
    265                                         notRendered = notRendered || ! $( node ).data( 'rendered' );
    266                                 }
    267                         } );
    268 
    269                         return ! notRendered;
    270266                }
    271267        } );
    272268
     
    432428                                instances[ encodedText ] = instance;
    433429                        }
    434430
    435                         return wp.html.string({
    436                                 tag: 'div',
    437 
    438                                 attrs: {
    439                                         'class': 'wpview-wrap',
    440                                         'data-wpview-text': encodedText,
    441                                         'data-wpview-type': viewType
    442                                 },
    443 
    444                                 content: '\u00a0'
    445                         });
     431                        return '<p data-wpview-marked="' + encodedText + '">' + text + '</p>';
    446432                },
    447433
    448434                /**
     
    681667                                        }
    682668                                } )
    683669                                .done( function( response ) {
    684                                         if ( response ) {
    685                                                 self.parsed = response;
    686                                                 self.setIframes( response.head, response.body );
    687                                                 self.deferredListen();
    688                                         } else {
    689                                                 self.fail( true );
    690                                         }
     670                                        self.parsed = response;
     671                                        self.render();
    691672                                } )
    692673                                .fail( function( response ) {
    693674                                        self.fail( response || true );
     
    742723
    743724                        unbind: function() {
    744725                                this.stopPlayers( 'remove' );
     726                        },
     727
     728                        getHtml: function() {
     729                                return this.parsed ? '\u00a0' : '';
    745730                        }
    746731                },
    747732
     
    891876                                        url: match[2]
    892877                                }
    893878                        };
    894                 }
     879                },
     880                View: _.extend( {}, wp.mce.embedMixin.View, {
     881                        loadingPlaceholder: false
     882                } )
    895883        } ) );
    896884
    897885}(jQuery));