Make WordPress Core

Changeset 39994


Ignore:
Timestamp:
01/26/2017 06:07:58 PM (8 years ago)
Author:
westonruter
Message:

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].
See #38015.
Fixes #39600.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/customize-nav-menus.js

    r39558 r39994  
    15191519         */
    15201520        _setupTitleUI: function() {
    1521             var control = this;
    1522 
     1521            var control = this, titleEl;
     1522
     1523            // Ensure that whitespace is trimmed on blur so placeholder can be shown.
     1524            control.container.find( '.edit-menu-item-title' ).on( 'blur', function() {
     1525                $( this ).val( $.trim( $( this ).val() ) );
     1526            } );
     1527
     1528            titleEl = control.container.find( '.menu-item-title' );
    15231529            control.setting.bind( function( item ) {
     1530                var trimmedTitle, titleText;
    15241531                if ( ! item ) {
    15251532                    return;
    15261533                }
    1527 
    1528                 var titleEl = control.container.find( '.menu-item-title' ),
    1529                     titleText = item.title || item.original_title || api.Menus.data.l10n.untitled;
     1534                trimmedTitle = $.trim( item.title );
     1535
     1536                titleText = trimmedTitle || item.original_title || api.Menus.data.l10n.untitled;
    15301537
    15311538                if ( item._invalid ) {
     
    15341541
    15351542                // Don't update to an empty title.
    1536                 if ( item.title || item.original_title ) {
     1543                if ( trimmedTitle || item.original_title ) {
    15371544                    titleEl
    15381545                        .text( titleText )
Note: See TracChangeset for help on using the changeset viewer.