Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.

Improve nav menus integration #289

Merged
merged 2 commits into from
Sep 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions js/customize-nav-menus-posts-extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,20 @@ wp.customize.Posts.NavMenusExtensions = (function( api, $ ) {
if ( ! oldPostData || newPostData.post_title !== oldPostData.post_title ) {
title = $.trim( newPostData.post_title ) || api.Posts.data.l10n.noTitle;
}
control.container.find( '.menu-item-actions > .link-to-original > .original-link' ).text( title );
control.container.find( '.edit-menu-item-title:first' ).attr( 'placeholder', title );

// Change original_title without triggering setting change since it's a readonly value.
if ( 'resolved' === control.deferred.embedded.state() ) {
control.container.find( '.menu-item-actions > .link-to-original > .original-link' ).text( title );
control.container.find( '.edit-menu-item-title:first' ).attr( 'placeholder', title );
}

// Update original_title.
settingValue = _.clone( control.setting.get() );
settingValue.original_title = newPostData.post_title;
control.setting.set( settingValue );
if ( settingValue.title ) {
control.setting._value = settingValue; // Set quietly since the original_value will be unused here.
} else {
control.setting.set( settingValue );
}
};
postSetting.bind( setOriginalLinkTitle );
setOriginalLinkTitle( postSetting.get(), null );
Expand All @@ -117,6 +124,8 @@ wp.customize.Posts.NavMenusExtensions = (function( api, $ ) {
var onceExpanded;
if ( control.extended( api.Menus.MenuItemControl ) ) {

component.syncOriginalItemTitle( control );

/**
* Trigger once expanded.
*
Expand All @@ -127,7 +136,6 @@ wp.customize.Posts.NavMenusExtensions = (function( api, $ ) {
if ( expanded ) {
control.expanded.unbind( onceExpanded );
component.addEditPostButton( control );
component.syncOriginalItemTitle( control );
}
};

Expand All @@ -144,8 +152,6 @@ wp.customize.Posts.NavMenusExtensions = (function( api, $ ) {
/**
* Update available menu items to match a changing post title.
*
* @todo The ajax requests for search-available-menu-items-customizer and load-available-menu-items-customizer need to include the customized state.
*
* @param {wp.customize.Setting} setting Changed setting.
* @returns {void}
*/
Expand Down
22 changes: 6 additions & 16 deletions js/customize-posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -656,12 +656,6 @@
/**
* Handle creating a new page.
*
* This is adapted from the Customize Object Selector plugin.
*
* @todo Customize Object Selector can eliminate its copies.
*
* @link https://github.com/xwp/wp-customize-object-selector/blob/d1ce38f7b14eff4f2ce9c59c93b6e356e7c0912f/js/customize-object-selector-component.js#L337-L425
*
* @param {object} args Args.
* @param {String} args.postType - Post type.
* @param {jQuery} [args.initiatingButton] - Clicked button which will be disabled during the request, and re-focused if returnToOriginatingConstruct is true.
Expand Down Expand Up @@ -779,9 +773,6 @@
/**
* Handle editing an existing page.
*
* This is adapted from the Customize Object Selector plugin.
*
* @link https://github.com/xwp/wp-customize-object-selector/blob/d1ce38f7b14eff4f2ce9c59c93b6e356e7c0912f/js/customize-object-selector-component.js#L337-L425
* @param {object} args Args.
* @param {Number} args.postId - Post type.
* @param {jQuery} [args.initiatingButton] - Clicked button which will be disabled during the request, and re-focused if returnToOriginatingConstruct is true.
Expand Down Expand Up @@ -885,9 +876,6 @@
* This overrides the back button to serve the purpose of breadcrumb navigation.
* This is modified from WP Core.
*
* This is copied from the Customize Object Selector plugin.
*
* @link https://github.com/xwp/wp-customize-object-selector/blob/d1ce38f7b14eff4f2ce9c59c93b6e356e7c0912f/js/customize-object-selector-component.js#L427-L466
* @link https://github.com/xwp/wordpress-develop/blob/e7bbb482d6069d9c2d0e33789c7d290ac231f056/src/wp-admin/js/customize-widgets.js#L2143-L2193
* @param {wp.customize.Section|wp.customize.Panel|wp.customize.Control} focusConstruct - The object to initially focus.
* @param {wp.customize.Section|wp.customize.Panel|wp.customize.Control} returnConstruct - The object to return focus.
Expand Down Expand Up @@ -930,9 +918,6 @@
* early can result in the focus logic not being able to see
* any visible inputs to focus on.
*
* This is copied from the Customize Object Selector plugin.
*
* @link https://github.com/xwp/wp-customize-object-selector/blob/d1ce38f7b14eff4f2ce9c59c93b6e356e7c0912f/js/customize-object-selector-component.js#L468-L502
* @param {wp.customize.Section} section Section.
* @returns {void}
*/
Expand All @@ -950,7 +935,12 @@
_.delay( function focusControlAfterDelay() {
firstControl.focus( {
completeCallback: function() {
firstControl.container.find( 'input:first' ).select();
var input = firstControl.container.find( 'input:first' );
if ( input.val() === api.Posts.data.l10n.noTitle ) {
input.select();
} else {
input.focus();
}
}
} );
}, delay );
Expand Down