From 96f845d1a764d4a0de7ebef43b6768976cf614c5 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 16 Feb 2020 06:25:54 +0000 Subject: [PATCH] Menus: Restore the title of the currently active/expanded menu item when clicking "Cancel" after editing. Other inputs are already restored to their previous values in that case. Props Girishpanchal, nilamacharya, JoshuaWold, welcher, SergeyBiryukov. Fixes #43031. git-svn-id: https://develop.svn.wordpress.org/trunk@47294 602fd350-edb4-49c9-b593-d223f7449a82 --- src/js/_enqueues/lib/nav-menu.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/js/_enqueues/lib/nav-menu.js b/src/js/_enqueues/lib/nav-menu.js index 3a0bd642ef..221007d65d 100644 --- a/src/js/_enqueues/lib/nav-menu.js +++ b/src/js/_enqueues/lib/nav-menu.js @@ -1162,6 +1162,7 @@ eventOnClickEditLink : function(clickedEl) { var settings, item, matchedSection = /#(.*)$/.exec(clickedEl.href); + if ( matchedSection && matchedSection[1] ) { settings = $('#'+matchedSection[1]); item = settings.parent(); @@ -1186,8 +1187,12 @@ eventOnClickCancelLink : function(clickedEl) { var settings = $( clickedEl ).closest( '.menu-item-settings' ), thisMenuItem = $( clickedEl ).closest( '.menu-item' ); - thisMenuItem.removeClass('menu-item-edit-active').addClass('menu-item-edit-inactive'); - settings.setItemData( settings.data('menu-item-data') ).hide(); + + thisMenuItem.removeClass( 'menu-item-edit-active' ).addClass( 'menu-item-edit-inactive' ); + settings.setItemData( settings.data( 'menu-item-data' ) ).hide(); + // Restore the title of the currently active/expanded menu item. + thisMenuItem.find( '.menu-item-title' ).text( settings.data( 'menu-item-data' )['menu-item-title'] ); + return false; }, @@ -1195,6 +1200,7 @@ var locs = '', menuName = $('#menu-name'), menuNameVal = menuName.val(); + // Cancel and warn if invalid menu name. if ( ! menuNameVal || ! menuNameVal.replace( /\s+/, '' ) ) { menuName.parent().addClass( 'form-invalid' ); @@ -1223,6 +1229,7 @@ eventOnClickMenuItemDelete : function(clickedEl) { var itemID = parseInt(clickedEl.id.replace('delete-', ''), 10); + api.removeMenuItem( $('#menu-item-' + itemID) ); api.registerChange(); return false;