Make WordPress Core

Changeset 31832


Ignore:
Timestamp:
03/19/2015 07:07:48 AM (11 years ago)
Author:
azaozz
Message:

TinyMCE: revert stripping of tags from pasted URLs on beforeSetContent [31817] and [31819]. Clean up URLs on pastePreProcess.
See #31158.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/tinymce/plugins/wpview/plugin.js

    r31819 r31832  
    168168        // view wrappers.
    169169        editor.on( 'BeforeSetContent', function( event ) {
    170                 var pastedStr = event.content,
    171                         trim = tinymce.trim,
    172                         node;
    173 
    174                 if ( ! pastedStr ) {
     170                var node;
     171
     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;
    190 
    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                         }
     179                if ( event.content.match( /^\s*(https?:\/\/[^\s"]+)\s*$/i ) &&
     180                        ( node.nodeName !== 'P' || node.parentNode !== editor.getBody() || ! editor.dom.isEmpty( node ) ) ) {
     181
     182                        return;
    200183                }
    201184
    202185                event.content = wp.mce.views.setMarkers( event.content );
     186        });
     187
     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                }
    203200        });
    204201
Note: See TracChangeset for help on using the changeset viewer.