From 4a849e7c24093635d60909ab4c6c41f8e372c3e2 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 13 Jul 2015 08:39:17 +0000 Subject: [PATCH] Customizer: Disambiguate a menu's auto-add pages option from preceding menu location checkboxes. Creates a separate `nav_menu_auto_add` control type following the pattern of the `nav_menu_name` control type. Props valendesigns. Fixes #32820. git-svn-id: https://develop.svn.wordpress.org/trunk@33189 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/js/customize-nav-menus.js | 95 ++++++++++++++----- .../class-wp-customize-control.php | 48 ++++++++-- .../class-wp-customize-nav-menus.php | 1 + 3 files changed, 113 insertions(+), 31 deletions(-) diff --git a/src/wp-admin/js/customize-nav-menus.js b/src/wp-admin/js/customize-nav-menus.js index e745561cde..b7bb7a0643 100644 --- a/src/wp-admin/js/customize-nav-menus.js +++ b/src/wp-admin/js/customize-nav-menus.js @@ -676,7 +676,7 @@ }, populateControls: function() { - var section = this, menuNameControlId, menuControl, menuNameControl; + var section = this, menuNameControlId, menuAutoAddControlId, menuControl, menuNameControl, menuAutoAddControl; // Add the control for managing the menu name. menuNameControlId = section.id + '[name]'; @@ -685,7 +685,7 @@ menuNameControl = new api.controlConstructor.nav_menu_name( menuNameControlId, { params: { type: 'nav_menu_name', - content: '
  • ', // @todo core should do this for us + content: '
  • ', // @todo core should do this for us; see #30741 label: '', active: true, section: section.id, @@ -705,9 +705,9 @@ menuControl = new api.controlConstructor.nav_menu( section.id, { params: { type: 'nav_menu', - content: '
  • ', // @todo core should do this for us + content: '
  • ', // @todo core should do this for us; see #30741 section: section.id, - priority: 999, + priority: 998, active: true, settings: { 'default': section.id @@ -719,6 +719,27 @@ menuControl.active.set( true ); } + // Add the control for managing the menu auto_add. + menuAutoAddControlId = section.id + '[auto_add]'; + menuAutoAddControl = api.control( menuAutoAddControlId ); + if ( ! menuAutoAddControl ) { + menuAutoAddControl = new api.controlConstructor.nav_menu_auto_add( menuAutoAddControlId, { + params: { + type: 'nav_menu_auto_add', + content: '
  • ', // @todo core should do this for us + label: '', + active: true, + section: section.id, + priority: 999, + settings: { + 'default': section.id + } + } + } ); + api.control.add( menuAutoAddControl.id, menuAutoAddControl ); + menuAutoAddControl.active.set( true ); + } + }, /** @@ -1591,6 +1612,52 @@ }); + /** + * wp.customize.Menus.MenuAutoAddControl + * + * Customizer control for a nav menu's auto add. + * + * @constructor + * @augments wp.customize.Control + */ + api.Menus.MenuAutoAddControl = api.Control.extend({ + + ready: function() { + var control = this, + settingValue = control.setting(); + + /* + * Since the control is not registered in PHP, we need to prevent the + * preview's sending of the activeControls to result in this control + * being deactivated. + */ + control.active.validate = function() { + return api.section( control.section() ).active(); + }; + + control.autoAddElement = new api.Element( control.container.find( 'input[type=checkbox].auto_add' ) ); + + control.autoAddElement.bind(function( value ) { + var settingValue = control.setting(); + if ( settingValue && settingValue.name !== value ) { + settingValue = _.clone( settingValue ); + settingValue.auto_add = value; + control.setting.set( settingValue ); + } + }); + if ( settingValue ) { + control.autoAddElement.set( settingValue.auto_add ); + } + + control.setting.bind(function( object ) { + if ( object ) { + control.autoAddElement.set( object.auto_add ); + } + }); + } + + }); + /** * wp.customize.Menus.MenuControl * @@ -1662,25 +1729,6 @@ var control = this, menuId = control.params.menu_id; - control.elements = {}; - control.elements.auto_add = new api.Element( control.container.find( 'input[type=checkbox].auto_add' ) ); - - control.elements.auto_add.bind(function( auto_add ) { - var settingValue = control.setting(); - if ( settingValue && settingValue.auto_add !== auto_add ) { - settingValue = _.clone( settingValue ); - settingValue.auto_add = auto_add; - control.setting.set( settingValue ); - } - }); - control.elements.auto_add.set( control.setting().auto_add ); - control.setting.bind(function( object ) { - if ( ! object ) { - return; - } - control.elements.auto_add.set( object.auto_add ); - }); - control.setting.bind( function( to ) { var name; if ( false === to ) { @@ -2244,6 +2292,7 @@ nav_menu_item: api.Menus.MenuItemControl, nav_menu: api.Menus.MenuControl, nav_menu_name: api.Menus.MenuNameControl, + nav_menu_auto_add: api.Menus.MenuAutoAddControl, new_menu: api.Menus.NewMenuControl }); diff --git a/src/wp-includes/class-wp-customize-control.php b/src/wp-includes/class-wp-customize-control.php index 6aad58eb9b..09ab176f32 100644 --- a/src/wp-includes/class-wp-customize-control.php +++ b/src/wp-includes/class-wp-customize-control.php @@ -1603,14 +1603,7 @@ class WP_Customize_Nav_Menu_Control extends WP_Customize_Control { - -

    - -

    - + + manager->register_panel_type( 'WP_Customize_Nav_Menus_Panel' ); $this->manager->register_control_type( 'WP_Customize_Nav_Menu_Control' ); $this->manager->register_control_type( 'WP_Customize_Nav_Menu_Name_Control' ); + $this->manager->register_control_type( 'WP_Customize_Nav_Menu_Auto_Add_Control' ); $this->manager->register_control_type( 'WP_Customize_Nav_Menu_Item_Control' ); // Create a panel for Menus.