return;
}
section = api.section( sectionId );
- if ( section && section.expanded() ) {
+ if ( ( section && section.expanded() ) || api.settings.autofocus.control === control.id ) {
control.actuallyEmbed();
}
},
}
});
if ( settingValue ) {
- element.set( settingValue[ property ] );
+ if ( ( property === 'classes' || property === 'xfn' ) && _.isArray( settingValue[ property ] ) ) {
+ element.set( settingValue[ property ].join( ' ' ) );
+ } else {
+ element.set( settingValue[ property ] );
+ }
}
});
return;
}
- var titleEl = control.container.find( '.menu-item-title' );
+ var titleEl = control.container.find( '.menu-item-title' ),
+ titleText = item.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 ) {
titleEl
- .text( item.title )
+ .text( titleText )
.removeClass( 'no-title' );
} else {
titleEl
- .text( api.Menus.data.l10n.untitled )
+ .text( titleText )
.addClass( 'no-title' );
}
} );
'menu-item-edit-inactive'
];
- if ( settingValue.invalid ) {
- containerClasses.push( 'invalid' );
- control.params.title = api.Menus.data.invalidTitleTpl.replace( '%s', control.params.title );
+ if ( settingValue._invalid ) {
+ containerClasses.push( 'menu-item-invalid' );
+ control.params.title = api.Menus.data.l10n.invalidTitleTpl.replace( '%s', control.params.title );
} else if ( 'draft' === settingValue.status ) {
containerClasses.push( 'pending' );
control.params.title = api.Menus.data.pendingTitleTpl.replace( '%s', control.params.title );
* the first input in the control.
*/
focus: function() {
- this.expandControlSection();
- this.expandForm();
- this.container.find( '.menu-item-settings :focusable:first' ).focus();
+ var control = this, focusable;
+ control.expandControlSection();
+ control.expandForm();
+ // Note that we can't use :focusable due to a jQuery UI issue. See: https://github.com/jquery/jquery-ui/pull/1583
+ focusable = control.container.find( '.menu-item-settings' ).find( 'input, select, textarea, button, object, a[href], [tabindex]' ).filter( ':visible' );
+ focusable.first().focus();
},
/**
control.isSorting = false;
+ // Reset horizontal scroll position when done dragging.
+ control.$sectionContent.scrollLeft( 0 );
+
_.each( menuItemContainerIds, function( menuItemContainerId ) {
var menuItemId, menuItemControl, matches;
matches = menuItemContainerId.match( /^customize-control-nav_menu_item-(-?\d+)$/, '' );
*/
api.Menus.applySavedData = function( data ) {
- var insertedMenuIdMapping = {};
+ var insertedMenuIdMapping = {}, insertedMenuItemIdMapping = {};
_( data.nav_menu_updates ).each(function( update ) {
var oldCustomizeId, newCustomizeId, customizeId, oldSetting, newSetting, setting, settingValue, oldSection, newSection, wasSaved, widgetTemplate, navMenuCount;
}
} );
+ // Build up mapping of nav_menu_item placeholder IDs to inserted IDs.
+ _( data.nav_menu_item_updates ).each(function( update ) {
+ if ( update.previous_post_id ) {
+ insertedMenuItemIdMapping[ update.previous_post_id ] = update.post_id;
+ }
+ });
+
_( data.nav_menu_item_updates ).each(function( update ) {
var oldCustomizeId, newCustomizeId, oldSetting, newSetting, settingValue, oldControl, newControl;
if ( 'inserted' === update.status ) {
}
settingValue = _.clone( settingValue );
+ // If the parent menu item was also inserted, update the menu_item_parent to the new ID.
+ if ( settingValue.menu_item_parent < 0 ) {
+ if ( ! insertedMenuItemIdMapping[ settingValue.menu_item_parent ] ) {
+ throw new Error( 'inserted ID for menu_item_parent not available' );
+ }
+ settingValue.menu_item_parent = insertedMenuItemIdMapping[ settingValue.menu_item_parent ];
+ }
+
// If the menu was also inserted, then make sure it uses the new menu ID for nav_menu_term_id.
if ( insertedMenuIdMapping[ settingValue.nav_menu_term_id ] ) {
settingValue.nav_menu_term_id = insertedMenuIdMapping[ settingValue.nav_menu_term_id ];