Created
June 30, 2015 21:50
-
-
Save pagelab/cdc57b12736aef0077ac to your computer and use it in GitHub Desktop.
jQuery function for update events on WordPress widgets save/add
This file contains 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