laipower/wp-content/plugins/gp-premium/secondary-nav/functions/js/customizer.js

78 lines
3.5 KiB
JavaScript
Raw Normal View History

(function( $ ){
/**
2020-04-07 13:03:04 +00:00
* Navigation width
*/
wp.customize( 'generate_secondary_nav_settings[secondary_nav_layout_setting]', function( value ) {
value.bind( function( newval ) {
var navLocation = wp.customize.value('generate_secondary_nav_settings[secondary_nav_position_setting]')();
2020-04-07 13:03:04 +00:00
if ( 'secondary-fluid-nav' == newval ) {
$( '.secondary-navigation' ).removeClass( 'grid-container' ).removeClass( 'grid-parent' );
if ( 'full-width' !== wp.customize.value('generate_secondary_nav_settings[secondary_nav_inner_width]')() ) {
$( '.secondary-navigation .inside-navigation' ).addClass( 'grid-container' ).addClass( 'grid-parent' );
}
}
if ( 'secondary-contained-nav' == newval ) {
if ( generateSecondaryNav.isFlex && ( 'secondary-nav-float-right' === navLocation || 'secondary-nav-float-left' === navLocation ) ) {
return;
}
2020-04-07 13:03:04 +00:00
jQuery( '.secondary-navigation' ).addClass( 'grid-container' ).addClass( 'grid-parent' );
jQuery( '.secondary-navigation .inside-navigation' ).removeClass( 'grid-container' ).removeClass( 'grid-parent' );
}
} );
} );
/**
2020-04-07 13:03:04 +00:00
* Inner navigation width
*/
wp.customize( 'generate_secondary_nav_settings[secondary_nav_inner_width]', function( value ) {
value.bind( function( newval ) {
if ( 'full-width' == newval ) {
$( '.secondary-navigation .inside-navigation' ).removeClass( 'grid-container' ).removeClass( 'grid-parent' );
}
if ( 'contained' == newval ) {
$( '.secondary-navigation .inside-navigation' ).addClass( 'grid-container' ).addClass( 'grid-parent' );
}
} );
} );
2020-04-07 13:03:04 +00:00
wp.customize( 'generate_secondary_nav_settings[secondary_nav_alignment]', function( value ) {
value.bind( function( newval ) {
var classes = [ 'secondary-nav-aligned-left', 'secondary-nav-aligned-center', 'secondary-nav-aligned-right' ];
$.each( classes, function( i, v ) {
$( 'body' ).removeClass( v );
});
$( 'body' ).addClass( 'secondary-nav-aligned-' + newval );
} );
} );
2020-04-07 13:03:04 +00:00
wp.customize( 'generate_secondary_nav_settings[secondary_menu_item]', function( value ) {
value.bind( function( newval ) {
jQuery( 'head' ).append( '<style id="secondary_menu_item">.secondary-navigation .main-nav ul li a, .secondary-navigation .menu-toggle, .secondary-menu-bar-items .menu-bar-item > a{padding: 0 ' + newval + 'px;}.secondary-navigation .menu-item-has-children .dropdown-menu-toggle{padding-right:' + newval + 'px;}</style>' );
2020-04-07 13:03:04 +00:00
setTimeout(function() {
jQuery( 'style#secondary_menu_item' ).not( ':last' ).remove();
}, 50);
} );
} );
2020-04-07 13:03:04 +00:00
wp.customize( 'generate_secondary_nav_settings[secondary_menu_item_height]', function( value ) {
value.bind( function( newval ) {
jQuery( 'head' ).append( '<style id="secondary_menu_item_height">.secondary-navigation .main-nav ul li a, .secondary-navigation .menu-toggle, .secondary-navigation .top-bar, .secondary-navigation .menu-bar-item > a{line-height: ' + newval + 'px;}.secondary-navigation ul ul{top:' + newval + 'px;}</style>' );
2020-04-07 13:03:04 +00:00
setTimeout(function() {
jQuery( 'style#secondary_menu_item_height' ).not( ':last' ).remove();
}, 50);
} );
} );
2020-04-07 13:03:04 +00:00
wp.customize( 'generate_secondary_nav_settings[secondary_sub_menu_item_height]', function( value ) {
value.bind( function( newval ) {
jQuery( 'head' ).append( '<style id="secondary_sub_menu_item_height">.secondary-navigation .main-nav ul ul li a{padding-top: ' + newval + 'px;padding-bottom: ' + newval + 'px;}</style>' );
setTimeout(function() {
jQuery( 'style#secondary_sub_menu_item_height' ).not( ':last' ).remove();
}, 50);
} );
} );
})( jQuery );