WordPress.org

Make WordPress Core

Changeset 31856


Ignore:
Timestamp:
03/20/2015 08:33:55 PM (6 years ago)
Author:
azaozz
Message:

TinyMCE: when pasting an URL, check if the node it is pasted at is empty and remove any empty inline child elements.
Fixes #31158.

File:
1 edited

Legend:

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

    r31832 r31856  
    174174        }
    175175
    176         node = editor.selection.getNode();
    177 
    178         // When a url is pasted, only try to embed it when pasted in an empty paragrapgh.
    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;
     176        if ( ! event.load ) {
     177            node = editor.selection.getNode();
     178
     179            if ( node && node !== editor.getBody() && /^\s*https?:\/\/\S+\s*$/i.test( event.content ) ) {
     180                // When a url is pasted or inserted, only try to embed it when it is in an empty paragrapgh.
     181                node = editor.dom.getParent( node, 'p' );
     182
     183                if ( node && /^[\s\uFEFF\u00A0]*$/.test( node.textContent || node.innerText ) ) {
     184                    // Make sure there are no empty inline elements in the <p>
     185                    node.innerHTML = '';
     186                } else {
     187                    return;
     188                }
     189            }
    183190        }
    184191
Note: See TracChangeset for help on using the changeset viewer.