Created
September 27, 2014 15:32
-
-
Save farinspace/0ad43a604d5740094725 to your computer and use it in GitHub Desktop.
Using a color picker with WPAlchemy
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
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