I’ve written a operate for my WP theme primarily based off of this query:Altering your complete management decisions utilizing wp.customise with JavaScript
My code is as follows:
( operate( wp, $ ) {
wp.customise.management( 'google_fonts_body', operate( management ) {
management.setting.bind( operate( to ) {
var selectElem = wp.customise.management( 'body_font_weight' ).container.discover( 'choose' );
var fontsList = theFont[0];
selectElem.empty();
var choice = '';
// Do Stuff
selectElem.append( choice );
} );
} );
} )( wp, jQuery );
This script watches for the wp.customise.management for my physique font, after which will replace a associated setting for the font weight. Some code stripped for brevity.
The code is working simply tremendous, however I discover that it’s executing for each character that modifications within the physique font title because the consumer is typing it, relatively than as the sector updates when the consumer leaves the sector (like an onChange occasion would do). The font title entry brings up a menu of decisions, the consumer simply must enter sufficient textual content to seek out the font title they need. For reference, that subject is outlined as follows:
$wp_customize->add_setting( 'google_fonts_body',
array(
'default' => $default_fonts['body'],
'transport' => 'refresh',
'sanitize_callback' => 'throwback_sanitize_font_body',
)
);
$wp_customize->add_control( 'google_fonts_body',
array(
'label' => __( 'Google font for content material', 'throwback' ),
'part' => 'font_family-settings',
'sort' => 'textual content',
'input_attrs' => array(
'placeholder' => __( 'Enter any Google Font title', 'throwback' ),
'listing' => 'throwback-fonts-list',
),
)
);
I do not know sufficient but about WP and JQuery to know the right way to right this, assuming it is attainable. I am simply making an attempt to maintain code from working unnecessarily with every key entry if in any respect attainable.