X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/03f2fa83c13c1b532284205fa7efcab9b8b2c41f..e8f61417994be715a90671aa87f1cd70d8ba132a:/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 9db1664b..7f092533 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 ); @@ -187,6 +187,8 @@ // Close the panel if the URL in the preview changes api.previewer.bind( 'url', this.close ); + + self.delegateEvents(); }, // Search input change handler. @@ -216,7 +218,7 @@ .prop( 'tabIndex', -1 ) .removeClass( 'is-visible' ); } - + this.searchTerm = event.target.value; this.pages.search = 1; this.doSearch( 1 ); @@ -248,7 +250,7 @@ $section.addClass( 'loading' ); self.loading = true; params = { - 'customize-menus-nonce': api.Menus.data.nonce, + 'customize-menus-nonce': api.settings.nonce['customize-menus'], 'wp_customize': 'on', 'search': self.searchTerm, 'page': page @@ -323,7 +325,7 @@ availableMenuItemContainer.find( '.accordion-section-title' ).addClass( 'loading' ); self.loading = true; params = { - 'customize-menus-nonce': api.Menus.data.nonce, + 'customize-menus-nonce': api.settings.nonce['customize-menus'], 'wp_customize': 'on', 'type': type, 'object': object, @@ -612,15 +614,21 @@ }); }, - saveManageColumnsState: function() { - var hidden = this.hidden(); - $.post( wp.ajax.settings.url, { - action: 'hidden-columns', - hidden: hidden, + saveManageColumnsState: _.debounce( function() { + var panel = this; + if ( panel._updateHiddenColumnsRequest ) { + panel._updateHiddenColumnsRequest.abort(); + } + + panel._updateHiddenColumnsRequest = wp.ajax.post( 'hidden-columns', { + hidden: panel.hidden(), screenoptionnonce: $( '#screenoptionnonce' ).val(), page: 'nav-menus' - }); - }, + } ); + panel._updateHiddenColumnsRequest.always( function() { + panel._updateHiddenColumnsRequest = null; + } ); + }, 2000 ), checked: function( column ) { this.container.addClass( 'field-' + column + '-active' ); @@ -631,12 +639,10 @@ }, hidden: function() { - this.hidden = function() { - return $( '.hide-column-tog' ).not( ':checked' ).map( function() { - var id = this.id; - return id.substring( id, id.length - 5 ); - }).get().join( ',' ); - }; + return $( '.hide-column-tog' ).not( ':checked' ).map( function() { + var id = this.id; + return id.substring( 0, id.length - 5 ); + }).get().join( ',' ); } } ); @@ -806,19 +812,21 @@ /** * @param {array} themeLocations */ - updateAssignedLocationsInSectionTitle: function( themeLocations ) { + updateAssignedLocationsInSectionTitle: function( themeLocationSlugs ) { var section = this, $title; $title = section.container.find( '.accordion-section-title:first' ); $title.find( '.menu-in-location' ).remove(); - _.each( themeLocations, function( themeLocation ) { - var $label = $( '' ); - $label.text( api.Menus.data.l10n.menuLocation.replace( '%s', themeLocation ) ); + _.each( themeLocationSlugs, function( themeLocationSlug ) { + var $label, locationName; + $label = $( '' ); + locationName = api.Menus.data.locationSlugMappedToName[ themeLocationSlug ]; + $label.text( api.Menus.data.l10n.menuLocation.replace( '%s', locationName ) ); $title.append( $label ); }); - section.container.toggleClass( 'assigned-to-menu-location', 0 !== themeLocations.length ); + section.container.toggleClass( 'assigned-to-menu-location', 0 !== themeLocationSlugs.length ); }, @@ -1363,24 +1371,38 @@ /** * Expand the menu item form control. + * + * @since 4.5.0 Added params.completeCallback. + * + * @param {Object} [params] - Optional params. + * @param {Function} [params.completeCallback] - Function to call when the form toggle has finished animating. */ - expandForm: function() { - this.toggleForm( true ); + expandForm: function( params ) { + this.toggleForm( true, params ); }, /** * Collapse the menu item form control. + * + * @since 4.5.0 Added params.completeCallback. + * + * @param {Object} [params] - Optional params. + * @param {Function} [params.completeCallback] - Function to call when the form toggle has finished animating. */ - collapseForm: function() { - this.toggleForm( false ); + collapseForm: function( params ) { + this.toggleForm( false, params ); }, /** * Expand or collapse the menu item control. * - * @param {boolean|undefined} [showOrHide] If not supplied, will be inverse of current visibility + * @since 4.5.0 Added params.completeCallback. + * + * @param {boolean} [showOrHide] - If not supplied, will be inverse of current visibility + * @param {Object} [params] - Optional params. + * @param {Function} [params.completeCallback] - Function to call when the form toggle has finished animating. */ - toggleForm: function( showOrHide ) { + toggleForm: function( showOrHide, params ) { var self = this, $menuitem, $inside, complete; $menuitem = this.container; @@ -1391,6 +1413,9 @@ // Already expanded or collapsed. if ( $inside.is( ':visible' ) === showOrHide ) { + if ( params && params.completeCallback ) { + params.completeCallback(); + } return; } @@ -1407,6 +1432,10 @@ .removeClass( 'menu-item-edit-inactive' ) .addClass( 'menu-item-edit-active' ); self.container.trigger( 'expanded' ); + + if ( params && params.completeCallback ) { + params.completeCallback(); + } }; $menuitem.find( '.item-edit' ).attr( 'aria-expanded', 'true' ); @@ -1419,6 +1448,10 @@ .addClass( 'menu-item-edit-inactive' ) .removeClass( 'menu-item-edit-active' ); self.container.trigger( 'collapsed' ); + + if ( params && params.completeCallback ) { + params.completeCallback(); + } }; self.container.trigger( 'collapse' ); @@ -1431,14 +1464,31 @@ /** * Expand the containing menu section, expand the form, and focus on * the first input in the control. + * + * @since 4.5.0 Added params.completeCallback. + * + * @param {Object} [params] - Params object. + * @param {Function} [params.completeCallback] - Optional callback function when focus has completed. */ - focus: function() { - var control = this, focusable; + focus: function( params ) { + params = params || {}; + var control = this, originalCompleteCallback = params.completeCallback; + control.expandControlSection(); - control.expandForm(); - // Note that we can't use :focusable due to a jQuery UI issue. See: https://github.com/jquery/jquery-ui/pull/1583 - focusable = control.container.find( '.menu-item-settings' ).find( 'input, select, textarea, button, object, a[href], [tabindex]' ).filter( ':visible' ); - focusable.first().focus(); + + params.completeCallback = function() { + var focusable; + + // Note that we can't use :focusable due to a jQuery UI issue. See: https://github.com/jquery/jquery-ui/pull/1583 + focusable = control.container.find( '.menu-item-settings' ).find( 'input, select, textarea, button, object, a[href], [tabindex]' ).filter( ':visible' ); + focusable.first().focus(); + + if ( originalCompleteCallback ) { + originalCompleteCallback(); + } + }; + + control.expandForm( params ); }, /** @@ -2266,7 +2316,7 @@ customizeId = 'nav_menu_item[' + String( placeholderId ) + ']'; settingArgs = { type: 'nav_menu_item', - transport: 'postMessage', + transport: api.Menus.data.settingTransport, previewer: api.previewer }; setting = api.create( customizeId, customizeId, {}, settingArgs ); @@ -2355,7 +2405,7 @@ // Register the menu control setting. api.create( customizeId, customizeId, {}, { type: 'nav_menu', - transport: 'postMessage', + transport: api.Menus.data.settingTransport, previewer: api.previewer } ); api( customizeId ).set( $.extend( @@ -2442,9 +2492,8 @@ } } ); - api.previewer.bind( 'refresh', function() { - api.previewer.refresh(); - }); + // Open and focus menu control. + api.previewer.bind( 'focus-nav-menu-item-control', api.Menus.focusMenuItemControl ); } ); /** @@ -2488,7 +2537,7 @@ newCustomizeId = 'nav_menu[' + String( update.term_id ) + ']'; newSetting = api.create( newCustomizeId, newCustomizeId, settingValue, { type: 'nav_menu', - transport: 'postMessage', + transport: api.Menus.data.settingTransport, previewer: api.previewer } ); @@ -2636,7 +2685,7 @@ newCustomizeId = 'nav_menu_item[' + String( update.post_id ) + ']'; newSetting = api.create( newCustomizeId, newCustomizeId, settingValue, { type: 'nav_menu_item', - transport: 'postMessage', + transport: api.Menus.data.settingTransport, previewer: api.previewer } );