mirror of
https://github.com/WordPress/WordPress.git
synced 2024-09-10 14:48:07 +02:00
Built from https://develop.svn.wordpress.org/trunk@27934 git-svn-id: http://core.svn.wordpress.org/trunk@27764 1a063a9b-81f0-0310-95a4-ce76da25c4cd
61 lines
1.4 KiB
JavaScript
61 lines
1.4 KiB
JavaScript
/* 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' ) {
|
|
window.wpLink.open( editor.id );
|
|
}
|
|
});
|
|
|
|
// WP default shortcut
|
|
editor.addShortcut( 'alt+shift+a', '', 'WP_Link' );
|
|
// The "de-facto standard" shortcut, see #27305
|
|
editor.addShortcut( 'ctrl+k', '', 'WP_Link' );
|
|
|
|
function setState( button, node ) {
|
|
button.disabled( editor.selection.isCollapsed() && node.nodeName !== 'A' );
|
|
button.active( node.nodeName === 'A' && ! node.name );
|
|
}
|
|
|
|
editor.addButton( 'link', {
|
|
icon: 'link',
|
|
tooltip: 'Insert/edit link',
|
|
shortcut: 'Alt+Shift+A',
|
|
cmd: 'WP_Link',
|
|
|
|
onPostRender: function() {
|
|
linkButton = this;
|
|
|
|
editor.on( 'nodechange', function( event ) {
|
|
setState( linkButton, event.element );
|
|
});
|
|
}
|
|
});
|
|
|
|
editor.addButton( 'unlink', {
|
|
icon: 'unlink',
|
|
tooltip: 'Remove link',
|
|
cmd: 'unlink',
|
|
|
|
onPostRender: function() {
|
|
var unlinkButton = this;
|
|
|
|
editor.on( 'nodechange', function( event ) {
|
|
setState( unlinkButton, event.element );
|
|
});
|
|
}
|
|
});
|
|
|
|
editor.addMenuItem( 'link', {
|
|
icon: 'link',
|
|
text: 'Insert link',
|
|
shortcut: 'Alt+Shift+A',
|
|
cmd: 'WP_Link',
|
|
stateSelector: 'a[href]',
|
|
context: 'insert',
|
|
prependToContext: true
|
|
});
|
|
});
|