Customize: Trim whitespace from nav menu item titles so that the underlying object's original title appears as input placeholder and in the control's title.

Whitespace is trimmed from titles in PHP when saved in any case, so this aligns the client-side behavior with what happens on the server.

Amends [38618].
Merges [39994] to the 4.7 branch.
See #38015.
Fixes #39600.

Built from https://develop.svn.wordpress.org/branches/4.7@40094


git-svn-id: http://core.svn.wordpress.org/branches/4.7@40031 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dion Hulse 2017-02-21 06:52:35 +00:00
parent 2a891e4456
commit a0edd9b006
3 changed files with 14 additions and 7 deletions

View File

@ -1509,22 +1509,29 @@
* Update item handle title when changed. * Update item handle title when changed.
*/ */
_setupTitleUI: function() { _setupTitleUI: function() {
var control = this; var control = this, titleEl;
// Ensure that whitespace is trimmed on blur so placeholder can be shown.
control.container.find( '.edit-menu-item-title' ).on( 'blur', function() {
$( this ).val( $.trim( $( this ).val() ) );
} );
titleEl = control.container.find( '.menu-item-title' );
control.setting.bind( function( item ) { control.setting.bind( function( item ) {
var trimmedTitle, titleText;
if ( ! item ) { if ( ! item ) {
return; return;
} }
trimmedTitle = $.trim( item.title );
var titleEl = control.container.find( '.menu-item-title' ), titleText = trimmedTitle || item.original_title || api.Menus.data.l10n.untitled;
titleText = item.title || item.original_title || api.Menus.data.l10n.untitled;
if ( item._invalid ) { if ( item._invalid ) {
titleText = api.Menus.data.l10n.invalidTitleTpl.replace( '%s', titleText ); titleText = api.Menus.data.l10n.invalidTitleTpl.replace( '%s', titleText );
} }
// Don't update to an empty title. // Don't update to an empty title.
if ( item.title || item.original_title ) { if ( trimmedTitle || item.original_title ) {
titleEl titleEl
.text( titleText ) .text( titleText )
.removeClass( 'no-title' ); .removeClass( 'no-title' );

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.7.3-alpha-40093'; $wp_version = '4.7.3-alpha-40094';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.