From 641f9f9a9308996460ac3da4a4b43a8b5be90ace Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Thu, 3 Apr 2014 20:04:44 +0000 Subject: [PATCH] TinyMCE: improve setting disabled/enabled/activated states on the Unlink button, fixes #27309 git-svn-id: https://develop.svn.wordpress.org/trunk@27934 602fd350-edb4-49c9-b593-d223f7449a82 --- .../js/tinymce/plugins/wplink/plugin.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/js/tinymce/plugins/wplink/plugin.js b/src/wp-includes/js/tinymce/plugins/wplink/plugin.js index ce23641643..1d6820a12b 100644 --- a/src/wp-includes/js/tinymce/plugins/wplink/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wplink/plugin.js @@ -14,6 +14,11 @@ tinymce.PluginManager.add( 'wplink', function( editor ) { // 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', @@ -24,10 +29,7 @@ tinymce.PluginManager.add( 'wplink', function( editor ) { linkButton = this; editor.on( 'nodechange', function( event ) { - var node = event.element; - - linkButton.disabled( editor.selection.isCollapsed() && node.nodeName !== 'A' ); - linkButton.active( node.nodeName === 'A' && ! node.name ); + setState( linkButton, event.element ); }); } }); @@ -36,7 +38,14 @@ tinymce.PluginManager.add( 'wplink', function( editor ) { icon: 'unlink', tooltip: 'Remove link', cmd: 'unlink', - stateSelector: 'a[href]' + + onPostRender: function() { + var unlinkButton = this; + + editor.on( 'nodechange', function( event ) { + setState( unlinkButton, event.element ); + }); + } }); editor.addMenuItem( 'link', {