laipower/wp-content/plugins/gp-premium/library/customizer/controls/js/generatepress-controls.js

184 lines
6.2 KiB
JavaScript
Raw Normal View History

2020-04-07 13:03:04 +00:00
( function( $, api ) {
/**
* Set some controls when we're using the navigation as a header.
*
* @since 1.8
*/
api( 'generate_menu_plus_settings[navigation_as_header]', function( value ) {
value.bind( function( newval ) {
var navAlignmentSetting = api.instance( 'generate_settings[nav_alignment_setting]' ),
navAlignment = gpControls.navigationAlignment,
siteTitleFontSizeSetting = api.instance( 'generate_settings[site_title_font_size]' ),
mobileSiteTitleFontSizeSetting = api.instance( 'generate_settings[mobile_site_title_font_size]' ),
siteTitleFontSize = gpControls.siteTitleFontSize,
mobileSiteTitleFontSize = gpControls.mobileSiteTitleFontSize,
mobileHeader = api.instance( 'generate_menu_plus_settings[mobile_header]' ).get(),
navTextColorSetting = api.instance( 'generate_settings[navigation_text_color]' ),
navTextColor = gpControls.navigationTextColor,
headerTextColorSetting = api.instance( 'generate_settings[header_text_color]' ),
headerTextColor = gpControls.headerTextColor;
if ( siteTitleFontSizeSetting && ! siteTitleFontSizeSetting._dirty && 25 !== siteTitleFontSizeSetting.get() ) {
2020-04-07 13:03:04 +00:00
siteTitleFontSize = siteTitleFontSizeSetting.get();
}
if ( mobileSiteTitleFontSizeSetting && ! mobileSiteTitleFontSizeSetting._dirty && 20 !== mobileSiteTitleFontSizeSetting.get() ) {
2020-04-07 13:03:04 +00:00
mobileSiteTitleFontSize = mobileSiteTitleFontSizeSetting.get();
}
if ( navTextColorSetting && ! navTextColorSetting._dirty ) {
2020-04-07 13:03:04 +00:00
navTextColor = navTextColorSetting.get();
}
if ( headerTextColorSetting && ! headerTextColorSetting._dirty ) {
2020-04-07 13:03:04 +00:00
headerTextColor = headerTextColorSetting.get();
}
if ( newval ) {
navAlignmentSetting.set( 'right' );
if ( siteTitleFontSizeSetting ) {
siteTitleFontSizeSetting.set( 25 );
}
if ( api.instance( 'generate_settings[site_title_color]' ) ) {
api.instance( 'generate_settings[site_title_color]' ).set( navTextColor );
}
if ( mobileSiteTitleFontSizeSetting && 'enable' !== mobileHeader ) {
2020-04-07 13:03:04 +00:00
mobileSiteTitleFontSizeSetting.set( 20 );
}
} else {
navAlignmentSetting.set( navAlignment );
if ( siteTitleFontSizeSetting ) {
siteTitleFontSizeSetting.set( siteTitleFontSize );
}
if ( api.instance( 'generate_settings[site_title_color]' ) ) {
api.instance( 'generate_settings[site_title_color]' ).set( headerTextColor );
}
if ( mobileSiteTitleFontSizeSetting && 'enable' !== mobileHeader ) {
2020-04-07 13:03:04 +00:00
mobileSiteTitleFontSizeSetting.set( mobileSiteTitleFontSize );
}
}
} );
var showRegularHeader,
showRegularHeaderCallback,
showNavHeader,
showNavHeaderCallback;
/**
* Determine whether we should display our header controls.
*
* @returns {boolean}
*/
showRegularHeader = function() {
if ( value.get() ) {
return false;
}
return true;
};
/**
* Determine whether our navigation is our header.
*
* @returns {boolean}
*/
showNavHeader = function() {
if ( value.get() ) {
return true;
}
return false;
};
/**
* Update a control's active state according to the navigation as header option.
*
* @param {wp.customize.Control} control
*/
showRegularHeaderCallback = function( control ) {
var setActiveState = function() {
control.active.set( showRegularHeader() );
};
control.active.validate = showRegularHeader;
setActiveState();
value.bind( setActiveState );
};
/**
* Update a control's active state according to the navigation as header option.
*
* @param {wp.customize.Control} control
*/
showNavHeaderCallback = function( control ) {
var setActiveState = function() {
control.active.set( showNavHeader() );
};
control.active.validate = showNavHeader;
setActiveState();
value.bind( setActiveState );
};
api.control( 'generate_header_helper', showRegularHeaderCallback );
api.control( 'generate_settings[header_layout_setting]', showRegularHeaderCallback );
api.control( 'generate_settings[header_inner_width]', showRegularHeaderCallback );
api.control( 'generate_settings[header_alignment_setting]', showRegularHeaderCallback );
api.control( 'header_spacing', showRegularHeaderCallback );
api.control( 'generate_settings[header_background_color]', showRegularHeaderCallback );
api.control( 'header_text_color', showRegularHeaderCallback );
api.control( 'header_link_color', showRegularHeaderCallback );
api.control( 'header_link_hover_color', showRegularHeaderCallback );
api.control( 'site_tagline_color', showRegularHeaderCallback );
api.control( 'font_site_tagline_control', showRegularHeaderCallback );
api.control( 'generate_settings[site_tagline_font_size]', showRegularHeaderCallback );
api.control( 'generate_settings[nav_position_setting]', showRegularHeaderCallback );
api.control( 'generate_settings[logo_width]', showRegularHeaderCallback );
} );
/**
* Set the navigation branding font size label on mobile header branding change.
*
* @since 1.8
*/
api( 'generate_menu_plus_settings[mobile_header_branding]', function( value ) {
value.bind( function( newval ) {
if ( api.instance( 'generate_settings[mobile_site_title_font_size]' ) && 'title' === newval ) {
2020-04-07 13:03:04 +00:00
api.instance( 'generate_settings[mobile_site_title_font_size]' ).set( 20 );
}
} );
} );
/**
* Set the navigation branding font size label on mobile header change.
*
* @since 1.8
*/
api( 'generate_menu_plus_settings[mobile_header]', function( value ) {
value.bind( function( newval ) {
var mobileSiteTitleFontSizeSetting = api.instance( 'generate_settings[mobile_site_title_font_size]' ),
mobileSiteTitleFontSize = gpControls.mobileSiteTitleFontSize;
if ( mobileSiteTitleFontSizeSetting && ! mobileSiteTitleFontSizeSetting._dirty && 20 !== mobileSiteTitleFontSizeSetting.get() ) {
2020-04-07 13:03:04 +00:00
mobileSiteTitleFontSize = mobileSiteTitleFontSizeSetting.get();
}
if ( api.instance( 'generate_settings[mobile_site_title_font_size]' ) ) {
if ( 'enable' === newval ) {
api.instance( 'generate_settings[mobile_site_title_font_size]' ).set( 20 );
} else {
api.instance( 'generate_settings[mobile_site_title_font_size]' ).set( mobileSiteTitleFontSize );
}
2020-04-07 13:03:04 +00:00
}
} );
} );
} )( jQuery, wp.customize );