From 60ca80009aaae193311e587ea38bcfd43232f439 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Tue, 21 Feb 2017 06:51:47 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/branches/4.7@40094 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/js/customize-nav-menus.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/wp-admin/js/customize-nav-menus.js b/src/wp-admin/js/customize-nav-menus.js index a37d2c4e79..8abf97fe2c 100644 --- a/src/wp-admin/js/customize-nav-menus.js +++ b/src/wp-admin/js/customize-nav-menus.js @@ -1509,22 +1509,29 @@ * Update item handle title when changed. */ _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 ) { + var trimmedTitle, titleText; if ( ! item ) { return; } + trimmedTitle = $.trim( item.title ); - var titleEl = control.container.find( '.menu-item-title' ), - titleText = item.title || item.original_title || api.Menus.data.l10n.untitled; + titleText = trimmedTitle || item.original_title || api.Menus.data.l10n.untitled; if ( item._invalid ) { titleText = api.Menus.data.l10n.invalidTitleTpl.replace( '%s', titleText ); } // Don't update to an empty title. - if ( item.title || item.original_title ) { + if ( trimmedTitle || item.original_title ) { titleEl .text( titleText ) .removeClass( 'no-title' );