Restore keyboard accessibility to the color picker. Props lessbloat. see #21206

git-svn-id: https://develop.svn.wordpress.org/trunk@22385 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2012-11-05 23:00:15 +00:00
parent 0d86cdf176
commit f6d899210a
4 changed files with 40 additions and 36 deletions

View File

@ -6,19 +6,12 @@
} }
.wp-color-result { .wp-color-result {
background-color: #f9f9f9; background-color: #f9f9f9;
border: 1px solid #c4c4c4; border: 1px solid #bbb;
-moz-border-radius: 4px; border-radius: 2px;
-webkit-border-radius: 4px;
border-radius: 4px;
box-shadow: inset 1px 1px 0 rgba(0,0,0,.05);
-moz-box-shadow: inset 1px 1px 0 rgba(0,0,0,.05);
-ms-box-shadow: inset 1px 1px 0 rgba(0,0,0,.05);
-o-box-shadow: inset 1px 1px 0 rgba(0,0,0,.05);
-webkit-box-shadow: inset 1px 1px 0 rgba(0,0,0,.05);
cursor: pointer; cursor: pointer;
display: inline-block; display: inline-block;
height: 21px; height: 22px;
margin: 0 6px 1px 0px; margin: 0 6px 6px 0px;
position: relative; position: relative;
top: 1px; top: 1px;
user-select: none; user-select: none;
@ -29,24 +22,21 @@
display: inline-block; display: inline-block;
padding-left: 30px; padding-left: 30px;
} }
.wp-color-result::after { .wp-color-result:after {
background-color: #f9f9f9; background: #f3f3f3;
background-image: -moz-linear-gradient(top, #fff 0%, #eee 100%); background-image: -webkit-gradient(linear, left top, left bottom, from(#fefefe), to(#f4f4f4));
background-image: -webkit-linear-gradient(top, #fff 0%, #eee 100%); background-image: -webkit-linear-gradient(top, #fefefe, #f4f4f4);
background-image: -ms-linear-gradient(top, #fff 0%, #eee 100%); background-image: -moz-linear-gradient(top, #fefefe, #f4f4f4);
background-image: -o-linear-gradient(top, #fff 0%, #eee 100%); background-image: -o-linear-gradient(top, #fefefe, #f4f4f4);
background-image: linear-gradient(top, #fff 0%, #eee 100%); background-image: linear-gradient(to bottom, #fefefe, #f4f4f4);
-moz-border-radius-bottomright: 3px; color: #333;
-moz-border-radius-topright: 3px; text-shadow: 0 1px 0 #fff;
-webkit-border-radius: 0 3px 3px 0; border-radius: 0 1px 1px 0;
border-radius: 0 3px 3px 0; border-left: 1px solid #bbb;
border-bottom-right-radius: 3px;
border-left: 1px solid #c4c4c4;
content: attr( title ); content: attr( title );
color: #555;
display: block; display: block;
font-size: 11px; font-size: 11px;
line-height: 21px; line-height: 22px;
padding: 0 6px; padding: 0 6px;
position: relative; position: relative;
right: 0px; right: 0px;
@ -68,7 +58,6 @@
} }
.wp-color-result.wp-picker-open { .wp-color-result.wp-picker-open {
top: 0; top: 0;
/*width: 5px;*/
} }
.wp-color-result.wp-picker-open:after { .wp-color-result.wp-picker-open:after {
content: attr( data-current ); content: attr( data-current );
@ -88,6 +77,10 @@
.wp-color-result:focus:after { .wp-color-result:focus:after {
border-color: #888; border-color: #888;
} }
.wp-picker-open + .wp-picker-input-wrap {
display: inline-block;
vertical-align: top;
}
.wp-picker-container .button { .wp-picker-container .button {
margin-left: 6px; margin-left: 6px;
} }

View File

@ -338,6 +338,7 @@ body {
width: 65px; width: 65px;
font-family: monospace; font-family: monospace;
text-align: center; text-align: center;
line-height: 16px;
} }
/* The centered cursor overlaps the placeholder in webkit. Hide it when selected. */ /* The centered cursor overlaps the placeholder in webkit. Hide it when selected. */

View File

@ -1,10 +1,10 @@
( function( $, undef ){ ( function( $, undef ){
// html stuff // html stuff
var _before = '<a tabindex="0" class="wp-color-result" />'; var _before = '<a tabindex="0" class="wp-color-result" />',
var _after = '<div class="wp-picker-holder" />'; _after = '<div class="wp-picker-holder" />',
var _wrap = '<div class="wp-picker-container" />'; _wrap = '<div class="wp-picker-container" />',
var _button = '<input type="button" class="button button-tiny hidden" />'; _button = '<input type="button" class="button button-small hidden" />';
// jQuery UI Widget constructor // jQuery UI Widget constructor
var ColorPicker = { var ColorPicker = {
@ -36,11 +36,13 @@
else else
self.button.addClass( 'wp-picker-clear' ).val( wpColorPickerL10n.clear ); self.button.addClass( 'wp-picker-clear' ).val( wpColorPickerL10n.clear );
self.button.insertAfter( el ); el.wrap('<span class="wp-picker-input-wrap" />').after(self.button);
el.iris( { el.iris( {
target: self.pickerContainer, target: self.pickerContainer,
hide: true, hide: true,
width: 255,
mode: 'hsv',
change: function( event, ui ) { change: function( event, ui ) {
self.toggler.css( { backgroundColor: ui.color.toString() } ); self.toggler.css( { backgroundColor: ui.color.toString() } );
// check for a custom cb // check for a custom cb
@ -82,8 +84,8 @@
}); });
// open a keyboard-focused closed picker with space or enter // open a keyboard-focused closed picker with space or enter
$( document ).keydown( function( e ) { self.toggler.on('keyup', function( e ) {
if ( self.toggler.is( ':focus' ) && ( e.keyCode === 13 || e.keyCode === 32 ) ) { if ( e.keyCode === 13 || e.keyCode === 32 ) {
e.preventDefault(); e.preventDefault();
self.toggler.trigger('click').next().focus(); self.toggler.trigger('click').next().focus();
} }
@ -112,6 +114,14 @@
return this.element.iris( "option", "color" ); return this.element.iris( "option", "color" );
this.element.iris( "option", "color", newColor ); this.element.iris( "option", "color", newColor );
},
//$("#input").wpColorPicker('default_color') returns the current default color
//$("#input").wpColorPicker('default_color', newDefaultColor) to set
default_color: function( newDefaultColor ) {
if ( newDefaultColor === undef )
return this.options.defaultColor;
this.options.defaultColor = newDefaultColor;
} }
} }

File diff suppressed because one or more lines are too long