Changeset 42034
- Timestamp:
- 10/28/2017 05:47:06 AM (7 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/js/customize-nav-menus.js
r41930 r42034 1163 1163 1164 1164 /** 1165 * Create a nav menu setting and section. 1166 * 1167 * @since 4.9.0 1168 * 1169 * @param {string} [name=''] Nav menu name. 1170 * @returns {wp.customize.Menus.MenuSection} Added nav menu. 1171 */ 1172 api.Menus.createNavMenu = function createNavMenu( name ) { 1173 var customizeId, placeholderId, setting; 1174 placeholderId = api.Menus.generatePlaceholderAutoIncrementId(); 1175 1176 customizeId = 'nav_menu[' + String( placeholderId ) + ']'; 1177 1178 // Register the menu control setting. 1179 setting = api.create( customizeId, customizeId, {}, { 1180 type: 'nav_menu', 1181 transport: api.Menus.data.settingTransport, 1182 previewer: api.previewer 1183 } ); 1184 setting.set( $.extend( 1185 {}, 1186 api.Menus.data.defaultSettingValues.nav_menu, 1187 { 1188 name: name || '' 1189 } 1190 ) ); 1191 1192 /* 1193 * Add the menu section (and its controls). 1194 * Note that this will automatically create the required controls 1195 * inside via the Section's ready method. 1196 */ 1197 return api.section.add( new api.Menus.MenuSection( customizeId, { 1198 panel: 'nav_menus', 1199 title: displayNavMenuName( name ), 1200 customizeAction: api.Menus.data.l10n.customizingMenus, 1201 priority: 10, 1202 menu_id: placeholderId 1203 } ) ); 1204 }; 1205 1206 /** 1165 1207 * wp.customize.Menus.NewMenuSection 1166 1208 * … … 1340 1382 nameInput = contentContainer.find( '.menu-name-field' ).first(), 1341 1383 name = nameInput.val(), 1342 menuSection, 1343 customizeId, 1344 editMenuSection, 1345 placeholderId = api.Menus.generatePlaceholderAutoIncrementId(); 1384 menuSection; 1346 1385 1347 1386 if ( ! name ) { … … 1351 1390 } 1352 1391 1353 customizeId = 'nav_menu[' + String( placeholderId ) + ']'; 1354 1355 // Register the menu control setting. 1356 api.create( customizeId, customizeId, {}, { 1357 type: 'nav_menu', 1358 transport: api.Menus.data.settingTransport, 1359 previewer: api.previewer 1360 } ); 1361 api( customizeId ).set( $.extend( 1362 {}, 1363 api.Menus.data.defaultSettingValues.nav_menu, 1364 { 1365 name: name 1366 } 1367 ) ); 1368 1369 /* 1370 * Add the menu section (and its controls). 1371 * Note that this will automatically create the required controls 1372 * inside via the Section's ready method. 1373 */ 1374 menuSection = new api.Menus.MenuSection( customizeId, { 1375 panel: 'nav_menus', 1376 title: displayNavMenuName( name ), 1377 customizeAction: api.Menus.data.l10n.customizingMenus, 1378 priority: 10, 1379 menu_id: placeholderId 1380 } ); 1381 api.section.add( customizeId, menuSection ); 1392 menuSection = api.Menus.createNavMenu( name ); 1382 1393 1383 1394 // Clear name field. … … 1391 1402 if ( checkbox.prop( 'checked' ) ) { 1392 1403 navMenuLocationSetting = api( 'nav_menu_locations[' + checkbox.data( 'location-id' ) + ']' ); 1393 navMenuLocationSetting.set( placeholderId );1404 navMenuLocationSetting.set( menuSection.params.menu_id ); 1394 1405 1395 1406 // Reset state for next new menu … … 1401 1412 1402 1413 // Focus on the new menu section. 1403 editMenuSection = api.section( customizeId ); 1404 editMenuSection.focus( { 1414 menuSection.focus( { 1405 1415 completeCallback: function() { 1406 editMenuSection.highlightNewItemButton();1407 } 1408 } ); // @todo should we focus on the new menu's control and open the add-items panel? Thinking user flow...1416 menuSection.highlightNewItemButton(); 1417 } 1418 } ); 1409 1419 }, 1410 1420 … … 3009 3019 3010 3020 /** 3021 * wp.customize.Menus.NewMenuControl 3022 * 3023 * Customizer control for creating new menus and handling deletion of existing menus. 3024 * Note that 'new_menu' must match the WP_Customize_New_Menu_Control::$type. 3025 * 3026 * @constructor 3027 * @augments wp.customize.Control 3028 * @deprecated 4.9.0 This class is no longer used due to new menu creation UX. 3029 */ 3030 api.Menus.NewMenuControl = api.Control.extend({ 3031 3032 /** 3033 * Initialize. 3034 * 3035 * @deprecated 4.9.0 3036 */ 3037 initialize: function() { 3038 if ( 'undefined' !== typeof console && console.warn ) { 3039 console.warn( '[DEPRECATED] wp.customize.NewMenuControl will be removed. Please use wp.customize.Menus.createNavMenu() instead.' ); 3040 } 3041 api.Control.prototype.initialize.apply( this, arguments ); 3042 }, 3043 3044 /** 3045 * Set up the control. 3046 * 3047 * @deprecated 4.9.0 3048 */ 3049 ready: function() { 3050 this._bindHandlers(); 3051 }, 3052 3053 _bindHandlers: function() { 3054 var self = this, 3055 name = $( '#customize-control-new_menu_name input' ), 3056 submit = $( '#create-new-menu-submit' ); 3057 name.on( 'keydown', function( event ) { 3058 if ( 13 === event.which ) { // Enter. 3059 self.submit(); 3060 } 3061 } ); 3062 submit.on( 'click', function( event ) { 3063 self.submit(); 3064 event.stopPropagation(); 3065 event.preventDefault(); 3066 } ); 3067 }, 3068 3069 /** 3070 * Create the new menu with the name supplied. 3071 * 3072 * @deprecated 4.9.0 3073 */ 3074 submit: function() { 3075 3076 var control = this, 3077 container = control.container.closest( '.accordion-section-new-menu' ), 3078 nameInput = container.find( '.menu-name-field' ).first(), 3079 name = nameInput.val(), 3080 menuSection; 3081 3082 if ( ! name ) { 3083 nameInput.addClass( 'invalid' ); 3084 nameInput.focus(); 3085 return; 3086 } 3087 3088 menuSection = api.Menus.createNavMenu( name ); 3089 3090 // Clear name field. 3091 nameInput.val( '' ); 3092 nameInput.removeClass( 'invalid' ); 3093 3094 wp.a11y.speak( api.Menus.data.l10n.menuAdded ); 3095 3096 // Focus on the new menu section. 3097 menuSection.focus(); 3098 } 3099 }); 3100 3101 /** 3011 3102 * Extends wp.customize.controlConstructor with control constructor for 3012 3103 * menu_location, menu_item, nav_menu, and new_menu. … … 3017 3108 nav_menu: api.Menus.MenuControl, 3018 3109 nav_menu_name: api.Menus.MenuNameControl, 3110 new_menu: api.Menus.NewMenuControl, // @todo Remove in 5.0. See #42364. 3019 3111 nav_menu_locations: api.Menus.MenuLocationsControl, 3020 3112 nav_menu_auto_add: api.Menus.MenuAutoAddControl -
trunk/src/wp-includes/class-wp-customize-control.php
r41935 r42034 770 770 /** 771 771 * WP_Customize_Nav_Menu_Name_Control class. 772 * 773 * As this file is deprecated, it will trigger a deprecation notice if instantiated. In a subsequent 774 * release, the require_once() here will be removed and _deprecated_file() will be called if file is 775 * required at all. 776 * 777 * @deprecated 4.9.0 This file is no longer used due to new menu creation UX. 772 778 */ 773 779 require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-name-control.php' ); -
trunk/src/wp-includes/class-wp-customize-manager.php
r42025 r42034 318 318 require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-locations-control.php' ); 319 319 require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-auto-add-control.php' ); 320 require_once( ABSPATH . WPINC . '/customize/class-wp-customize-new-menu-control.php' ); // @todo Remove in 5.0. See #42364. 320 321 321 322 require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menus-panel.php' ); … … 325 326 require_once( ABSPATH . WPINC . '/customize/class-wp-customize-sidebar-section.php' ); 326 327 require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-section.php' ); 328 require_once( ABSPATH . WPINC . '/customize/class-wp-customize-new-menu-section.php' ); // @todo Remove in 5.0. See #42364. 327 329 328 330 require_once( ABSPATH . WPINC . '/customize/class-wp-customize-custom-css-setting.php' ); -
trunk/src/wp-includes/class-wp-customize-section.php
r41768 r42034 386 386 /** WP_Customize_Nav_Menu_Section class */ 387 387 require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-section.php' ); 388 389 /** 390 * WP_Customize_New_Menu_Section class 391 * 392 * As this file is deprecated, it will trigger a deprecation notice if instantiated. In a subsequent 393 * release, the require_once() here will be removed and _deprecated_file() will be called if file is 394 * required at all. 395 * 396 * @deprecated 4.9.0 This file is no longer used due to new menu creation UX. 397 */ 398 require_once( ABSPATH . WPINC . '/customize/class-wp-customize-new-menu-section.php' ); -
trunk/src/wp-includes/customize/class-wp-customize-new-menu-control.php
r41162 r42034 6 6 * @subpackage Customize 7 7 * @since 4.4.0 8 * @deprecated 4.9.0 This file is no longer used as of the menu creation UX introduced in #40104. 8 9 */ 9 10 … … 12 13 * 13 14 * @since 4.3.0 15 * @deprecated 4.9.0 This class is no longer used as of the menu creation UX introduced in #40104. 14 16 * 15 17 * @see WP_Customize_Control … … 26 28 27 29 /** 30 * Constructor. 31 * 32 * @since 4.9.0 33 * 34 * @param WP_Customize_Manager $manager Manager. 35 * @param string $id ID. 36 * @param array $args Args. 37 */ 38 public function __construct( WP_Customize_Manager $manager, $id, array $args = array() ) { 39 _deprecated_file( basename( __FILE__ ), '4.9.0' ); // @todo Move this outside of class in 5.0, and remove its require_once() from class-wp-customize-control.php. See #42364. 40 parent::__construct( $manager, $id, $args ); 41 } 42 43 /** 28 44 * Render the control's content. 29 45 * -
trunk/src/wp-includes/customize/class-wp-customize-new-menu-section.php
r41162 r42034 6 6 * @subpackage Customize 7 7 * @since 4.4.0 8 * @deprecated 4.9.0 This file is no longer used as of the menu creation UX introduced in #40104. 8 9 */ 9 10 … … 11 12 * Customize Menu Section Class 12 13 * 13 * Implements the new-menu-ui toggle button instead of a regular section.14 *15 14 * @since 4.3.0 15 * @deprecated 4.9.0 This class is no longer used as of the menu creation UX introduced in #40104. 16 16 * 17 17 * @see WP_Customize_Section … … 26 26 */ 27 27 public $type = 'new_menu'; 28 29 /** 30 * Constructor. 31 * 32 * Any supplied $args override class property defaults. 33 * 34 * @since 4.9.0 35 * 36 * @param WP_Customize_Manager $manager Customizer bootstrap instance. 37 * @param string $id An specific ID of the section. 38 * @param array $args Section arguments. 39 */ 40 public function __construct( WP_Customize_Manager $manager, $id, array $args = array() ) { 41 _deprecated_file( basename( __FILE__ ), '4.9.0' ); // @todo Move this outside of class in 5.0, and remove its require_once() from class-wp-customize-section.php. See #42364. 42 parent::__construct( $manager, $id, $args ); 43 } 28 44 29 45 /** -
trunk/tests/qunit/wp-admin/js/customize-nav-menus.js
r41899 r42034 114 114 // @todo Add tests for api.Menus.MenuAutoAddControl 115 115 // @todo Add tests for api.Menus.MenuControl 116 // @todo Add tests for api.Menus.NewMenuControl117 116 // @todo Add tests for api.Menus.applySavedData 118 117 // @todo Add tests for api.Menus.focusMenuItemControl 118 // @todo Add tests for api.Menus.createNavMenu 119 119 120 120 test( 'api.Menus.getMenuControl() should return the expected control', function() {
Note: See TracChangeset
for help on using the changeset viewer.