Skip to content

Instantly share code, notes, and snippets.

@raulillana
Forked from seedprod/gist:1181262
Last active September 30, 2015 23:08
Show Gist options
  • Save raulillana/1878051 to your computer and use it in GitHub Desktop.
Save raulillana/1878051 to your computer and use it in GitHub Desktop.
WordPress Farbtastic Color Picker for Multiple Instances
<!-- WordPress Farbtastic Color Picker for Multiple Instances -->
<div style="position:relative;">
<input type="text" name="my-theme-options[color]" id="color" />
<input type="button" class="pickcolor button-secondary" value="<?php _e('Select Color') ?>">
<div class="colorpicker" style="z-index:100; position:absolute; display:none;"></div>
</div>
<script>
// Include this script in your JS related file
$('.pickcolor').click(function(e) {
colorPicker = jQuery(this).next('div');
input = jQuery(this).prev('input');
$.farbtastic($(colorPicker), function(a) { $(input).val(a).css('background', a); });
colorPicker.show();
e.preventDefault();
$(document).mousedown( function() { $(colorPicker).hide(); });
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment