mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-25 10:38:11 +01:00
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:
parent
c7ec095da1
commit
0ee57f8f88
@ -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', {
|
||||||
|
@ -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})});
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user