Make WordPress Core

Ticket #32078: 32078.4.patch

File 32078.4.patch, 5.8 KB (added by azaozz, 11 years ago)
  • src/wp-includes/js/mce-view.js

     
    9393                setMarkers: function( content ) {
    9494                        var pieces = [ { content: content } ],
    9595                                self = this,
    96                                 instance,
    97                                 current;
     96                                instance, current;
    9897
    9998                        _.each( views, function( view, type ) {
    10099                                current = pieces.slice();
     
    102101
    103102                                _.each( current, function( piece ) {
    104103                                        var remaining = piece.content,
    105                                                 result;
     104                                                result, text;
    106105
    107106                                        // Ignore processed pieces, but retain their location.
    108107                                        if ( piece.processed ) {
     
    119118                                                }
    120119
    121120                                                instance = self.createInstance( type, result.content, result.options );
     121                                                text = instance.loader ? '.' : instance.text;
    122122
    123123                                                // Add the processed piece for the match.
    124124                                                pieces.push( {
    125                                                         content: '<p data-wpview-marker="' + instance.encodedText + '">' + instance.text + '</p>',
     125                                                        content: '<p data-wpview-marker="' + instance.encodedText + '">' + text + '</p>',
    126126                                                        processed: true
    127127                                                } );
    128128
     
    138138                                } );
    139139                        } );
    140140
    141                         return _.pluck( pieces, 'content' ).join( '' );
     141                        content = _.pluck( pieces, 'content' ).join( '' );
     142                        return content.replace( /<p>\s*<p data-wpview-marker=/g, '<p data-wpview-marker=' ).replace( /<\/p>\s*<\/p>/g, '</p>' );
    142143                },
    143144
    144145                /**
     
    416417                 */
    417418                replaceMarkers: function() {
    418419                        this.getMarkers( function( editor, node ) {
    419                                 if ( $( node ).text() !== this.text ) {
     420                                if ( ! this.loader && $( node ).text() !== this.text ) {
    420421                                        editor.dom.setAttrib( node, 'data-wpview-marker', null );
    421422                                        return;
    422423                                }
  • src/wp-includes/js/media-audiovideo.js

     
    704704
    705705                        if ( -1 === content.indexOf( attachment.get( 'url' ) ) ) {
    706706                                content += [
    707                                         '<track srclang="en" label="English"kind="subtitles" src="',
     707                                        '<track srclang="en" label="English" kind="subtitles" src="',
    708708                                        attachment.get( 'url' ),
    709709                                        '" />'
    710710                                ].join('');
  • src/wp-includes/js/media/views/frame/video-details.js

     
    120120
    121121                        if ( -1 === content.indexOf( attachment.get( 'url' ) ) ) {
    122122                                content += [
    123                                         '<track srclang="en" label="English"kind="subtitles" src="',
     123                                        '<track srclang="en" label="English" kind="subtitles" src="',
    124124                                        attachment.get( 'url' ),
    125125                                        '" />'
    126126                                ].join('');
  • src/wp-includes/js/tinymce/plugins/wpview/plugin.js

     
    152152                };
    153153        }
    154154
    155         // Remove the content of view wrappers from HTML string
    156         function emptyViews( content ) {
    157                 content = content.replace( /<div[^>]+data-wpview-text="([^"]+)"[^>]*>[\s\S]+?wpview-selection-after[^>]+>[^<>]*<\/p>\s*<\/div>/g, function( all, match ) {
    158                         return '<p>' + window.decodeURIComponent( match ) + '</p>';
    159                 });
     155        function resetViewsCallback( match, viewText ) {
     156                return '<p>' + window.decodeURIComponent( viewText ) + '</p>';
     157        }
    160158
    161                 return content.replace( / data-wpview-marker="[^"]+"/g, '' );
     159        // Replace the view tags with the view string
     160        function resetViews( content ) {
     161                return content.replace( /<div[^>]+data-wpview-text="([^"]+)"[^>]*>(?:[\s\S]+?wpview-selection-after[^>]+>[^<>]*<\/p>\s*|\.)<\/div>/g, resetViewsCallback )
     162                        .replace( /<p [^>]*?data-wpview-marker="([^"]+)"[^>]*>[\s\S]*?<\/p>/g, resetViewsCallback );
    162163        }
    163164
    164165        // Prevent adding undo levels on changes inside a view wrapper
    165166        editor.on( 'BeforeAddUndo', function( event ) {
    166167                if ( event.level.content ) {
    167                         event.level.content = emptyViews( event.level.content );
     168                        event.level.content = resetViews( event.level.content );
    168169                }
    169170        });
    170171
     
    348349                }
    349350        });
    350351
    351         function resetViews( rootNode ) {
    352                 // Replace view nodes
    353                 $( 'div[data-wpview-text]', rootNode ).each( function( i, node ) {
    354                         var $node = $( node ),
    355                                 text = window.decodeURIComponent( $node.attr( 'data-wpview-text' ) || '' );
    356 
    357                         if ( text && node.parentNode ) {
    358                                 $node.replaceWith( $( editor.dom.create('p') ).text( text ) );
    359                         }
     352        // Empty the wpview wrap and marker nodes
     353        function emptyViewNodes( rootNode ) {
     354                $( 'div[data-wpview-text], p[data-wpview-marker]', rootNode ).each( function( i, node ) {
     355                        node.innerHTML = '.';
    360356                });
    361 
    362                 // Remove marker attributes
    363                 $( 'p[data-wpview-marker]', rootNode ).attr( 'data-wpview-marker', null );
    364357        }
    365358
     359        // Run that before the DOM cleanup
    366360        editor.on( 'PreProcess', function( event ) {
    367                 // Replace the view nodes with their text in the DOM clone.
    368                 resetViews( event.node );
     361                emptyViewNodes( event.node );
    369362        }, true );
    370363
    371364        editor.on( 'hide', function() {
    372                 // Replace the view nodes with their text directly in the editor body.
    373365                wp.mce.views.unbind();
    374366                deselect();
    375                 resetViews( editor.getBody() );
     367                emptyViewNodes();
    376368        });
    377369
     370        editor.on( 'PostProcess', function( event ) {
     371                if ( event.content ) {
     372                        event.content = event.content.replace( /<div [^>]*?data-wpview-text="([^"]+)"[^>]*>[\s\S]*?<\/div>/g, resetViewsCallback )
     373                                .replace( /<p [^>]*?data-wpview-marker="([^"]+)"[^>]*>[\s\S]*?<\/p>/g, resetViewsCallback );
     374                }
     375        });
     376
    378377        // Excludes arrow keys, delete, backspace, enter, space bar.
    379378        // Ref: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent.keyCode
    380379        function isSpecialKey( key ) {