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' ),
19
getView = editor.plugins.wpview ? editor.plugins.wpview.getView : function() { return false; };
21
button.disabled( ( editor.selection.isCollapsed() && ! parent ) || ( parent && ! parent.href ) || getView( node ) );
22
button.active( parent && parent.href );
25
editor.addButton( 'link', {
27
tooltip: 'Insert/edit link',
28
shortcut: 'Alt+Shift+A',
31
onPostRender: function() {
34
editor.on( 'nodechange', function( event ) {
35
setState( linkButton, event.element );
40
editor.addButton( 'unlink', {
42
tooltip: 'Remove link',
45
onPostRender: function() {
46
var unlinkButton = this;
48
editor.on( 'nodechange', function( event ) {
49
setState( unlinkButton, event.element );
54
editor.addMenuItem( 'link', {
57
shortcut: 'Alt+Shift+A',
59
stateSelector: 'a[href]',
61
prependToContext: true