Skip to content

Instantly share code, notes, and snippets.

@farinspace
Created September 27, 2014 15:32
Show Gist options
  • Save farinspace/0ad43a604d5740094725 to your computer and use it in GitHub Desktop.
Save farinspace/0ad43a604d5740094725 to your computer and use it in GitHub Desktop.
Using a color picker with WPAlchemy
jQuery(function($){
var picker_config = {
onSubmit: function(hsb, hex, rgb, el) {
$(el).val(hex);
$(el).ColorPickerHide();
},
onBeforeShow: function () {
$(this).ColorPickerSetColor(this.value);
},
onChange: function (hsb, hex, rgb) {
var el = $(this).data('colorpicker').el;
$(el).val(hex);
}
};
var keyup_handler = function(e) {
$(this).ColorPickerSetColor($(this).val());
};
// initialize all current inputs
$('.color-picker').ColorPicker(picker_config).on('keyup', keyup_handler);
// event fired when an element is cloned
$.wpalchemy.on('wpa_copy', function(el){
// initialize the new colorpicker
$(el).ColorPicker(picker_config).on('keyup', keyup_handler);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment