TinyMCE: improve setting disabled/enabled/activated states on the Unlink button, fixes #27309

Built from https://develop.svn.wordpress.org/trunk@27934


git-svn-id: http://core.svn.wordpress.org/trunk@27764 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2014-04-03 20:05:31 +00:00
parent c7ec095da1
commit 0ee57f8f88
3 changed files with 15 additions and 6 deletions

View File

@ -14,6 +14,11 @@ tinymce.PluginManager.add( 'wplink', function( editor ) {
// The "de-facto standard" shortcut, see #27305 // The "de-facto standard" shortcut, see #27305
editor.addShortcut( 'ctrl+k', '', 'WP_Link' ); 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', { editor.addButton( 'link', {
icon: 'link', icon: 'link',
tooltip: 'Insert/edit link', tooltip: 'Insert/edit link',
@ -24,10 +29,7 @@ tinymce.PluginManager.add( 'wplink', function( editor ) {
linkButton = this; linkButton = this;
editor.on( 'nodechange', function( event ) { editor.on( 'nodechange', function( event ) {
var node = event.element; setState( linkButton, event.element );
linkButton.disabled( editor.selection.isCollapsed() && node.nodeName !== 'A' );
linkButton.active( node.nodeName === 'A' && ! node.name );
}); });
} }
}); });
@ -36,7 +38,14 @@ tinymce.PluginManager.add( 'wplink', function( editor ) {
icon: 'unlink', icon: 'unlink',
tooltip: 'Remove link', tooltip: 'Remove link',
cmd: 'unlink', cmd: 'unlink',
stateSelector: 'a[href]'
onPostRender: function() {
var unlinkButton = this;
editor.on( 'nodechange', function( event ) {
setState( unlinkButton, event.element );
});
}
}); });
editor.addMenuItem( 'link', { editor.addMenuItem( 'link', {

View File

@ -1 +1 @@
tinymce.PluginManager.add("wplink",function(a){var b;a.addCommand("WP_Link",function(){b&&b.disabled()||"undefined"==typeof window.wpLink||window.wpLink.open(a.id)}),a.addShortcut("alt+shift+a","","WP_Link"),a.addShortcut("ctrl+k","","WP_Link"),a.addButton("link",{icon:"link",tooltip:"Insert/edit link",shortcut:"Alt+Shift+A",cmd:"WP_Link",onPostRender:function(){b=this,a.on("nodechange",function(c){var d=c.element;b.disabled(a.selection.isCollapsed()&&"A"!==d.nodeName),b.active("A"===d.nodeName&&!d.name)})}}),a.addButton("unlink",{icon:"unlink",tooltip:"Remove link",cmd:"unlink",stateSelector:"a[href]"}),a.addMenuItem("link",{icon:"link",text:"Insert link",shortcut:"Alt+Shift+A",cmd:"WP_Link",stateSelector:"a[href]",context:"insert",prependToContext:!0})}); tinymce.PluginManager.add("wplink",function(a){function b(b,c){b.disabled(a.selection.isCollapsed()&&"A"!==c.nodeName),b.active("A"===c.nodeName&&!c.name)}var c;a.addCommand("WP_Link",function(){c&&c.disabled()||"undefined"==typeof window.wpLink||window.wpLink.open(a.id)}),a.addShortcut("alt+shift+a","","WP_Link"),a.addShortcut("ctrl+k","","WP_Link"),a.addButton("link",{icon:"link",tooltip:"Insert/edit link",shortcut:"Alt+Shift+A",cmd:"WP_Link",onPostRender:function(){c=this,a.on("nodechange",function(a){b(c,a.element)})}}),a.addButton("unlink",{icon:"unlink",tooltip:"Remove link",cmd:"unlink",onPostRender:function(){var c=this;a.on("nodechange",function(a){b(c,a.element)})}}),a.addMenuItem("link",{icon:"link",text:"Insert link",shortcut:"Alt+Shift+A",cmd:"WP_Link",stateSelector:"a[href]",context:"insert",prependToContext:!0})});