Skip to content

Instantly share code, notes, and snippets.

@cvhau
Forked from pagelab/widget-update-function.js
Created April 19, 2022 09:16
Show Gist options
  • Save cvhau/03530c9c1306333753b675bb5a8065e6 to your computer and use it in GitHub Desktop.
Save cvhau/03530c9c1306333753b675bb5a8065e6 to your computer and use it in GitHub Desktop.
jQuery function for update events on WordPress widgets save/add
( function( $ ){
function initColorPicker( widget ) {
widget.find( '.color-picker' ).wpColorPicker( {
change: _.throttle( function() { // For Customizer
$(this).trigger( 'change' );
}, 3000 )
});
}
function onFormUpdate( event, widget ) {
initColorPicker( widget );
}
$( document ).on( 'widget-added widget-updated', onFormUpdate );
$( document ).ready( function() {
$( '#widgets-right .widget:has(.color-picker)' ).each( function () {
initColorPicker( $( this ) );
} );
} );
}( jQuery ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment