Make WordPress Core

Changeset 31691


Ignore:
Timestamp:
03/09/2015 07:59:14 PM (10 years ago)
Author:
azaozz
Message:

TinyMCE: when pasting an URL over a selection, insert a link with the URL instead of replacing the selection with it. Props iseulde. Fixes #31571.

Location:
trunk/src/wp-includes/js/tinymce/plugins
Files:
2 edited

Legend:

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

    r31362 r31691  
    12211221    });
    12221222
     1223    editor.on( 'beforeexeccommand', function( event ) {
     1224        if ( isPlaceholder( editor.selection.getNode() ) ) {
     1225            event.preventDefault();
     1226        }
     1227    } );
     1228
    12231229    return {
    12241230        _do_shcode: parseShortcode,
  • trunk/src/wp-includes/js/tinymce/plugins/wplink/plugin.js

    r29183 r31691  
    22tinymce.PluginManager.add( 'wplink', function( editor ) {
    33    var linkButton;
    4    
     4
    55    // Register a command so that it can be invoked by using tinyMCE.activeEditor.execCommand( 'WP_Link' );
    66    editor.addCommand( 'WP_Link', function() {
     
    6161        prependToContext: true
    6262    });
     63
     64    editor.on( 'pastepreprocess', function( event ) {
     65        var pastedStr = event.content;
     66
     67        if ( ! editor.selection.isCollapsed() ) {
     68            pastedStr = pastedStr.replace( /<[^>]+>/g, '' );
     69            pastedStr = tinymce.trim( pastedStr );
     70
     71            if ( /^(?:https?:)?\/\/\S+$/i.test( pastedStr ) ) {
     72                editor.execCommand( 'mceInsertLink', false, {
     73                    href: editor.dom.decode( pastedStr )
     74                } );
     75
     76                event.preventDefault();
     77            }
     78        }
     79    } );
    6380});
Note: See TracChangeset for help on using the changeset viewer.