mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-05 02:10:45 +01:00
c465640107
Fixes #32357. Built from https://develop.svn.wordpress.org/trunk@32817 git-svn-id: http://core.svn.wordpress.org/trunk@32788 1a063a9b-81f0-0310-95a4-ce76da25c4cd
52 lines
1.2 KiB
JavaScript
52 lines
1.2 KiB
JavaScript
/* global tinymce */
|
|
tinymce.PluginManager.add( 'wplink', function( editor ) {
|
|
editor.addCommand( 'WP_Link', function() {
|
|
window.wpLink && window.wpLink.open( editor.id );
|
|
});
|
|
|
|
// WP default shortcut
|
|
editor.addShortcut( 'Alt+Shift+A', '', 'WP_Link' );
|
|
// The "de-facto standard" shortcut, see #27305
|
|
editor.addShortcut( 'Meta+K', '', 'WP_Link' );
|
|
|
|
editor.addButton( 'link', {
|
|
icon: 'link',
|
|
tooltip: 'Insert/edit link',
|
|
cmd: 'WP_Link',
|
|
stateSelector: 'a[href]'
|
|
});
|
|
|
|
editor.addButton( 'unlink', {
|
|
icon: 'unlink',
|
|
tooltip: 'Remove link',
|
|
cmd: 'unlink'
|
|
});
|
|
|
|
editor.addMenuItem( 'link', {
|
|
icon: 'link',
|
|
text: 'Insert/edit link',
|
|
cmd: 'WP_Link',
|
|
stateSelector: 'a[href]',
|
|
context: 'insert',
|
|
prependToContext: true
|
|
});
|
|
|
|
editor.on( 'pastepreprocess', function( event ) {
|
|
var pastedStr = event.content,
|
|
regExp = /^(?:https?:)?\/\/\S+$/i;
|
|
|
|
if ( ! editor.selection.isCollapsed() && ! regExp.test( editor.selection.getContent() ) ) {
|
|
pastedStr = pastedStr.replace( /<[^>]+>/g, '' );
|
|
pastedStr = tinymce.trim( pastedStr );
|
|
|
|
if ( regExp.test( pastedStr ) ) {
|
|
editor.execCommand( 'mceInsertLink', false, {
|
|
href: editor.dom.decode( pastedStr )
|
|
} );
|
|
|
|
event.preventDefault();
|
|
}
|
|
}
|
|
} );
|
|
});
|