TinyMCE inline link:

- Fix not displaying anything when the URL is only a fragment. Show the whole URL.
- Fix editing a link when it is the very first word in the editor.
- Fix editing a link then some of the surrounding text or space is selected. Change the selection to only the link node.
- Add placeholder when adding new link.

See #33301.
Built from https://develop.svn.wordpress.org/trunk@36483


git-svn-id: http://core.svn.wordpress.org/trunk@36450 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2016-02-06 00:51:27 +00:00
parent 20c07afbd5
commit 3a2ef071d4
5 changed files with 40 additions and 12 deletions

View File

@ -1043,6 +1043,7 @@ final class _WP_Editors {
'No alignment' => __( 'No alignment' ), // Tooltip for the 'alignnone' button in the image toolbar
'Remove' => __( 'Remove' ), // Tooltip for the 'remove' button in the image toolbar
'Edit ' => __( 'Edit' ), // Tooltip for the 'edit' button in the image toolbar
'Paste URL or type to search' => __( 'Paste URL or type to search' ), // Placeholder for the inline link dialog
// Shortcuts help modal
'Keyboard Shortcuts' => __( 'Keyboard Shortcuts' ),

View File

@ -32,6 +32,11 @@
url = url.slice( 0, -1 );
}
// If nothing's left (maybe the URL was just a fragment), use the whole URL.
if ( url === '' ) {
url = this.url;
}
// If the URL is longer that 40 chars, concatenate the beginning (after the domain) and ending with ...
if ( url.length > 40 && ( index = url.indexOf( '/' ) ) !== -1 && ( lastIndex = url.lastIndexOf( '/' ) ) !== -1 && lastIndex !== index ) {
// If the beginning + ending are shorter that 40 chars, show more of the ending
@ -51,7 +56,7 @@
renderHtml: function() {
return (
'<div id="' + this._id + '" class="wp-link-input">' +
'<input type="text" value="" tabindex="-1" />' +
'<input type="text" value="" tabindex="-1" placeholder="' + tinymce.translate('Paste URL or type to search') + '" />' +
'</div>'
);
},
@ -68,6 +73,28 @@
var inputInstance;
var $ = window.jQuery;
function getSelectedLink() {
var href,
selectedNode = editor.selection.getNode(),
selectedText = editor.selection.getContent(),
link = editor.dom.getParent( selectedNode, 'a[href]' );
if ( ! link && selectedText.indexOf( '</a>' ) !== -1 ) {
href = selectedText.match( /href="([^">]+)"/ );
if ( href && href[1] ) {
link = editor.$( 'a[href="' + href[1] + '"]', selectedNode )[0];
}
if ( link ) {
editor.selection.select( link );
editor.nodeChanged();
}
}
return link;
}
editor.on( 'preinit', function() {
if ( editor.wp && editor.wp._createToolbar ) {
toolbar = editor.wp._createToolbar( [
@ -83,9 +110,10 @@
], true );
editToolbar.on( 'show', function() {
var node = editToolbar.find( 'toolbar' )[0];
node && node.focus( true );
a = editor.dom.getParent( editor.selection.getNode(), 'a' );
var inputNode = editToolbar.find( 'toolbar' )[0];
inputNode && inputNode.focus( true );
a = getSelectedLink();
} );
editToolbar.on( 'hide', function() {
@ -95,15 +123,14 @@
} );
editor.addCommand( 'WP_Link', function() {
var a = editor.dom.getParent( editor.selection.getNode(), 'a' );
var link = getSelectedLink();
if ( a ) {
editor.dom.setAttribs( a, { 'data-wp-edit': true } );
if ( link ) {
editor.dom.setAttribs( link, { 'data-wp-edit': true } );
} else {
editor.execCommand( 'mceInsertLink', false, { href: '_wp_link_placeholder' } );
editor.nodeChanged();
}
editor.nodeChanged();
} );
editor.addCommand( 'wp_link_apply', function() {

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.5-alpha-36482';
$wp_version = '4.5-alpha-36483';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
@ -18,7 +18,7 @@ $wp_db_version = 36180;
*
* @global string $tinymce_version
*/
$tinymce_version = '4303-20160119';
$tinymce_version = '4303-20160205';
/**
* Holds the required PHP version