Add instant background-color feedback to Custom Backgrounds. Add input validation to user-entered colour data. See #12186

git-svn-id: https://develop.svn.wordpress.org/trunk@13764 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dion Hulse 2010-03-19 09:10:37 +00:00
parent 12c0c3d475
commit 06c835eba5
1 changed files with 12 additions and 0 deletions

View File

@ -179,12 +179,24 @@ class Custom_Background {
function pickColor(color) {
jQuery('#background-color').val(color);
farbtastic.setColor(color);
jQuery('#custom-background-image').css('background-color', color);
}
jQuery(document).ready(function() {
jQuery('#pickcolor').click(function() {
jQuery('#colorPickerDiv').show();
});
jQuery('#background-color').keyup(function() {
var _hex = jQuery('#background-color').val();
var hex = _hex;
if ( hex[0] != '#' )
hex = '#' + hex;
hex = hex.replace(/[^#a-fA-F0-9]+/, '');
if ( hex != _hex )
jQuery('#background-color').val(hex);
if ( hex.length == 4 || hex.length == 7 )
pickColor( hex );
});
farbtastic = jQuery.farbtastic('#colorPickerDiv', function(color) { pickColor(color); });
pickColor('#<?php background_color(); ?>');