Make WordPress Core

Ticket #31158: 31158.3.patch

File 31158.3.patch, 2.0 KB (added by azaozz, 11 years ago)
  • src/wp-includes/js/tinymce/plugins/wpview/plugin.js

     
    167167        // matching view patterns, and transform the matches into
    168168        // view wrappers.
    169169        editor.on( 'BeforeSetContent', function( event ) {
    170                 var pastedStr = event.content,
    171                         trim = tinymce.trim,
    172                         node;
     170                var node;
    173171
    174                 if ( ! pastedStr ) {
     172                if ( ! event.content ) {
    175173                        return;
    176174                }
    177175
    178                 if ( selected ) {
    179                         removeView( selected );
    180                 }
    181 
    182176                node = editor.selection.getNode();
    183177
    184                 pastedStr = pastedStr.replace( /<[^>]+>/g, '' );
    185                 pastedStr = trim( pastedStr );
    186 
    187178                // When a url is pasted, only try to embed it when pasted in an empty paragrapgh.
    188                 if ( /^https?:\/\/\S+$/i.test( pastedStr ) ) {
    189                         event.content = pastedStr;
     179                if ( event.content.match( /^\s*(https?:\/\/[^\s"]+)\s*$/i ) &&
     180                        ( node.nodeName !== 'P' || node.parentNode !== editor.getBody() || ! editor.dom.isEmpty( node ) ) ) {
    190181
    191                         node = editor.dom.getParent( node, function( node ) {
    192                                 if ( node.parentNode === editor.getBody() ) {
    193                                         return node;
    194                                 }
    195                         } );
    196 
    197                         if ( node.nodeName !== 'P' || trim( node.textContent || node.innerText ) ) {
    198                                 return;
    199                         }
     182                        return;
    200183                }
    201184
    202185                event.content = wp.mce.views.setMarkers( event.content );
    203186        });
    204187
     188        // When pasting strip all tags and check if the string is an URL.
     189        // Then replace the pasted content with the cleaned URL.
     190        editor.on( 'pastePreProcess', function( event ) {
     191                var pastedStr = event.content;
     192
     193                if ( pastedStr ) {
     194                        pastedStr = tinymce.trim( pastedStr.replace( /<[^>]+>/g, '' ) );
     195
     196                        if ( /^https?:\/\/\S+$/i.test( pastedStr ) ) {
     197                                event.content = pastedStr;
     198                        }
     199                }
     200        });
     201
    205202        // When the editor's content has been updated and the DOM has been
    206203        // processed, render the views in the document.
    207204        editor.on( 'SetContent', function() {