I am new to WordPress, and trying to make a child theme with customizer options.
For part of this, I have code that can only run only once an image has loaded, and I want to use information from the image to update other customize settings. I have both of these things working seperately.
When I enqueue the javascript in customize_preview_init, the image loads fine and I am able to do operations on it, but I cannot update other customizer settings. When I enqueue the javascript in customize_controls_enqueue_scripts, onload no longer works, but I can set the other setting to things (outside of onload)
How do I have onload run in a script enqueued in customize_controls_enqueue_scripts, or is there a better way to accomplish this? Thank you!!
In my customizer class constructer:
add_action( 'customize_controls_enqueue_scripts' or 'customize_preview_init' , array( $this, 'my_link_js') );
In link_test.js:
( function( $ ) {
wp.customize( 'logo1', 'setting1', function( value, setting1) {
value.bind( function( newval ) { //on logo upload?
var image_in = new Image;
image_in.onload = function(){
console.log("here?"); //this never happens
//[Image processing things happen, a settingFromImage variable is created]
setting1.set(settingFromImage);
}
image_in.src = newval;
setting1.set(arbitraryValue); //works if tried here
} );
} );
} )( jQuery );