Skip to content

Commit

Permalink
fixes #1180
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath committed May 20, 2017
1 parent 3acc2f0 commit ddccb63
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions controls/typography/typography.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,10 @@ wp.customize.controlConstructor['kirki-typography'] = wp.customize.Control.exten
control.saveValue( 'font-family', jQuery( this ).val() );

// Re-init variants selector.
jQuery( variantSelector ).select2( 'destroy' );
control.renderVariantSelector();


// Re-init subsets selector.
jQuery( subsetSelector ).select2( 'destroy' );
control.renderSubsetSelector();
});
},
Expand All @@ -132,29 +131,41 @@ wp.customize.controlConstructor['kirki-typography'] = wp.customize.Control.exten
variants = control.getVariants( fontFamily ),
selector = control.selector + ' .variant select',
data = [],
isValid = false,
variantSelector;

if ( false !== variants ) {
jQuery( control.selector + ' .variant' ).show();
_.each( variants, function( variant ) {
if ( value.variant === variant.id ) {
isValid = true;
}
data.push({
id: variant.id,
text: variant.label
});
});
if ( ! isValid ) {
value.variant = 'regular';
control.saveValue( 'variant', value.variant );
}

if ( jQuery( selector ).hasClass( 'select2-hidden-accessible' ) ) {
jQuery( selector ).select2( 'destroy' );
jQuery( selector ).empty();
}

// Instantiate select2 with the data.
variantSelector = jQuery( selector ).select2({
data: data
});
variantSelector.val( value.variant );
variantSelector.on( 'change', function() {
control.saveValue( 'variant', jQuery( this ).val() );
});
} else {
jQuery( control.selector + ' .variant' ).hide();
}

// Instantiate select2 with the data.
variantSelector = jQuery( selector ).select2({
data: data
});
variantSelector.val( value.variant );
variantSelector.on( 'change', function() {
control.saveValue( 'variant', jQuery( this ).val() );
});
},

/**
Expand Down Expand Up @@ -184,6 +195,11 @@ wp.customize.controlConstructor['kirki-typography'] = wp.customize.Control.exten
jQuery( control.selector + ' .subsets' ).hide();
}

if ( jQuery( selector ).hasClass( 'select2-hidden-accessible' ) ) {
jQuery( selector ).select2( 'destroy' );
jQuery( selector ).empty();
}

// Instantiate select2 with the data.
subsetSelector = jQuery( selector ).select2({
data: data
Expand Down

0 comments on commit ddccb63

Please sign in to comment.