X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/dc1231b7312fbdca99e9e887cc2bb35a28f85cdc..4ea0dca21bda49aab5ccb91ec12bb4ef5924ed3e:/wp-admin/js/customize-nav-menus.js
diff --git a/wp-admin/js/customize-nav-menus.js b/wp-admin/js/customize-nav-menus.js
index f5296b65..a37d2c4e 100644
--- a/wp-admin/js/customize-nav-menus.js
+++ b/wp-admin/js/customize-nav-menus.js
@@ -17,15 +17,15 @@
// Link settings.
api.Menus.data = {
- nonce: '',
itemTypes: [],
l10n: {},
- menuItemTransport: 'postMessage',
+ settingTransport: 'refresh',
phpIntMax: 0,
defaultSettingValues: {
nav_menu: {},
nav_menu_item: {}
- }
+ },
+ locationSlugMappedToName: {}
};
if ( 'undefined' !== typeof _wpCustomizeNavMenusSettings ) {
$.extend( api.Menus.data, _wpCustomizeNavMenusSettings );
@@ -80,6 +80,66 @@
});
api.Menus.availableMenuItems = new api.Menus.AvailableItemCollection( api.Menus.data.availableMenuItems );
+ /**
+ * Insert a new `auto-draft` post.
+ *
+ * @since 4.7.0
+ * @access public
+ *
+ * @param {object} params - Parameters for the draft post to create.
+ * @param {string} params.post_type - Post type to add.
+ * @param {string} params.post_title - Post title to use.
+ * @return {jQuery.promise} Promise resolved with the added post.
+ */
+ api.Menus.insertAutoDraftPost = function insertAutoDraftPost( params ) {
+ var request, deferred = $.Deferred();
+
+ request = wp.ajax.post( 'customize-nav-menus-insert-auto-draft', {
+ 'customize-menus-nonce': api.settings.nonce['customize-menus'],
+ 'wp_customize': 'on',
+ 'params': params
+ } );
+
+ request.done( function( response ) {
+ if ( response.post_id ) {
+ api( 'nav_menus_created_posts' ).set(
+ api( 'nav_menus_created_posts' ).get().concat( [ response.post_id ] )
+ );
+
+ if ( 'page' === params.post_type ) {
+
+ // Activate static front page controls as this could be the first page created.
+ if ( api.section.has( 'static_front_page' ) ) {
+ api.section( 'static_front_page' ).activate();
+ }
+
+ // Add new page to dropdown-pages controls.
+ api.control.each( function( control ) {
+ var select;
+ if ( 'dropdown-pages' === control.params.type ) {
+ select = control.container.find( 'select[name^="_customize-dropdown-pages-"]' );
+ select.append( new Option( params.post_title, response.post_id ) );
+ }
+ } );
+ }
+ deferred.resolve( response );
+ }
+ } );
+
+ request.fail( function( response ) {
+ var error = response || '';
+
+ if ( 'undefined' !== typeof response.message ) {
+ error = response.message;
+ }
+
+ console.error( error );
+ deferred.rejectWith( error );
+ } );
+
+ return deferred.promise();
+ };
+
/**
* wp.customize.Menus.AvailableMenuItemsPanelView
*
@@ -100,6 +160,8 @@
'click .menu-item-tpl': '_submit',
'click #custom-menu-item-submit': '_submitLink',
'keypress #custom-menu-item-name': '_submitLink',
+ 'click .new-content-item .add-content': '_submitNew',
+ 'keypress .create-item-input': '_submitNew',
'keydown': 'keyboardAccessible'
},
@@ -110,11 +172,13 @@
currentMenuControl: null,
debounceSearch: null,
$search: null,
+ $clearResults: null,
searchTerm: '',
rendered: false,
pages: {},
sectionContent: '',
loading: false,
+ addingNew: false,
initialize: function() {
var self = this;
@@ -124,7 +188,8 @@
}
this.$search = $( '#menu-items-search' );
- this.sectionContent = this.$el.find( '.accordion-section-content' );
+ this.$clearResults = this.$el.find( '.clear-results' );
+ this.sectionContent = this.$el.find( '.available-menu-items-list' );
this.debounceSearch = _.debounce( self.search, 500 );
@@ -141,17 +206,9 @@
}
} );
- // Clear the search results.
- $( '.clear-results' ).on( 'click keydown', function( event ) {
- if ( event.type === 'keydown' && ( 13 !== event.which && 32 !== event.which ) ) { // "return" or "space" keys only
- return;
- }
-
- event.preventDefault();
-
- $( '#menu-items-search' ).val( '' ).focus();
- event.target.value = '';
- self.search( event );
+ // Clear the search results and trigger a `keyup` event to fire a new search.
+ this.$clearResults.on( 'click', function() {
+ self.$search.val( '' ).focus().trigger( 'keyup' );
} );
this.$el.on( 'input', '#custom-menu-item-name.invalid, #custom-menu-item-url.invalid', function() {
@@ -168,7 +225,7 @@
// Load more items.
this.sectionContent.scroll( function() {
- var totalHeight = self.$el.find( '.accordion-section.open .accordion-section-content' ).prop( 'scrollHeight' ),
+ var totalHeight = self.$el.find( '.accordion-section.open .available-menu-items-list' ).prop( 'scrollHeight' ),
visibleHeight = self.$el.find( '.accordion-section.open' ).height();
if ( ! self.loading && $( this ).scrollTop() > 3 / 4 * totalHeight - visibleHeight ) {
@@ -180,13 +237,17 @@
self.doSearch( self.pages.search );
}
} else {
- self.loadItems( type, object );
+ self.loadItems( [
+ { type: type, object: object }
+ ] );
}
}
});
// Close the panel if the URL in the preview changes
api.previewer.bind( 'url', this.close );
+
+ self.delegateEvents();
},
// Search input change handler.
@@ -206,17 +267,13 @@
$otherSections.fadeOut( 100 );
$searchSection.find( '.accordion-section-content' ).slideDown( 'fast' );
$searchSection.addClass( 'open' );
- $searchSection.find( '.clear-results' )
- .prop( 'tabIndex', 0 )
- .addClass( 'is-visible' );
+ this.$clearResults.addClass( 'is-visible' );
} else if ( '' === event.target.value ) {
$searchSection.removeClass( 'open' );
$otherSections.show();
- $searchSection.find( '.clear-results' )
- .prop( 'tabIndex', -1 )
- .removeClass( 'is-visible' );
+ this.$clearResults.removeClass( 'is-visible' );
}
-
+
this.searchTerm = event.target.value;
this.pages.search = 1;
this.doSearch( 1 );
@@ -247,12 +304,14 @@
$section.addClass( 'loading' );
self.loading = true;
- params = {
- 'customize-menus-nonce': api.Menus.data.nonce,
+
+ params = api.previewer.query( { excludeCustomizedSaved: true } );
+ _.extend( params, {
+ 'customize-menus-nonce': api.settings.nonce['customize-menus'],
'wp_customize': 'on',
'search': self.searchTerm,
'page': page
- };
+ } );
self.currentRequest = wp.ajax.post( 'search-available-menu-items-customizer', params );
@@ -286,7 +345,7 @@
self.currentRequest.fail(function( data ) {
// data.message may be undefined, for example when typing slow and the request is aborted.
if ( data.message ) {
- $content.empty().append( $( '
' ).text( data.message ) );
+ $content.empty().append( $( '' ).text( data.message ) );
wp.a11y.speak( data.message );
}
self.pages.search = -1;
@@ -307,51 +366,86 @@
// Render the template for each item by type.
_.each( api.Menus.data.itemTypes, function( itemType ) {
self.pages[ itemType.type + ':' + itemType.object ] = 0;
- self.loadItems( itemType.type, itemType.object ); // @todo we need to combine these Ajax requests.
} );
+ self.loadItems( api.Menus.data.itemTypes );
},
- // Load available menu items.
- loadItems: function( type, object ) {
- var self = this, params, request, itemTemplate, availableMenuItemContainer;
+ /**
+ * Load available nav menu items.
+ *
+ * @since 4.3.0
+ * @since 4.7.0 Changed function signature to take list of item types instead of single type/object.
+ * @access private
+ *
+ * @param {Array.