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.

Built from https://develop.svn.wordpress.org/trunk@31691


git-svn-id: http://core.svn.wordpress.org/trunk@31672 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2015-03-09 20:00:27 +00:00
parent 6ffa051689
commit d08bb970ae
6 changed files with 27 additions and 4 deletions

View File

@ -1220,6 +1220,12 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) {
}
});
editor.on( 'beforeexeccommand', function( event ) {
if ( isPlaceholder( editor.selection.getNode() ) ) {
event.preventDefault();
}
} );
return {
_do_shcode: parseShortcode,
_get_shcode: getShortcode

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,7 @@
/* global tinymce */
tinymce.PluginManager.add( 'wplink', function( editor ) {
var linkButton;
// Register a command so that it can be invoked by using tinyMCE.activeEditor.execCommand( 'WP_Link' );
editor.addCommand( 'WP_Link', function() {
if ( ( ! linkButton || ! linkButton.disabled() ) && typeof window.wpLink !== 'undefined' ) {
@ -60,4 +60,21 @@ tinymce.PluginManager.add( 'wplink', function( editor ) {
context: 'insert',
prependToContext: true
});
editor.on( 'pastepreprocess', function( event ) {
var pastedStr = event.content;
if ( ! editor.selection.isCollapsed() ) {
pastedStr = pastedStr.replace( /<[^>]+>/g, '' );
pastedStr = tinymce.trim( pastedStr );
if ( /^(?:https?:)?\/\/\S+$/i.test( pastedStr ) ) {
editor.execCommand( 'mceInsertLink', false, {
href: editor.dom.decode( pastedStr )
} );
event.preventDefault();
}
}
} );
});

View File

@ -1 +1 @@
tinymce.PluginManager.add("wplink",function(a){function b(b,c){var d=a.dom.getParent(c,"a"),e=a.plugins.wpview?a.plugins.wpview.getView:function(){return!1};b.disabled(a.selection.isCollapsed()&&!d||d&&!d.href||e(c)),b.active(d&&d.href)}var c;a.addCommand("WP_Link",function(){c&&c.disabled()||"undefined"==typeof window.wpLink||window.wpLink.open(a.id)}),a.addShortcut("alt+shift+a","","WP_Link"),a.addShortcut("ctrl+k","","WP_Link"),a.addButton("link",{icon:"link",tooltip:"Insert/edit link",shortcut:"Alt+Shift+A",cmd:"WP_Link",onPostRender:function(){c=this,a.on("nodechange",function(a){b(c,a.element)})}}),a.addButton("unlink",{icon:"unlink",tooltip:"Remove link",cmd:"unlink",onPostRender:function(){var c=this;a.on("nodechange",function(a){b(c,a.element)})}}),a.addMenuItem("link",{icon:"link",text:"Insert link",shortcut:"Alt+Shift+A",cmd:"WP_Link",stateSelector:"a[href]",context:"insert",prependToContext:!0})});
tinymce.PluginManager.add("wplink",function(a){function b(b,c){var d=a.dom.getParent(c,"a"),e=a.plugins.wpview?a.plugins.wpview.getView:function(){return!1};b.disabled(a.selection.isCollapsed()&&!d||d&&!d.href||e(c)),b.active(d&&d.href)}var c;a.addCommand("WP_Link",function(){c&&c.disabled()||"undefined"==typeof window.wpLink||window.wpLink.open(a.id)}),a.addShortcut("alt+shift+a","","WP_Link"),a.addShortcut("ctrl+k","","WP_Link"),a.addButton("link",{icon:"link",tooltip:"Insert/edit link",shortcut:"Alt+Shift+A",cmd:"WP_Link",onPostRender:function(){c=this,a.on("nodechange",function(a){b(c,a.element)})}}),a.addButton("unlink",{icon:"unlink",tooltip:"Remove link",cmd:"unlink",onPostRender:function(){var c=this;a.on("nodechange",function(a){b(c,a.element)})}}),a.addMenuItem("link",{icon:"link",text:"Insert link",shortcut:"Alt+Shift+A",cmd:"WP_Link",stateSelector:"a[href]",context:"insert",prependToContext:!0}),a.on("pastepreprocess",function(b){var c=b.content;a.selection.isCollapsed()||(c=c.replace(/<[^>]+>/g,""),c=tinymce.trim(c),/^(?:https?:)?\/\/\S+$/i.test(c)&&(a.execCommand("mceInsertLink",!1,{href:a.dom.decode(c)}),b.preventDefault()))})});

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.2-alpha-31690';
$wp_version = '4.2-alpha-31691';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.