|
298 | 298 |
|
299 | 299 | $.each( parentDropdowns, function() { |
300 | 300 | var parentDropdown = $( this ), |
301 | | - $html = '', |
302 | | - $selected = '', |
303 | | - currentItemID = parentDropdown.closest( 'li.menu-item' ).find( '.menu-item-data-db-id' ).val(), |
304 | | - currentparentID = parentDropdown.closest( 'li.menu-item' ).find( '.menu-item-data-parent-id' ).val(), |
| 301 | + currentItemID = parseInt( parentDropdown.closest( 'li.menu-item' ).find( '.menu-item-data-db-id' ).val() ), |
| 302 | + currentParentID = parseInt( parentDropdown.closest( 'li.menu-item' ).find( '.menu-item-data-parent-id' ).val() ), |
305 | 303 | currentItem = parentDropdown.closest( 'li.menu-item' ), |
306 | 304 | currentMenuItemChild = currentItem.childMenuItems(), |
307 | | - excludeMenuItem = [ currentItemID ]; |
| 305 | + excludeMenuItem = /** @type {number[]} */ [ currentItemID ]; |
| 306 | + |
| 307 | + parentDropdown.empty(); |
308 | 308 |
|
309 | 309 | if ( currentMenuItemChild.length > 0 ) { |
310 | 310 | $.each( currentMenuItemChild, function(){ |
311 | 311 | var childItem = $(this), |
312 | | - childID = childItem.find( '.menu-item-data-db-id' ).val(); |
| 312 | + childID = parseInt( childItem.find( '.menu-item-data-db-id' ).val() ); |
313 | 313 |
|
314 | 314 | excludeMenuItem.push( childID ); |
315 | 315 | }); |
316 | 316 | } |
317 | 317 |
|
318 | | - if ( currentparentID == 0 ) { |
319 | | - $selected = 'selected'; |
320 | | - } |
321 | | - |
322 | | - $html += '<option ' + $selected + ' value="0">' + wp.i18n._x( 'No Parent', 'menu item without a parent in navigation menu' ) + '</option>'; |
| 318 | + parentDropdown.append( |
| 319 | + $( '<option>', { |
| 320 | + value: '0', |
| 321 | + selected: currentParentID === 0, |
| 322 | + text: wp.i18n._x( 'No Parent', 'menu item without a parent in navigation menu' ), |
| 323 | + } ) |
| 324 | + ); |
323 | 325 |
|
324 | 326 | $.each( menuItems, function() { |
325 | 327 | var menuItem = $(this), |
326 | | - $selected = '', |
327 | | - menuID = menuItem.find( '.menu-item-data-db-id' ).val(), |
| 328 | + menuID = parseInt( menuItem.find( '.menu-item-data-db-id' ).val() ), |
328 | 329 | menuTitle = menuItem.find( '.edit-menu-item-title' ).val(); |
329 | 330 |
|
330 | 331 | if ( ! excludeMenuItem.includes( menuID ) ) { |
331 | | - if ( currentparentID == menuID ) { |
332 | | - $selected = 'selected'; |
333 | | - } |
334 | | - $html += '<option ' + $selected + ' value="' + menuID + '">' + menuTitle + '</option>'; |
| 332 | + parentDropdown.append( |
| 333 | + $( '<option>', { |
| 334 | + value: menuID.toString(), |
| 335 | + selected: currentParentID === menuID, |
| 336 | + text: menuTitle, |
| 337 | + } ) |
| 338 | + ); |
335 | 339 | } |
336 | 340 | }); |
337 | | - |
338 | | - parentDropdown.html( $html ); |
339 | 341 | }); |
340 | 342 |
|
341 | 343 | }); |
|
349 | 351 | var orderDropdown = $( this ), |
350 | 352 | menuItem = orderDropdown.closest( 'li.menu-item' ).first(), |
351 | 353 | depth = menuItem.menuItemDepth(), |
352 | | - isPrimaryMenuItem = ( 0 === depth ), |
353 | | - $html = '', |
354 | | - $selected = ''; |
| 354 | + isPrimaryMenuItem = ( 0 === depth ); |
| 355 | + |
| 356 | + orderDropdown.empty(); |
355 | 357 |
|
356 | 358 | if ( isPrimaryMenuItem ) { |
357 | 359 | var primaryItems = $( '.menu-item-depth-0' ), |
|
360 | 362 | itemPosition = primaryItems.index( menuItem ) + 1; |
361 | 363 |
|
362 | 364 | for ( let i = 1; i < totalMenuItems + 1; i++ ) { |
363 | | - $selected = ''; |
364 | | - if ( i == itemPosition ) { |
365 | | - $selected = 'selected'; |
366 | | - } |
367 | | - var itemString = wp.i18n.sprintf( |
| 365 | + var itemString = wp.i18n.sprintf( |
368 | 366 | /* translators: 1: The current menu item number, 2: The total number of menu items. */ |
369 | 367 | wp.i18n._x( '%1$s of %2$s', 'part of a total number of menu items' ), |
370 | 368 | i, |
371 | 369 | totalMenuItems |
372 | 370 | ); |
373 | | - $html += '<option ' + $selected + ' value="' + i + '">' + itemString + '</option>'; |
| 371 | + orderDropdown.append( |
| 372 | + $( '<option>', { |
| 373 | + selected: i === itemPosition, |
| 374 | + value: i.toString(), |
| 375 | + text: itemString, |
| 376 | + } ) |
| 377 | + ); |
374 | 378 | } |
375 | 379 |
|
376 | 380 | } else { |
|
382 | 386 | itemPosition = $( subItems.parents('.menu-item').get().reverse() ).index( menuItem ) + 1; |
383 | 387 |
|
384 | 388 | for ( let i = 1; i < totalSubMenuItems + 1; i++ ) { |
385 | | - $selected = ''; |
386 | | - if ( i == itemPosition ) { |
387 | | - $selected = 'selected'; |
388 | | - } |
389 | | - var submenuString = wp.i18n.sprintf( |
| 389 | + var submenuString = wp.i18n.sprintf( |
390 | 390 | /* translators: 1: The current submenu item number, 2: The total number of submenu items. */ |
391 | 391 | wp.i18n._x( '%1$s of %2$s', 'part of a total number of menu items' ), |
392 | 392 | i, |
393 | 393 | totalSubMenuItems |
394 | 394 | ); |
395 | | - $html += '<option ' + $selected + ' value="' + i + '">' + submenuString + '</option>'; |
| 395 | + orderDropdown.append( |
| 396 | + $( '<option>', { |
| 397 | + selected: i === itemPosition, |
| 398 | + value: i.toString(), |
| 399 | + text: submenuString, |
| 400 | + } ) |
| 401 | + ); |
396 | 402 | } |
397 | 403 |
|
398 | 404 | } |
399 | | - |
400 | | - orderDropdown.html( $html ); |
401 | 405 | }); |
402 | 406 |
|
403 | 407 | }); |
|
1290 | 1294 | } |
1291 | 1295 |
|
1292 | 1296 | if ( this.checked === true ) { |
1293 | | - $( '#pending-menu-items-to-delete ul' ).append( |
1294 | | - '<li data-menu-item-id="' + menuItemID + '">' + |
1295 | | - '<span class="pending-menu-item-name">' + menuItemName + '</span> ' + |
1296 | | - '<span class="pending-menu-item-type">(' + menuItemType + ')</span>' + |
1297 | | - '<span class="separator"></span>' + |
1298 | | - '</li>' |
1299 | | - ); |
| 1297 | + const $li = $( '<li>', { 'data-menu-item-id': menuItemID } ); |
| 1298 | + $li.append( $( '<span>', { |
| 1299 | + 'class': 'pending-menu-item-name', |
| 1300 | + text: menuItemName |
| 1301 | + } ) ); |
| 1302 | + $li.append( ' ' ); |
| 1303 | + $li.append( $( '<span>', { |
| 1304 | + 'class': 'pending-menu-item-type', |
| 1305 | + text: '(' + menuItemType + ')', |
| 1306 | + } ) ); |
| 1307 | + $li.append( $( '<span>', { 'class': 'separator' } ) ); |
| 1308 | + $( '#pending-menu-items-to-delete ul' ).append( $li ); |
1300 | 1309 | } |
1301 | 1310 |
|
1302 | 1311 | $( '#pending-menu-items-to-delete li .separator' ).html( ', ' ); |
|
1699 | 1708 | }, |
1700 | 1709 |
|
1701 | 1710 | eventOnClickMenuSave : function() { |
1702 | | - var locs = '', |
1703 | | - menuName = $('#menu-name'), |
1704 | | - menuNameVal = menuName.val(); |
| 1711 | + var menuName = $('#menu-name'), |
| 1712 | + menuNameVal = menuName.val(); |
1705 | 1713 |
|
1706 | 1714 | // Cancel and warn if invalid menu name. |
1707 | 1715 | if ( ! menuNameVal || ! menuNameVal.replace( /\s+/, '' ) ) { |
1708 | 1716 | menuName.parent().addClass( 'form-invalid' ); |
1709 | 1717 | return false; |
1710 | 1718 | } |
1711 | 1719 | // Copy menu theme locations. |
| 1720 | + // Note: This appears to be dead code since #nav-menu-theme-locations no longer exists, perhaps removed in r32842. |
| 1721 | + var $updateNavMenu = $('#update-nav-menu'); |
1712 | 1722 | $('#nav-menu-theme-locations select').each(function() { |
1713 | | - locs += '<input type="hidden" name="' + this.name + '" value="' + $(this).val() + '" />'; |
| 1723 | + $updateNavMenu.append( |
| 1724 | + $( '<input>', { |
| 1725 | + type: 'hidden', |
| 1726 | + name: this.name, |
| 1727 | + value: $( this ).val(), |
| 1728 | + } ) |
| 1729 | + ); |
1714 | 1730 | }); |
1715 | | - $('#update-nav-menu').append( locs ); |
1716 | 1731 | // Update menu item position data. |
1717 | 1732 | api.menuList.find('.menu-item-data-position').val( function(index) { return index + 1; } ); |
1718 | 1733 | window.onbeforeunload = null; |
|
1755 | 1770 | $item; |
1756 | 1771 |
|
1757 | 1772 | if( ! $items.length ) { |
1758 | | - $('.categorychecklist', panel).html( '<li><p>' + wp.i18n.__( 'No results found.' ) + '</p></li>' ); |
| 1773 | + const li = $( '<li>' ); |
| 1774 | + const p = $( '<p>', { text: wp.i18n.__( 'No results found.' ) } ); |
| 1775 | + li.append( p ); |
| 1776 | + $('.categorychecklist', panel).empty().append( li ); |
1759 | 1777 | $( '.spinner', panel ).removeClass( 'is-active' ); |
1760 | 1778 | wrapper.addClass( 'has-no-menu-item' ); |
1761 | 1779 | return; |
|
0 commit comments