413 | | $( '.item-edit' ).each( function() { |
414 | | var thisLink, thisLinkText, primaryItems, itemPosition, title, |
415 | | parentItem, parentItemId, parentItemName, subItems, |
416 | | $this = $(this), |
417 | | menuItem = $this.closest( 'li.menu-item' ).first(), |
418 | | depth = menuItem.menuItemDepth(), |
419 | | isPrimaryMenuItem = ( 0 === depth ), |
420 | | itemName = $this.closest( '.menu-item-handle' ).find( '.menu-item-title' ).text(), |
421 | | position = parseInt( menuItem.index(), 10 ), |
422 | | prevItemDepth = ( isPrimaryMenuItem ) ? depth : parseInt( depth - 1, 10 ), |
423 | | prevItemNameLeft = menuItem.prevAll('.menu-item-depth-' + prevItemDepth).first().find( '.menu-item-title' ).text(), |
424 | | prevItemNameRight = menuItem.prevAll('.menu-item-depth-' + depth).first().find( '.menu-item-title' ).text(), |
425 | | totalMenuItems = $('#menu-to-edit li').length, |
426 | | hasSameDepthSibling = menuItem.nextAll( '.menu-item-depth-' + depth ).length; |
| 420 | var thisLink, thisLinkText, primaryItems, itemPosition, title, |
| 421 | parentItem, parentItemId, parentItemName, subItems, |
| 422 | $this = $( itemToRefresh ), |
| 423 | menuItem = $this.closest( 'li.menu-item' ).first(), |
| 424 | depth = menuItem.menuItemDepth(), |
| 425 | isPrimaryMenuItem = ( 0 === depth ), |
| 426 | itemName = $this.closest( '.menu-item-handle' ).find( '.menu-item-title' ).text(), |
| 427 | position = parseInt( menuItem.index(), 10 ), |
| 428 | prevItemDepth = ( isPrimaryMenuItem ) ? depth : parseInt( depth - 1, 10 ), |
| 429 | prevItemNameLeft = menuItem.prevAll('.menu-item-depth-' + prevItemDepth).first().find( '.menu-item-title' ).text(), |
| 430 | prevItemNameRight = menuItem.prevAll('.menu-item-depth-' + depth).first().find( '.menu-item-title' ).text(), |
| 431 | totalMenuItems = $('#menu-to-edit li').length, |
| 432 | hasSameDepthSibling = menuItem.nextAll( '.menu-item-depth-' + depth ).length; |
449 | | if ( ! isPrimaryMenuItem ) { |
450 | | thisLink = menuItem.find( '.menus-move-left' ), |
451 | | thisLinkText = menus.outFrom.replace( '%s', prevItemNameLeft ); |
452 | | thisLink.prop( 'title', menus.moveOutFrom.replace( '%s', prevItemNameLeft ) ).html( thisLinkText ).css( 'display', 'inline' ); |
453 | | } |
| 455 | if ( ! isPrimaryMenuItem ) { |
| 456 | thisLink = menuItem.find( '.menus-move-left' ), |
| 457 | thisLinkText = menus.outFrom.replace( '%s', prevItemNameLeft ); |
| 458 | thisLink.prop( 'title', menus.moveOutFrom.replace( '%s', prevItemNameLeft ) ).html( thisLinkText ).css( 'display', 'inline' ); |
| 459 | } |
455 | | if ( 0 !== position ) { |
456 | | if ( menuItem.find( '.menu-item-data-parent-id' ).val() !== menuItem.prev().find( '.menu-item-data-db-id' ).val() ) { |
457 | | thisLink = menuItem.find( '.menus-move-right' ), |
458 | | thisLinkText = menus.under.replace( '%s', prevItemNameRight ); |
459 | | thisLink.prop( 'title', menus.moveUnder.replace( '%s', prevItemNameRight ) ).html( thisLinkText ).css( 'display', 'inline' ); |
460 | | } |
| 461 | if ( 0 !== position ) { |
| 462 | if ( menuItem.find( '.menu-item-data-parent-id' ).val() !== menuItem.prev().find( '.menu-item-data-db-id' ).val() ) { |
| 463 | thisLink = menuItem.find( '.menus-move-right' ), |
| 464 | thisLinkText = menus.under.replace( '%s', prevItemNameRight ); |
| 465 | thisLink.prop( 'title', menus.moveUnder.replace( '%s', prevItemNameRight ) ).html( thisLinkText ).css( 'display', 'inline' ); |
463 | | if ( isPrimaryMenuItem ) { |
464 | | primaryItems = $( '.menu-item-depth-0' ), |
465 | | itemPosition = primaryItems.index( menuItem ) + 1, |
466 | | totalMenuItems = primaryItems.length, |
| 469 | if ( isPrimaryMenuItem ) { |
| 470 | primaryItems = $( '.menu-item-depth-0' ), |
| 471 | itemPosition = primaryItems.index( menuItem ) + 1, |
| 472 | totalMenuItems = primaryItems.length, |
468 | | // String together help text for primary menu items |
469 | | title = menus.menuFocus.replace( '%1$s', itemName ).replace( '%2$d', itemPosition ).replace( '%3$d', totalMenuItems ); |
470 | | } else { |
471 | | parentItem = menuItem.prevAll( '.menu-item-depth-' + parseInt( depth - 1, 10 ) ).first(), |
472 | | parentItemId = parentItem.find( '.menu-item-data-db-id' ).val(), |
473 | | parentItemName = parentItem.find( '.menu-item-title' ).text(), |
474 | | subItems = $( '.menu-item .menu-item-data-parent-id[value="' + parentItemId + '"]' ), |
475 | | itemPosition = $( subItems.parents('.menu-item').get().reverse() ).index( menuItem ) + 1; |
| 474 | // String together help text for primary menu items |
| 475 | title = menus.menuFocus.replace( '%1$s', itemName ).replace( '%2$d', itemPosition ).replace( '%3$d', totalMenuItems ); |
| 476 | } else { |
| 477 | parentItem = menuItem.prevAll( '.menu-item-depth-' + parseInt( depth - 1, 10 ) ).first(), |
| 478 | parentItemId = parentItem.find( '.menu-item-data-db-id' ).val(), |
| 479 | parentItemName = parentItem.find( '.menu-item-title' ).text(), |
| 480 | subItems = $( '.menu-item .menu-item-data-parent-id[value="' + parentItemId + '"]' ), |
| 481 | itemPosition = $( subItems.parents('.menu-item').get().reverse() ).index( menuItem ) + 1; |