Skip to content

Commit

Permalink
resolves #401 (#729)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesros161 committed Aug 30, 2022
1 parent 8d3ee84 commit cd3a23c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
16 changes: 14 additions & 2 deletions src/assets/js/customizer/controls/bgtfw-menu-locations.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ export default {
let customMenus = [];
Object.keys( _wpCustomizeNavMenusSettings.locationSlugMappedToName ).forEach( menu => {
let isActive = false;
if ( /.*_\d+/.test( menu ) ) {

// Only mark as active if there is a panel for it.
if ( /.*_\d+/.test( menu ) && api.panel( `bgtfw_menu_location_${menu}` ) ) {
isActive = true;
api.controlConstructor.nav_menu_location.prototype.updateMenuLocations( menu, isActive );
customMenus.push( menu );
}
api.controlConstructor.nav_menu_location.prototype.updateMenuLocations( menu, isActive );
} );
let menus = api.control( 'bgtfw_header_layout_custom' ).getConnectedMenus()
.map( menu => menu.replace( 'boldgrid_menu_', '' ) );
Expand Down Expand Up @@ -66,6 +68,11 @@ export default {
if ( /.*_\d+/.test( menu ) ) {
isActive = true;
}

// If there is no panel for this location, mark inactive.
if ( ! api.panel( `bgtfw_menu_location_${menu}` ) ) {
isActive = false;
}
api.controlConstructor.nav_menu_location.prototype.updateMenuLocations( menu, isActive );
} );
} );
Expand Down Expand Up @@ -96,6 +103,11 @@ export default {
}
let panel = api.panel( `bgtfw_menu_location_${ locationId }` );

// If there is no panel for this location quit.
if ( ! panel ) {
return;
}

// Force the active panel state to read JS state set with isActive() and ignore server response.
panel.active.validate = isActive;

Expand Down
16 changes: 15 additions & 1 deletion src/assets/js/customizer/controls/bgtfw-sortable-accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,11 @@ export default {
if ( 'sticky-header' === this.params.location && ! location.includes( 'sticky' ) ) {
return;
}

// Do not include menu locations without a customizer panel.
if ( ! api.panel( `bgtfw_menu_location_${location}` ) ) {
return;
}
attr = `boldgrid_menu_${ location }` === type ? 'selected' : '';
markup += `<option value="boldgrid_menu_${ location }"${ attr }>${ name }</option>`;
} );
Expand Down Expand Up @@ -886,7 +891,16 @@ export default {
* @since 2.0.3
*/
getAllMenuActions() {
return Object.keys( window._wpCustomizeNavMenusSettings.locationSlugMappedToName ).map( item => `boldgrid_menu_${item}` );
var menuLocations = [];

// We only want to list menus that have an associated panel.
$.each( window._wpCustomizeNavMenusSettings.locationSlugMappedToName, ( location ) => {
if ( api.panel( `bgtfw_menu_location_${location}` ) ) {
menuLocations.push( location );
}
} );

return menuLocations.map( location => `bgtfw_menu_${ location }` );
},

/**
Expand Down
7 changes: 5 additions & 2 deletions src/assets/js/customizer/header-layout/header-layout.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const controlApi = parent.wp.customize;

// Sometimes underscore is needed, when the parent / parent.window are not defined.
const underscore = parent.window._;

parent.window.BOLDGRID.colWidthSliders = parent.window.BOLDGRID.colWidthSliders ?
parent.window.BOLDGRID.colWidthSliders :
{};
Expand Down Expand Up @@ -571,7 +574,7 @@ export class HeaderLayout {
this.brandingNotices( controlApi( 'bgtfw_header_preset_branding' )(), controlApi.control( 'bgtfw_header_preset_branding' ) );
controlApi.control( 'bgtfw_header_preset' ).container.find( '.bgtfw_header_presetcustom' ).on( 'click', () => {
controlApi.section( 'bgtfw_header_layout_advanced' ).activate();
window._.defer( () => {
underscore.defer( () => {
controlApi.control( 'bgtfw_header_layout_position' ).focus();
} );
} );
Expand Down Expand Up @@ -928,7 +931,7 @@ export class HeaderLayout {

if ( 'custom' === stickyHeaderPreset ) {
controlApi.section( 'bgtfw_sticky_header_layout_advanced' ).activate();
window._.defer( () => {
underscore.defer( () => {
controlApi.control( 'bgtfw_sticky_header_layout_custom' ).focus();
} );
requestData.customHeaderLayout = controlApi( 'bgtfw_sticky_header_layout_custom' )();
Expand Down
5 changes: 5 additions & 0 deletions src/assets/js/customizer/menus/extend-title.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ export class SectionExtendTitle {
*/
_bindMenuPanels() {
for ( const location of Object.keys( this.menus ) ) {

// Do not try to bind panels that do not exist.
if ( ! api.panel( `bgtfw_menu_location_${location}` ) ) {
continue;
}
api.panel( `bgtfw_menu_location_${location}` ).expanded.bind( () => this.updateTitle( location ) );
api( `bgtfw_menu_hamburger_${location}`, ( value ) => value.bind( () => this.updateTitle( location ) ) );
api( `bgtfw_menu_hamburger_${location}_toggle`, ( value ) => value.bind( () => this.updateTitle( location ) ) );
Expand Down

0 comments on commit cd3a23c

Please sign in to comment.