Twenty Eleven: Properly handle the default link color for the dark theme. props dcowgill for the patch refresh. fixes #17351.
git-svn-id: http://svn.automattic.com/wordpress/trunk@18198 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
296fdb256e
commit
e68bd9e42e
|
@ -8,6 +8,8 @@ var farbtastic;
|
||||||
};
|
};
|
||||||
|
|
||||||
$(document).ready( function() {
|
$(document).ready( function() {
|
||||||
|
$('#default-color').wrapInner('<a href="#" />');
|
||||||
|
|
||||||
farbtastic = $.farbtastic('#colorPickerDiv', pickColor);
|
farbtastic = $.farbtastic('#colorPickerDiv', pickColor);
|
||||||
|
|
||||||
pickColor( $('#link-color').val() );
|
pickColor( $('#link-color').val() );
|
||||||
|
@ -31,5 +33,20 @@ var farbtastic;
|
||||||
$(document).mousedown( function() {
|
$(document).mousedown( function() {
|
||||||
$('#colorPickerDiv').hide();
|
$('#colorPickerDiv').hide();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#default-color a').click( function(e) {
|
||||||
|
pickColor( '#' + this.innerHTML.replace(/[^a-fA-F0-9]/, '') );
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.image-radio-option input:radio').change( function() {
|
||||||
|
var currentDefault = $('#default-color a'),
|
||||||
|
newDefault;
|
||||||
|
if ( $('#link-color').val() !== currentDefault.text() )
|
||||||
|
return;
|
||||||
|
newDefault = $(this).next().val();
|
||||||
|
currentDefault.text( newDefault );
|
||||||
|
pickColor( newDefault );
|
||||||
|
});
|
||||||
});
|
});
|
||||||
})(jQuery);
|
})(jQuery);
|
|
@ -118,11 +118,13 @@ function twentyeleven_color_schemes() {
|
||||||
'value' => 'light',
|
'value' => 'light',
|
||||||
'label' => __( 'Light', 'twentyeleven' ),
|
'label' => __( 'Light', 'twentyeleven' ),
|
||||||
'thumbnail' => get_template_directory_uri() . '/inc/images/light.png',
|
'thumbnail' => get_template_directory_uri() . '/inc/images/light.png',
|
||||||
|
'default_link_color' => '#1b8be0',
|
||||||
),
|
),
|
||||||
'dark' => array(
|
'dark' => array(
|
||||||
'value' => 'dark',
|
'value' => 'dark',
|
||||||
'label' => __( 'Dark', 'twentyeleven' ),
|
'label' => __( 'Dark', 'twentyeleven' ),
|
||||||
'thumbnail' => get_template_directory_uri() . '/inc/images/dark.png',
|
'thumbnail' => get_template_directory_uri() . '/inc/images/dark.png',
|
||||||
|
'default_link_color' => '#e4741f',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -164,13 +166,34 @@ function twentyeleven_layouts() {
|
||||||
function twentyeleven_get_default_theme_options() {
|
function twentyeleven_get_default_theme_options() {
|
||||||
$default_theme_options = array(
|
$default_theme_options = array(
|
||||||
'color_scheme' => 'light',
|
'color_scheme' => 'light',
|
||||||
'link_color' => '#1b8be0',
|
'link_color' => twentyeleven_get_default_link_color( 'light' ),
|
||||||
'theme_layout' => 'content-sidebar',
|
'theme_layout' => 'content-sidebar',
|
||||||
);
|
);
|
||||||
|
|
||||||
return apply_filters( 'twentyeleven_default_theme_options', $default_theme_options );
|
return apply_filters( 'twentyeleven_default_theme_options', $default_theme_options );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the default link color for Twenty Eleven, based on color scheme.
|
||||||
|
*
|
||||||
|
* @since Twenty Eleven 1.0
|
||||||
|
*
|
||||||
|
* @param $string $color_scheme Color scheme. Defaults to the active color scheme.
|
||||||
|
* @return $string Color.
|
||||||
|
*/
|
||||||
|
function twentyeleven_get_default_link_color( $color_scheme = null ) {
|
||||||
|
if ( null === $color_scheme ) {
|
||||||
|
$options = twentyeleven_get_theme_options();
|
||||||
|
$color_scheme = $options['color_scheme'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$color_schemes = twentyeleven_color_schemes();
|
||||||
|
if ( ! isset( $color_schemes[ $color_scheme ] ) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return $color_schemes[ $color_scheme ]['default_link_color'];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the options array for Twenty Eleven.
|
* Returns the options array for Twenty Eleven.
|
||||||
*
|
*
|
||||||
|
@ -205,14 +228,15 @@ function theme_options_render_page() {
|
||||||
<td>
|
<td>
|
||||||
<fieldset><legend class="screen-reader-text"><span><?php _e( 'Color Scheme', 'twentyeleven' ); ?></span></legend>
|
<fieldset><legend class="screen-reader-text"><span><?php _e( 'Color Scheme', 'twentyeleven' ); ?></span></legend>
|
||||||
<?php
|
<?php
|
||||||
foreach ( twentyeleven_color_schemes() as $color ) {
|
foreach ( twentyeleven_color_schemes() as $scheme ) {
|
||||||
?>
|
?>
|
||||||
<div class="layout">
|
<div class="layout">
|
||||||
<label class="description">
|
<label class="description">
|
||||||
<input type="radio" name="twentyeleven_theme_options[color_scheme]" value="<?php echo esc_attr( $color['value'] ); ?>" <?php checked( $options['color_scheme'], $color['value'] ); ?> />
|
<input type="radio" name="twentyeleven_theme_options[color_scheme]" value="<?php echo esc_attr( $scheme['value'] ); ?>" <?php checked( $options['color_scheme'], $scheme['value'] ); ?> />
|
||||||
|
<input type="hidden" id="default-color-<?php echo esc_attr( $scheme['value'] ); ?>" value="<?php echo esc_attr( $scheme['default_link_color'] ); ?>" />
|
||||||
<span>
|
<span>
|
||||||
<img src="<?php echo esc_url( $color['thumbnail'] ); ?>" alt=""/>
|
<img src="<?php echo esc_url( $scheme['thumbnail'] ); ?>" width="136" height="122" alt="" />
|
||||||
<?php echo $color['label']; ?>
|
<?php echo $scheme['label']; ?>
|
||||||
</span>
|
</span>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
@ -231,7 +255,7 @@ function theme_options_render_page() {
|
||||||
<input type="button" class="pickcolor button hide-if-no-js" value="<?php esc_attr_e( 'Select a Color', 'twentyeleven' ); ?>" />
|
<input type="button" class="pickcolor button hide-if-no-js" value="<?php esc_attr_e( 'Select a Color', 'twentyeleven' ); ?>" />
|
||||||
<div id="colorPickerDiv" style="z-index: 100; background:#eee; border:1px solid #ccc; position:absolute; display:none;"></div>
|
<div id="colorPickerDiv" style="z-index: 100; background:#eee; border:1px solid #ccc; position:absolute; display:none;"></div>
|
||||||
<br />
|
<br />
|
||||||
<small class="description"><?php printf( __( 'Default color: %s', 'twentyeleven' ), $default_options['link_color'] ); ?></small>
|
<span><?php printf( __( 'Default color: %s', 'twentyeleven' ), '<span id="default-color">' . twentyeleven_get_default_link_color( $options['color_scheme'] ) . '</span>' ); ?></span>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -246,7 +270,7 @@ function theme_options_render_page() {
|
||||||
<label class="description">
|
<label class="description">
|
||||||
<input type="radio" name="twentyeleven_theme_options[theme_layout]" value="<?php echo esc_attr( $layout['value'] ); ?>" <?php checked( $options['theme_layout'], $layout['value'] ); ?> />
|
<input type="radio" name="twentyeleven_theme_options[theme_layout]" value="<?php echo esc_attr( $layout['value'] ); ?>" <?php checked( $options['theme_layout'], $layout['value'] ); ?> />
|
||||||
<span>
|
<span>
|
||||||
<img src="<?php echo esc_url( $layout['thumbnail'] ); ?>" alt=""/>
|
<img src="<?php echo esc_url( $layout['thumbnail'] ); ?>" width="136" height="122" alt="" />
|
||||||
<?php echo $layout['label']; ?>
|
<?php echo $layout['label']; ?>
|
||||||
</span>
|
</span>
|
||||||
</label>
|
</label>
|
||||||
|
@ -280,6 +304,9 @@ function twentyeleven_theme_options_validate( $input ) {
|
||||||
if ( isset( $input['color_scheme'] ) && array_key_exists( $input['color_scheme'], twentyeleven_color_schemes() ) )
|
if ( isset( $input['color_scheme'] ) && array_key_exists( $input['color_scheme'], twentyeleven_color_schemes() ) )
|
||||||
$output['color_scheme'] = $input['color_scheme'];
|
$output['color_scheme'] = $input['color_scheme'];
|
||||||
|
|
||||||
|
// Our defaults for the link color may have changed, based on the color scheme.
|
||||||
|
$output['link_color'] = $defaults['link_color'] = twentyeleven_get_default_link_color( $output['color_scheme'] );
|
||||||
|
|
||||||
// Link color must be 3 or 6 hexadecimal characters
|
// Link color must be 3 or 6 hexadecimal characters
|
||||||
if ( isset( $input['link_color'] ) && preg_match( '/^#?([a-f0-9]{3}){1,2}$/i', $input['link_color'] ) )
|
if ( isset( $input['link_color'] ) && preg_match( '/^#?([a-f0-9]{3}){1,2}$/i', $input['link_color'] ) )
|
||||||
$output['link_color'] = '#' . strtolower( ltrim( $input['link_color'], '#' ) );
|
$output['link_color'] = '#' . strtolower( ltrim( $input['link_color'], '#' ) );
|
||||||
|
|
Loading…
Reference in New Issue