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

git-svn-id: http://svn.automattic.com/wordpress/trunk@13764 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
dd32 2010-03-19 09:10:37 +00:00
parent 96db88e1b8
commit 0b4c703fd8
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(); ?>');