wp/wp-admin/js/customize-nav-menus.js
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
       
     1 /**
       
     2  * @output wp-admin/js/customize-nav-menus.js
       
     3  */
       
     4 
     1 /* global _wpCustomizeNavMenusSettings, wpNavMenu, console */
     5 /* global _wpCustomizeNavMenusSettings, wpNavMenu, console */
     2 ( function( api, wp, $ ) {
     6 ( function( api, wp, $ ) {
     3 	'use strict';
     7 	'use strict';
     4 
     8 
     5 	/**
     9 	/**
    11 	wpNavMenu.options.targetTolerance       = 10;
    15 	wpNavMenu.options.targetTolerance       = 10;
    12 	wpNavMenu.init = function() {
    16 	wpNavMenu.init = function() {
    13 		this.jQueryExtensions();
    17 		this.jQueryExtensions();
    14 	};
    18 	};
    15 
    19 
       
    20 	/**
       
    21 	 * @namespace wp.customize.Menus
       
    22 	 */
    16 	api.Menus = api.Menus || {};
    23 	api.Menus = api.Menus || {};
    17 
    24 
    18 	// Link settings.
    25 	// Link settings.
    19 	api.Menus.data = {
    26 	api.Menus.data = {
    20 		itemTypes: [],
    27 		itemTypes: [],
    33 
    40 
    34 	/**
    41 	/**
    35 	 * Newly-created Nav Menus and Nav Menu Items have negative integer IDs which
    42 	 * Newly-created Nav Menus and Nav Menu Items have negative integer IDs which
    36 	 * serve as placeholders until Save & Publish happens.
    43 	 * serve as placeholders until Save & Publish happens.
    37 	 *
    44 	 *
       
    45 	 * @alias wp.customize.Menus.generatePlaceholderAutoIncrementId
       
    46 	 *
    38 	 * @return {number}
    47 	 * @return {number}
    39 	 */
    48 	 */
    40 	api.Menus.generatePlaceholderAutoIncrementId = function() {
    49 	api.Menus.generatePlaceholderAutoIncrementId = function() {
    41 		return -Math.ceil( api.Menus.data.phpIntMax * Math.random() );
    50 		return -Math.ceil( api.Menus.data.phpIntMax * Math.random() );
    42 	};
    51 	};
    44 	/**
    53 	/**
    45 	 * wp.customize.Menus.AvailableItemModel
    54 	 * wp.customize.Menus.AvailableItemModel
    46 	 *
    55 	 *
    47 	 * A single available menu item model. See PHP's WP_Customize_Nav_Menu_Item_Setting class.
    56 	 * A single available menu item model. See PHP's WP_Customize_Nav_Menu_Item_Setting class.
    48 	 *
    57 	 *
    49 	 * @constructor
    58 	 * @class    wp.customize.Menus.AvailableItemModel
    50 	 * @augments Backbone.Model
    59 	 * @augments Backbone.Model
    51 	 */
    60 	 */
    52 	api.Menus.AvailableItemModel = Backbone.Model.extend( $.extend(
    61 	api.Menus.AvailableItemModel = Backbone.Model.extend( $.extend(
    53 		{
    62 		{
    54 			id: null // This is only used by Backbone.
    63 			id: null // This is only used by Backbone.
    59 	/**
    68 	/**
    60 	 * wp.customize.Menus.AvailableItemCollection
    69 	 * wp.customize.Menus.AvailableItemCollection
    61 	 *
    70 	 *
    62 	 * Collection for available menu item models.
    71 	 * Collection for available menu item models.
    63 	 *
    72 	 *
    64 	 * @constructor
    73 	 * @class    wp.customize.Menus.AvailableItemCollection
    65 	 * @augments Backbone.Model
    74 	 * @augments Backbone.Collection
    66 	 */
    75 	 */
    67 	api.Menus.AvailableItemCollection = Backbone.Collection.extend({
    76 	api.Menus.AvailableItemCollection = Backbone.Collection.extend(/** @lends wp.customize.Menus.AvailableItemCollection.prototype */{
    68 		model: api.Menus.AvailableItemModel,
    77 		model: api.Menus.AvailableItemModel,
    69 
    78 
    70 		sort_key: 'order',
    79 		sort_key: 'order',
    71 
    80 
    72 		comparator: function( item ) {
    81 		comparator: function( item ) {
    82 
    91 
    83 	/**
    92 	/**
    84 	 * Insert a new `auto-draft` post.
    93 	 * Insert a new `auto-draft` post.
    85 	 *
    94 	 *
    86 	 * @since 4.7.0
    95 	 * @since 4.7.0
    87 	 * @access public
    96 	 * @alias wp.customize.Menus.insertAutoDraftPost
    88 	 *
    97 	 *
    89 	 * @param {object} params - Parameters for the draft post to create.
    98 	 * @param {object} params - Parameters for the draft post to create.
    90 	 * @param {string} params.post_type - Post type to add.
    99 	 * @param {string} params.post_type - Post type to add.
    91 	 * @param {string} params.post_title - Post title to use.
   100 	 * @param {string} params.post_title - Post title to use.
    92 	 * @return {jQuery.promise} Promise resolved with the added post.
   101 	 * @return {jQuery.promise} Promise resolved with the added post.
   139 		} );
   148 		} );
   140 
   149 
   141 		return deferred.promise();
   150 		return deferred.promise();
   142 	};
   151 	};
   143 
   152 
   144 	/**
   153 	api.Menus.AvailableMenuItemsPanelView = wp.Backbone.View.extend(/** @lends wp.customize.Menus.AvailableMenuItemsPanelView.prototype */{
   145 	 * wp.customize.Menus.AvailableMenuItemsPanelView
       
   146 	 *
       
   147 	 * View class for the available menu items panel.
       
   148 	 *
       
   149 	 * @constructor
       
   150 	 * @augments wp.Backbone.View
       
   151 	 * @augments Backbone.View
       
   152 	 */
       
   153 	api.Menus.AvailableMenuItemsPanelView = wp.Backbone.View.extend({
       
   154 
   154 
   155 		el: '#available-menu-items',
   155 		el: '#available-menu-items',
   156 
   156 
   157 		events: {
   157 		events: {
   158 			'input #menu-items-search': 'debounceSearch',
   158 			'input #menu-items-search': 'debounceSearch',
   159 			'keyup #menu-items-search': 'debounceSearch',
       
   160 			'focus .menu-item-tpl': 'focus',
   159 			'focus .menu-item-tpl': 'focus',
   161 			'click .menu-item-tpl': '_submit',
   160 			'click .menu-item-tpl': '_submit',
   162 			'click #custom-menu-item-submit': '_submitLink',
   161 			'click #custom-menu-item-submit': '_submitLink',
   163 			'keypress #custom-menu-item-name': '_submitLink',
   162 			'keypress #custom-menu-item-name': '_submitLink',
   164 			'click .new-content-item .add-content': '_submitNew',
   163 			'click .new-content-item .add-content': '_submitNew',
   179 		pages: {},
   178 		pages: {},
   180 		sectionContent: '',
   179 		sectionContent: '',
   181 		loading: false,
   180 		loading: false,
   182 		addingNew: false,
   181 		addingNew: false,
   183 
   182 
       
   183 		/**
       
   184 		 * wp.customize.Menus.AvailableMenuItemsPanelView
       
   185 		 *
       
   186 		 * View class for the available menu items panel.
       
   187 		 *
       
   188 		 * @constructs wp.customize.Menus.AvailableMenuItemsPanelView
       
   189 		 * @augments   wp.Backbone.View
       
   190 		 */
   184 		initialize: function() {
   191 		initialize: function() {
   185 			var self = this;
   192 			var self = this;
   186 
   193 
   187 			if ( ! api.panel.has( 'nav_menus' ) ) {
   194 			if ( ! api.panel.has( 'nav_menus' ) ) {
   188 				return;
   195 				return;
   535 		// Adds the custom menu item to the menu.
   542 		// Adds the custom menu item to the menu.
   536 		submitLink: function() {
   543 		submitLink: function() {
   537 			var menuItem,
   544 			var menuItem,
   538 				itemName = $( '#custom-menu-item-name' ),
   545 				itemName = $( '#custom-menu-item-name' ),
   539 				itemUrl = $( '#custom-menu-item-url' ),
   546 				itemUrl = $( '#custom-menu-item-url' ),
       
   547 				url = itemUrl.val().trim(),
   540 				urlRegex;
   548 				urlRegex;
   541 
   549 
   542 			if ( ! this.currentMenuControl ) {
   550 			if ( ! this.currentMenuControl ) {
   543 				return;
   551 				return;
   544 			}
   552 			}
   558 			urlRegex = /^((\w+:)?\/\/\w.*|\w+:(?!\/\/$)|\/|\?|#)/;
   566 			urlRegex = /^((\w+:)?\/\/\w.*|\w+:(?!\/\/$)|\/|\?|#)/;
   559 
   567 
   560 			if ( '' === itemName.val() ) {
   568 			if ( '' === itemName.val() ) {
   561 				itemName.addClass( 'invalid' );
   569 				itemName.addClass( 'invalid' );
   562 				return;
   570 				return;
   563 			} else if ( ! urlRegex.test( itemUrl.val() ) ) {
   571 			} else if ( ! urlRegex.test( url ) ) {
   564 				itemUrl.addClass( 'invalid' );
   572 				itemUrl.addClass( 'invalid' );
   565 				return;
   573 				return;
   566 			}
   574 			}
   567 
   575 
   568 			menuItem = {
   576 			menuItem = {
   569 				'title': itemName.val(),
   577 				'title': itemName.val(),
   570 				'url': itemUrl.val(),
   578 				'url': url,
   571 				'type': 'custom',
   579 				'type': 'custom',
   572 				'type_label': api.Menus.data.l10n.custom_label,
   580 				'type_label': api.Menus.data.l10n.custom_label,
   573 				'object': 'custom'
   581 				'object': 'custom'
   574 			};
   582 			};
   575 
   583 
   751 	 * wp.customize.Menus.MenusPanel
   759 	 * wp.customize.Menus.MenusPanel
   752 	 *
   760 	 *
   753 	 * Customizer panel for menus. This is used only for screen options management.
   761 	 * Customizer panel for menus. This is used only for screen options management.
   754 	 * Note that 'menus' must match the WP_Customize_Menu_Panel::$type.
   762 	 * Note that 'menus' must match the WP_Customize_Menu_Panel::$type.
   755 	 *
   763 	 *
   756 	 * @constructor
   764 	 * @class    wp.customize.Menus.MenusPanel
   757 	 * @augments wp.customize.Panel
   765 	 * @augments wp.customize.Panel
   758 	 */
   766 	 */
   759 	api.Menus.MenusPanel = api.Panel.extend({
   767 	api.Menus.MenusPanel = api.Panel.extend(/** @lends wp.customize.Menus.MenusPanel.prototype */{
   760 
   768 
   761 		attachEvents: function() {
   769 		attachEvents: function() {
   762 			api.Panel.prototype.attachEvents.call( this );
   770 			api.Panel.prototype.attachEvents.call( this );
   763 
   771 
   764 			var panel = this,
   772 			var panel = this,
   883 	 * wp.customize.Menus.MenuSection
   891 	 * wp.customize.Menus.MenuSection
   884 	 *
   892 	 *
   885 	 * Customizer section for menus. This is used only for lazy-loading child controls.
   893 	 * Customizer section for menus. This is used only for lazy-loading child controls.
   886 	 * Note that 'nav_menu' must match the WP_Customize_Menu_Section::$type.
   894 	 * Note that 'nav_menu' must match the WP_Customize_Menu_Section::$type.
   887 	 *
   895 	 *
   888 	 * @constructor
   896 	 * @class    wp.customize.Menus.MenuSection
   889 	 * @augments wp.customize.Section
   897 	 * @augments wp.customize.Section
   890 	 */
   898 	 */
   891 	api.Menus.MenuSection = api.Section.extend({
   899 	api.Menus.MenuSection = api.Section.extend(/** @lends wp.customize.Menus.MenuSection.prototype */{
   892 
   900 
   893 		/**
   901 		/**
   894 		 * Initialize.
   902 		 * Initialize.
   895 		 *
   903 		 *
   896 		 * @since 4.3.0
   904 		 * @since 4.3.0
  1210 	/**
  1218 	/**
  1211 	 * wp.customize.Menus.NewMenuSection
  1219 	 * wp.customize.Menus.NewMenuSection
  1212 	 *
  1220 	 *
  1213 	 * Customizer section for new menus.
  1221 	 * Customizer section for new menus.
  1214 	 *
  1222 	 *
  1215 	 * @constructor
  1223 	 * @class    wp.customize.Menus.NewMenuSection
  1216 	 * @augments wp.customize.Section
  1224 	 * @augments wp.customize.Section
  1217 	 */
  1225 	 */
  1218 	api.Menus.NewMenuSection = api.Section.extend({
  1226 	api.Menus.NewMenuSection = api.Section.extend(/** @lends wp.customize.Menus.NewMenuSection.prototype */{
  1219 
  1227 
  1220 		/**
  1228 		/**
  1221 		 * Add behaviors for the accordion section.
  1229 		 * Add behaviors for the accordion section.
  1222 		 *
  1230 		 *
  1223 		 * @since 4.3.0
  1231 		 * @since 4.3.0
  1449 	 * wp.customize.Menus.MenuLocationControl
  1457 	 * wp.customize.Menus.MenuLocationControl
  1450 	 *
  1458 	 *
  1451 	 * Customizer control for menu locations (rendered as a <select>).
  1459 	 * Customizer control for menu locations (rendered as a <select>).
  1452 	 * Note that 'nav_menu_location' must match the WP_Customize_Nav_Menu_Location_Control::$type.
  1460 	 * Note that 'nav_menu_location' must match the WP_Customize_Nav_Menu_Location_Control::$type.
  1453 	 *
  1461 	 *
  1454 	 * @constructor
  1462 	 * @class    wp.customize.Menus.MenuLocationControl
  1455 	 * @augments wp.customize.Control
  1463 	 * @augments wp.customize.Control
  1456 	 */
  1464 	 */
  1457 	api.Menus.MenuLocationControl = api.Control.extend({
  1465 	api.Menus.MenuLocationControl = api.Control.extend(/** @lends wp.customize.Menus.MenuLocationControl.prototype */{
  1458 		initialize: function( id, options ) {
  1466 		initialize: function( id, options ) {
  1459 			var control = this,
  1467 			var control = this,
  1460 				matches = id.match( /^nav_menu_locations\[(.+?)]/ );
  1468 				matches = id.match( /^nav_menu_locations\[(.+?)]/ );
  1461 			control.themeLocation = matches[1];
  1469 			control.themeLocation = matches[1];
  1462 			api.Control.prototype.initialize.call( control, id, options );
  1470 			api.Control.prototype.initialize.call( control, id, options );
  1527 				}
  1535 				}
  1528 			});
  1536 			});
  1529 		}
  1537 		}
  1530 	});
  1538 	});
  1531 
  1539 
  1532 	/**
  1540 	api.Menus.MenuItemControl = api.Control.extend(/** @lends wp.customize.Menus.MenuItemControl.prototype */{
  1533 	 * wp.customize.Menus.MenuItemControl
  1541 
  1534 	 *
  1542 		/**
  1535 	 * Customizer control for menu items.
  1543 		 * wp.customize.Menus.MenuItemControl
  1536 	 * Note that 'menu_item' must match the WP_Customize_Menu_Item_Control::$type.
  1544 		 *
  1537 	 *
  1545 		 * Customizer control for menu items.
  1538 	 * @constructor
  1546 		 * Note that 'menu_item' must match the WP_Customize_Menu_Item_Control::$type.
  1539 	 * @augments wp.customize.Control
  1547 		 *
  1540 	 */
  1548 		 * @constructs wp.customize.Menus.MenuItemControl
  1541 	api.Menus.MenuItemControl = api.Control.extend({
  1549 		 * @augments   wp.customize.Control
  1542 
  1550 		 *
  1543 		/**
  1551 		 * @inheritDoc
  1544 		 * @inheritdoc
       
  1545 		 */
  1552 		 */
  1546 		initialize: function( id, options ) {
  1553 		initialize: function( id, options ) {
  1547 			var control = this;
  1554 			var control = this;
  1548 			control.expanded = new api.Value( false );
  1555 			control.expanded = new api.Value( false );
  1549 			control.expandedArgumentsQueue = [];
  1556 			control.expandedArgumentsQueue = [];
  2322 	/**
  2329 	/**
  2323 	 * wp.customize.Menus.MenuNameControl
  2330 	 * wp.customize.Menus.MenuNameControl
  2324 	 *
  2331 	 *
  2325 	 * Customizer control for a nav menu's name.
  2332 	 * Customizer control for a nav menu's name.
  2326 	 *
  2333 	 *
  2327 	 * @constructor
  2334 	 * @class    wp.customize.Menus.MenuNameControl
  2328 	 * @augments wp.customize.Control
  2335 	 * @augments wp.customize.Control
  2329 	 */
  2336 	 */
  2330 	api.Menus.MenuNameControl = api.Control.extend({
  2337 	api.Menus.MenuNameControl = api.Control.extend(/** @lends wp.customize.Menus.MenuNameControl.prototype */{
  2331 
  2338 
  2332 		ready: function() {
  2339 		ready: function() {
  2333 			var control = this;
  2340 			var control = this;
  2334 
  2341 
  2335 			if ( control.setting ) {
  2342 			if ( control.setting ) {
  2362 	 * wp.customize.Menus.MenuLocationsControl
  2369 	 * wp.customize.Menus.MenuLocationsControl
  2363 	 *
  2370 	 *
  2364 	 * Customizer control for a nav menu's locations.
  2371 	 * Customizer control for a nav menu's locations.
  2365 	 *
  2372 	 *
  2366 	 * @since 4.9.0
  2373 	 * @since 4.9.0
  2367 	 * @constructor
  2374 	 * @class    wp.customize.Menus.MenuLocationsControl
  2368 	 * @augments wp.customize.Control
  2375 	 * @augments wp.customize.Control
  2369 	 */
  2376 	 */
  2370 	api.Menus.MenuLocationsControl = api.Control.extend({
  2377 	api.Menus.MenuLocationsControl = api.Control.extend(/** @lends wp.customize.Menus.MenuLocationsControl.prototype */{
  2371 
  2378 
  2372 		/**
  2379 		/**
  2373 		 * Set up the control.
  2380 		 * Set up the control.
  2374 		 *
  2381 		 *
  2375 		 * @since 4.9.0
  2382 		 * @since 4.9.0
  2435 	/**
  2442 	/**
  2436 	 * wp.customize.Menus.MenuAutoAddControl
  2443 	 * wp.customize.Menus.MenuAutoAddControl
  2437 	 *
  2444 	 *
  2438 	 * Customizer control for a nav menu's auto add.
  2445 	 * Customizer control for a nav menu's auto add.
  2439 	 *
  2446 	 *
  2440 	 * @constructor
  2447 	 * @class    wp.customize.Menus.MenuAutoAddControl
  2441 	 * @augments wp.customize.Control
  2448 	 * @augments wp.customize.Control
  2442 	 */
  2449 	 */
  2443 	api.Menus.MenuAutoAddControl = api.Control.extend({
  2450 	api.Menus.MenuAutoAddControl = api.Control.extend(/** @lends wp.customize.Menus.MenuAutoAddControl.prototype */{
  2444 
  2451 
  2445 		ready: function() {
  2452 		ready: function() {
  2446 			var control = this,
  2453 			var control = this,
  2447 				settingValue = control.setting();
  2454 				settingValue = control.setting();
  2448 
  2455 
  2488 	 * wp.customize.Menus.MenuControl
  2495 	 * wp.customize.Menus.MenuControl
  2489 	 *
  2496 	 *
  2490 	 * Customizer control for menus.
  2497 	 * Customizer control for menus.
  2491 	 * Note that 'nav_menu' must match the WP_Menu_Customize_Control::$type
  2498 	 * Note that 'nav_menu' must match the WP_Menu_Customize_Control::$type
  2492 	 *
  2499 	 *
  2493 	 * @constructor
  2500 	 * @class    wp.customize.Menus.MenuControl
  2494 	 * @augments wp.customize.Control
  2501 	 * @augments wp.customize.Control
  2495 	 */
  2502 	 */
  2496 	api.Menus.MenuControl = api.Control.extend({
  2503 	api.Menus.MenuControl = api.Control.extend(/** @lends wp.customize.Menus.MenuControl.prototype */{
  2497 		/**
  2504 		/**
  2498 		 * Set up the control.
  2505 		 * Set up the control.
  2499 		 */
  2506 		 */
  2500 		ready: function() {
  2507 		ready: function() {
  2501 			var control = this,
  2508 			var control = this,
  3019 
  3026 
  3020 			this.container.find( '.new-menu-item-invitation' ).toggle( menuItemControls.length === 0 );
  3027 			this.container.find( '.new-menu-item-invitation' ).toggle( menuItemControls.length === 0 );
  3021 		}
  3028 		}
  3022 	} );
  3029 	} );
  3023 
  3030 
  3024 	/**
  3031 	api.Menus.NewMenuControl = api.Control.extend(/** @lends wp.customize.Menus.NewMenuControl.prototype */{
  3025 	 * wp.customize.Menus.NewMenuControl
  3032 
  3026 	 *
  3033 		/**
  3027 	 * Customizer control for creating new menus and handling deletion of existing menus.
  3034 		 * wp.customize.Menus.NewMenuControl
  3028 	 * Note that 'new_menu' must match the WP_Customize_New_Menu_Control::$type.
  3035 		 *
  3029 	 *
  3036 		 * Customizer control for creating new menus and handling deletion of existing menus.
  3030 	 * @constructor
  3037 		 * Note that 'new_menu' must match the WP_Customize_New_Menu_Control::$type.
  3031 	 * @augments wp.customize.Control
  3038 		 *
  3032 	 * @deprecated 4.9.0 This class is no longer used due to new menu creation UX.
  3039 		 * @constructs wp.customize.Menus.NewMenuControl
  3033 	 */
  3040 		 * @augments   wp.customize.Control
  3034 	api.Menus.NewMenuControl = api.Control.extend({
  3041 		 *
  3035 
  3042 		 * @deprecated 4.9.0 This class is no longer used due to new menu creation UX.
  3036 		/**
       
  3037 		 * Initialize.
       
  3038 		 *
       
  3039 		 * @deprecated 4.9.0
       
  3040 		 */
  3043 		 */
  3041 		initialize: function() {
  3044 		initialize: function() {
  3042 			if ( 'undefined' !== typeof console && console.warn ) {
  3045 			if ( 'undefined' !== typeof console && console.warn ) {
  3043 				console.warn( '[DEPRECATED] wp.customize.NewMenuControl will be removed. Please use wp.customize.Menus.createNavMenu() instead.' );
  3046 				console.warn( '[DEPRECATED] wp.customize.NewMenuControl will be removed. Please use wp.customize.Menus.createNavMenu() instead.' );
  3044 			}
  3047 			}
  3109 	$.extend( api.controlConstructor, {
  3112 	$.extend( api.controlConstructor, {
  3110 		nav_menu_location: api.Menus.MenuLocationControl,
  3113 		nav_menu_location: api.Menus.MenuLocationControl,
  3111 		nav_menu_item: api.Menus.MenuItemControl,
  3114 		nav_menu_item: api.Menus.MenuItemControl,
  3112 		nav_menu: api.Menus.MenuControl,
  3115 		nav_menu: api.Menus.MenuControl,
  3113 		nav_menu_name: api.Menus.MenuNameControl,
  3116 		nav_menu_name: api.Menus.MenuNameControl,
  3114 		new_menu: api.Menus.NewMenuControl, // @todo Remove in 5.0. See #42364.
  3117 		new_menu: api.Menus.NewMenuControl, // @todo Remove in a future release. See #42364.
  3115 		nav_menu_locations: api.Menus.MenuLocationsControl,
  3118 		nav_menu_locations: api.Menus.MenuLocationsControl,
  3116 		nav_menu_auto_add: api.Menus.MenuAutoAddControl
  3119 		nav_menu_auto_add: api.Menus.MenuAutoAddControl
  3117 	});
  3120 	});
  3118 
  3121 
  3119 	/**
  3122 	/**
  3163 	} );
  3166 	} );
  3164 
  3167 
  3165 	/**
  3168 	/**
  3166 	 * When customize_save comes back with a success, make sure any inserted
  3169 	 * When customize_save comes back with a success, make sure any inserted
  3167 	 * nav menus and items are properly re-added with their newly-assigned IDs.
  3170 	 * nav menus and items are properly re-added with their newly-assigned IDs.
       
  3171 	 *
       
  3172 	 * @alias wp.customize.Menus.applySavedData
  3168 	 *
  3173 	 *
  3169 	 * @param {object} data
  3174 	 * @param {object} data
  3170 	 * @param {array} data.nav_menu_updates
  3175 	 * @param {array} data.nav_menu_updates
  3171 	 * @param {array} data.nav_menu_item_updates
  3176 	 * @param {array} data.nav_menu_item_updates
  3172 	 */
  3177 	 */
  3394 	};
  3399 	};
  3395 
  3400 
  3396 	/**
  3401 	/**
  3397 	 * Focus a menu item control.
  3402 	 * Focus a menu item control.
  3398 	 *
  3403 	 *
       
  3404 	 * @alias wp.customize.Menus.focusMenuItemControl
       
  3405 	 *
  3399 	 * @param {string} menuItemId
  3406 	 * @param {string} menuItemId
  3400 	 */
  3407 	 */
  3401 	api.Menus.focusMenuItemControl = function( menuItemId ) {
  3408 	api.Menus.focusMenuItemControl = function( menuItemId ) {
  3402 		var control = api.Menus.getMenuItemControl( menuItemId );
  3409 		var control = api.Menus.getMenuItemControl( menuItemId );
  3403 		if ( control ) {
  3410 		if ( control ) {
  3406 	};
  3413 	};
  3407 
  3414 
  3408 	/**
  3415 	/**
  3409 	 * Get the control for a given menu.
  3416 	 * Get the control for a given menu.
  3410 	 *
  3417 	 *
       
  3418 	 * @alias wp.customize.Menus.getMenuControl
       
  3419 	 *
  3411 	 * @param menuId
  3420 	 * @param menuId
  3412 	 * @return {wp.customize.controlConstructor.menus[]}
  3421 	 * @return {wp.customize.controlConstructor.menus[]}
  3413 	 */
  3422 	 */
  3414 	api.Menus.getMenuControl = function( menuId ) {
  3423 	api.Menus.getMenuControl = function( menuId ) {
  3415 		return api.control( 'nav_menu[' + menuId + ']' );
  3424 		return api.control( 'nav_menu[' + menuId + ']' );
  3416 	};
  3425 	};
  3417 
  3426 
  3418 	/**
  3427 	/**
  3419 	 * Given a menu item ID, get the control associated with it.
  3428 	 * Given a menu item ID, get the control associated with it.
  3420 	 *
  3429 	 *
       
  3430 	 * @alias wp.customize.Menus.getMenuItemControl
       
  3431 	 *
  3421 	 * @param {string} menuItemId
  3432 	 * @param {string} menuItemId
  3422 	 * @return {object|null}
  3433 	 * @return {object|null}
  3423 	 */
  3434 	 */
  3424 	api.Menus.getMenuItemControl = function( menuItemId ) {
  3435 	api.Menus.getMenuItemControl = function( menuItemId ) {
  3425 		return api.control( menuItemIdToSettingId( menuItemId ) );
  3436 		return api.control( menuItemIdToSettingId( menuItemId ) );
  3426 	};
  3437 	};
  3427 
  3438 
  3428 	/**
  3439 	/**
       
  3440 	 * @alias wp.customize.Menus~menuItemIdToSettingId
       
  3441 	 *
  3429 	 * @param {String} menuItemId
  3442 	 * @param {String} menuItemId
  3430 	 */
  3443 	 */
  3431 	function menuItemIdToSettingId( menuItemId ) {
  3444 	function menuItemIdToSettingId( menuItemId ) {
  3432 		return 'nav_menu_item[' + menuItemId + ']';
  3445 		return 'nav_menu_item[' + menuItemId + ']';
  3433 	}
  3446 	}
  3434 
  3447 
  3435 	/**
  3448 	/**
  3436 	 * Apply sanitize_text_field()-like logic to the supplied name, returning a
  3449 	 * Apply sanitize_text_field()-like logic to the supplied name, returning a
  3437 	 * "unnammed" fallback string if the name is then empty.
  3450 	 * "unnammed" fallback string if the name is then empty.
  3438 	 *
  3451 	 *
       
  3452 	 * @alias wp.customize.Menus~displayNavMenuName
       
  3453 	 *
  3439 	 * @param {string} name
  3454 	 * @param {string} name
  3440 	 * @returns {string}
  3455 	 * @returns {string}
  3441 	 */
  3456 	 */
  3442 	function displayNavMenuName( name ) {
  3457 	function displayNavMenuName( name ) {
  3443 		name = name || '';
  3458 		name = name || '';
  3444 		name = $( '<div>' ).text( name ).html(); // Emulate esc_html() which is used in wp-admin/nav-menus.php.
  3459 		name = wp.sanitize.stripTagsAndEncodeText( name ); // Remove any potential tags from name.
  3445 		name = $.trim( name );
  3460 		name = $.trim( name );
  3446 		return name || api.Menus.data.l10n.unnamed;
  3461 		return name || api.Menus.data.l10n.unnamed;
  3447 	}
  3462 	}
  3448 
  3463 
  3449 })( wp.customize, wp, jQuery );
  3464 })( wp.customize, wp, jQuery );