-
-
Save cvhau/03530c9c1306333753b675bb5a8065e6 to your computer and use it in GitHub Desktop.
jQuery function for update events on WordPress widgets save/add
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
( 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