2 tinymce.PluginManager.add( 'wplink', function( editor ) {
5 // Register a command so that it can be invoked by using tinyMCE.activeEditor.execCommand( 'WP_Link' );
6 editor.addCommand( 'WP_Link', function() {
7 if ( ( ! linkButton || ! linkButton.disabled() ) && typeof window.wpLink !== 'undefined' ) {
8 window.wpLink.open( editor.id );
12 // WP default shortcut
13 editor.addShortcut( 'alt+shift+a', '', 'WP_Link' );
14 // The "de-facto standard" shortcut, see #27305
15 editor.addShortcut( 'ctrl+k', '', 'WP_Link' );
17 function setState( button, node ) {
18 var parent = editor.dom.getParent( node, 'a' );
20 button.disabled( ( editor.selection.isCollapsed() && ! parent ) || ( parent && ! parent.href ) );
21 button.active( parent && parent.href );
24 editor.addButton( 'link', {
26 tooltip: 'Insert/edit link',
27 shortcut: 'Alt+Shift+A',
30 onPostRender: function() {
33 editor.on( 'nodechange', function( event ) {
34 setState( linkButton, event.element );
39 editor.addButton( 'unlink', {
41 tooltip: 'Remove link',
44 onPostRender: function() {
45 var unlinkButton = this;
47 editor.on( 'nodechange', function( event ) {
48 setState( unlinkButton, event.element );
53 editor.addMenuItem( 'link', {
56 shortcut: 'Alt+Shift+A',
58 stateSelector: 'a[href]',
60 prependToContext: true