mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
wpLink: replace the "Title" field with a "Text" field and populate it with the link text when editing an existing link or with the selected text if any.
Props iseulde. See #28206. git-svn-id: https://develop.svn.wordpress.org/trunk@31713 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1,12 +1,7 @@
|
||||
/* global tinymce */
|
||||
tinymce.PluginManager.add( 'wplink', function( editor ) {
|
||||
var linkButton;
|
||||
|
||||
// Register a command so that it can be invoked by using tinyMCE.activeEditor.execCommand( 'WP_Link' );
|
||||
editor.addCommand( 'WP_Link', function() {
|
||||
if ( ( ! linkButton || ! linkButton.disabled() ) && typeof window.wpLink !== 'undefined' ) {
|
||||
window.wpLink.open( editor.id );
|
||||
}
|
||||
window.wpLink && window.wpLink.open( editor.id );
|
||||
});
|
||||
|
||||
// WP default shortcut
|
||||
@@ -14,41 +9,18 @@ tinymce.PluginManager.add( 'wplink', function( editor ) {
|
||||
// The "de-facto standard" shortcut, see #27305
|
||||
editor.addShortcut( 'ctrl+k', '', 'WP_Link' );
|
||||
|
||||
function setState( button, node ) {
|
||||
var parent = editor.dom.getParent( node, 'a' ),
|
||||
getView = editor.plugins.wpview ? editor.plugins.wpview.getView : function() { return false; };
|
||||
|
||||
button.disabled( ( editor.selection.isCollapsed() && ! parent ) || ( parent && ! parent.href ) || getView( node ) );
|
||||
button.active( parent && parent.href );
|
||||
}
|
||||
|
||||
editor.addButton( 'link', {
|
||||
icon: 'link',
|
||||
tooltip: 'Insert/edit link',
|
||||
shortcut: 'Alt+Shift+A',
|
||||
cmd: 'WP_Link',
|
||||
|
||||
onPostRender: function() {
|
||||
linkButton = this;
|
||||
|
||||
editor.on( 'nodechange', function( event ) {
|
||||
setState( linkButton, event.element );
|
||||
});
|
||||
}
|
||||
stateSelector: 'a[href]'
|
||||
});
|
||||
|
||||
editor.addButton( 'unlink', {
|
||||
icon: 'unlink',
|
||||
tooltip: 'Remove link',
|
||||
cmd: 'unlink',
|
||||
|
||||
onPostRender: function() {
|
||||
var unlinkButton = this;
|
||||
|
||||
editor.on( 'nodechange', function( event ) {
|
||||
setState( unlinkButton, event.element );
|
||||
});
|
||||
}
|
||||
cmd: 'unlink'
|
||||
});
|
||||
|
||||
editor.addMenuItem( 'link', {
|
||||
|
||||
Reference in New Issue
Block a user