Make WordPress Core

Changeset 20241


Ignore:
Timestamp:
03/21/2012 07:10:13 PM (15 years ago)
Author:
nacin
Message:

Use display_header_text() in custom-header.php. Rework the UI to be a 'Show header text' checkbox (rather than radio buttons). Remove lame 'blank' hack for no-JS -- checkboxes work without JS. Move 'Select a Color' to a link like it is for custom background. Nearby code cleanup. see #18887.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/custom-header.php

    r20212 r20241  
    209209                }
    210210
    211                 if ( isset( $_POST['text-color'] ) ) {
     211                if ( ! isset( $_POST['display-header-text'] ) ) {
     212                        check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
     213                        set_theme_mod( 'header_textcolor', 'blank' );
     214                } elseif ( isset( $_POST['text-color'] ) ) {
    212215                        check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
    213216                        $_POST['text-color'] = str_replace( '#', '', $_POST['text-color'] );
    214                         if ( 'blank' == $_POST['text-color'] ) {
     217                        $color = preg_replace('/[^0-9a-fA-F]/', '', $_POST['text-color']);
     218                        if ( strlen($color) == 6 || strlen($color) == 3 )
     219                                set_theme_mod('header_textcolor', $color);
     220                        elseif ( ! $color )
    215221                                set_theme_mod( 'header_textcolor', 'blank' );
    216                         } else {
    217                                 $color = preg_replace('/[^0-9a-fA-F]/', '', $_POST['text-color']);
    218                                 if ( strlen($color) == 6 || strlen($color) == 3 )
    219                                         set_theme_mod('header_textcolor', $color);
    220                         }
    221222                }
    222223
    … …  
    330331<script type="text/javascript">
    331332/* <![CDATA[ */
    332         var text_objects = ['#name', '#desc', '#text-color-row'];
    333         var farbtastic;
    334         var default_color = '#<?php echo get_theme_support( 'custom-header', 'default-text-color' ); ?>';
    335         var old_color = null;
     333var farbtastic;
     334(function($){
     335        var default_color = '#<?php echo get_theme_support( 'custom-header', 'default-text-color' ); ?>',
     336                header_text_fields;
    336337
    337338        function pickColor(color) {
    338                 jQuery('#name').css('color', color);
    339                 jQuery('#desc').css('color', color);
    340                 jQuery('#text-color').val(color);
     339                $('#name').css('color', color);
     340                $('#desc').css('color', color);
     341                $('#text-color').val(color);
    341342                farbtastic.setColor(color);
    342343        }
    343344
    344         function toggle_text(s) {
    345                 if (jQuery(s).attr('id') == 'showtext' && jQuery('#text-color').val() != 'blank')
     345        function toggle_text() {
     346                var checked = $('#display-header-text').prop('checked'),
     347                        text_color;
     348                header_text_fields.toggle( checked );
     349                if ( ! checked )
    346350                        return;
    347 
    348                 if (jQuery(s).attr('id') == 'hidetext' && jQuery('#text-color').val() == 'blank')
    349                         return;
    350 
    351                 if (jQuery('#text-color').val() == 'blank') {
    352                         //Show text
    353                         if (old_color == '#blank')
    354                                 old_color = default_color;
    355 
    356                         jQuery( text_objects.toString() ).show();
    357                         jQuery('#text-color').val(old_color);
    358                         jQuery('#name').css('color', old_color);
    359                         jQuery('#desc').css('color', old_color);
    360                         pickColor(old_color);
     351                text_color = $('#text-color');
     352                if ( '' == text_color.val().replace('#', '') ) {
     353                        text_color.val( default_color );
     354                        pickColor( default_color );
    361355                } else {
    362                         //Hide text
    363                         jQuery( text_objects.toString() ).hide();
    364                         old_color = jQuery('#text-color').val();
    365                         jQuery('#text-color').val('blank');
    366                 }
    367         }
    368 
    369         jQuery(document).ready(function() {
    370                 jQuery('#pickcolor').click(function() {
    371                         jQuery('#color-picker').show();
     356                        pickColor( text_color.val() );
     357                }
     358        }
     359
     360        $(document).ready(function() {
     361                header_text_fields = $('.displaying-header-text');
     362                $('#pickcolor').click(function(e) {
     363                        e.preventDefault();
     364                        $('#color-picker').show();
    372365                });
    373366
    374                 jQuery('input[name="hidetext"]').click(function() {
    375                         toggle_text(this);
     367                $('#display-header-text').click( toggle_text );
     368
     369                $('#defaultcolor').click(function() {
     370                        pickColor(default_color);
     371                        $('#text-color').val(default_color);
    376372                });
    377373
    378                 jQuery('#defaultcolor').click(function() {
    379                         pickColor(default_color);
    380                         jQuery('#text-color').val(default_color)
    381                 });
    382 
    383                 jQuery('#text-color').keyup(function() {
    384                         var _hex = jQuery('#text-color').val();
     374                $('#text-color').keyup(function() {
     375                        var _hex = $('#text-color').val();
    385376                        var hex = _hex;
    386377                        if ( hex[0] != '#' )
    … …  
    388379                        hex = hex.replace(/[^#a-fA-F0-9]+/, '');
    389380                        if ( hex != _hex )
    390                                 jQuery('#text-color').val(hex);
     381                                $('#text-color').val(hex);
    391382                        if ( hex.length == 4 || hex.length == 7 )
    392383                                pickColor( hex );
    393384                });
    394385
    395                 jQuery(document).mousedown(function(){
    396                         jQuery('#color-picker').each( function() {
    397                                 var display = jQuery(this).css('display');
     386                $(document).mousedown(function(){
     387                        $('#color-picker').each( function() {
     388                                var display = $(this).css('display');
    398389                                if (display == 'block')
    399                                         jQuery(this).fadeOut(2);
     390                                        $(this).fadeOut(2);
    400391                        });
    401392                });
    402393
    403                 farbtastic = jQuery.farbtastic('#color-picker', function(color) { pickColor(color); });
    404                 <?php if ( $color = get_header_textcolor() ) { ?>
    405                 pickColor('#<?php echo $color; ?>');
    406                 <?php } ?>
    407 
    408                 <?php if ( 'blank' == $color || '' == $color || ! current_theme_supports( 'custom-header', 'header-text' ) ) { ?>
    409                 toggle_text();
     394                farbtastic = $.farbtastic('#color-picker', function(color) { pickColor(color); });
     395                <?php if ( display_header_text() ) { ?>
     396                pickColor('#<?php echo get_header_textcolor(); ?>');
     397                <?php } else { ?>
     398                toggle_text();         
    410399                <?php } ?>
    411400        });
     401})(jQuery);
    412402/* ]]> */
    413403</script>
    … …  
    508498<?php } ?>
    509499
     500<h3><?php _e( 'Header Image' ); ?></h3>
     501
    510502<table class="form-table">
    511503<tbody>
    … …  
    520512        <div id="headimg" style="background-image:url(<?php esc_url ( header_image() ) ?>);max-width:<?php echo get_custom_header()->width; ?>px;height:<?php echo get_custom_header()->height; ?>px;">
    521513                <?php
    522                 $color = get_header_textcolor();
    523                 if ( 'blank' == $color || '' == $color || ! current_theme_supports( 'custom-header', 'header-text' ) )
     514                if ( display_header_text() )
     515                        $style = ' style="color:#' . get_header_textcolor() . ';"';
     516                else
    524517                        $style = ' style="display:none;"';
    525                 else
    526                         $style = ' style="color:#' . $color . ';"';
    527518                ?>
    528                 <h1><a id="name"<?php echo $style; ?> onclick="return false;" href="<?php bloginfo('url'); ?>"><?php bloginfo( 'name' ); ?></a></h1>
    529                 <div id="desc"<?php echo $style; ?>><?php bloginfo( 'description' ); ?></div>
     519                <h1><a id="name" class="displaying-header-text" <?php echo $style; ?> onclick="return false;" href="<?php bloginfo('url'); ?>"><?php bloginfo( 'name' ); ?></a></h1>
     520                <div id="desc" class="displaying-header-text" <?php echo $style; ?>><?php bloginfo( 'description' ); ?></div>
    530521        </div>
    531522        <?php } ?>
    … …  
    619610</tbody>
    620611</table>
    621         <?php if ( current_theme_supports( 'custom-header', 'header-text' ) ) : ?>
     612
     613<?php if ( current_theme_supports( 'custom-header', 'header-text' ) ) : ?>
     614
     615<h3><?php _e( 'Header Text' ); ?></h3>
     616
    622617<table class="form-table">
    623618<tbody>
    624 <tr valign="top" class="hide-if-no-js">
    625 <th scope="row"><?php _e( 'Display Text' ); ?></th>
     619<tr valign="top">
     620<th scope="row"><?php _e( 'Header Text' ); ?></th>
    626621<td>
    627622        <p>
    628         <?php
    629                 $show_text = get_header_textcolor();
    630                 if ( 'blank' == $show_text )
    631                         $show_text = false;
    632                 else
    633                         $show_text = (bool) $show_text;
    634         ?>
    635         <label><input type="radio" value="1" name="hidetext" id="hidetext"<?php checked( ! $show_text ); ?> /> <?php _e( 'No' ); ?></label>
    636         <label><input type="radio" value="0" name="hidetext" id="showtext"<?php checked( $show_text ); ?> /> <?php _e( 'Yes' ); ?></label>
     623        <label><input type="checkbox" name="display-header-text" id="display-header-text"<?php checked( display_header_text() ); ?> /> <?php _e( 'Show header text with your image.' ); ?></label>
    637624        </p>
    638625</td>
    639626</tr>
    640627
    641 <tr valign="top" id="text-color-row">
     628<tr valign="top" class="displaying-header-text">
    642629<th scope="row"><?php _e( 'Text Color' ); ?></th>
    643630<td>
    644631        <p>
     632<?php if ( display_header_text() ) : ?>
    645633                <input type="text" name="text-color" id="text-color" value="#<?php echo esc_attr( get_header_textcolor() ); ?>" />
    646                 <span class="description hide-if-js"><?php _e( 'If you want to hide header text, add <strong>#blank</strong> as text color.' );?></span>
    647                 <input type="button" class="button hide-if-no-js" value="<?php esc_attr_e( 'Select a Color' ); ?>" id="pickcolor" />
     634<?php else : ?>
     635                <input type="text" name="text-color" id="text-color" value="#<?php echo esc_attr( get_theme_support( 'custom-header', 'default-text-color' ) ); ?>" />
     636<?php endif; ?>
     637                <a href="#" class="hide-if-no-js" id="pickcolor"><?php _e( 'Select a Color' ); ?></a>
    648638        </p>
    649639        <div id="color-picker" style="z-index: 100; background:#eee; border:1px solid #ccc; position:absolute; display:none;"></div>
    … …  
    663653</tbody>
    664654</table>
    665         <?php endif;
     655<?php endif;
    666656
    667657do_action( 'custom_header_options' );
Note: See TracChangeset for help on using the changeset viewer.