Skip to content

Instantly share code, notes, and snippets.

@pagelab
Created June 30, 2015 21:50
Show Gist options
  • Save pagelab/cdc57b12736aef0077ac to your computer and use it in GitHub Desktop.
Save pagelab/cdc57b12736aef0077ac 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