Make WordPress Core

Ticket #18650: 18650.8.patch

File 18650.8.patch, 2.9 KB (added by SergeyBiryukov, 10 years ago)
  • src/wp-includes/default-widgets.php

     
    279279                /** This filter is documented in wp-includes/default-widgets.php */
    280280                $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Archives' ) : $instance['title'], $instance, $this->id_base );
    281281
     282                $dropdown_id = "{$this->id_base}-dropdown-{$this->number}";
     283
    282284                echo $args['before_widget'];
    283285                if ( $title ) {
    284286                        echo $args['before_title'] . $title . $args['after_title'];
     287
     288                        if ( $d ) {
     289                                printf( '<label class="screen-reader-text" for="%s">%s</label>', esc_attr( $dropdown_id ), $title );
     290                        }
    285291                }
    286292
    287293                if ( $d ) {
    288294?>
    289                 <select name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'>
     295                <select id="<?php echo esc_attr( $dropdown_id ); ?>" name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'>
    290296                        <?php
    291297                        /**
    292298                         * Filter the arguments for the Archives widget drop-down.
     
    563569        }
    564570
    565571        public function widget( $args, $instance ) {
     572                static $first_dropdown = true;
    566573
    567574                /** This filter is documented in wp-includes/default-widgets.php */
    568575                $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title'], $instance, $this->id_base );
     
    571578                $h = ! empty( $instance['hierarchical'] ) ? '1' : '0';
    572579                $d = ! empty( $instance['dropdown'] ) ? '1' : '0';
    573580
     581                if ( $d ) {
     582                        $dropdown_id = ( $first_dropdown ) ? 'cat' : "{$this->id_base}-dropdown-{$this->number}";
     583                        $first_dropdown = false;
     584                }
     585
    574586                echo $args['before_widget'];
    575587                if ( $title ) {
    576588                        echo $args['before_title'] . $title . $args['after_title'];
     589
     590                        if ( $d ) {
     591                                printf( '<label class="screen-reader-text" for="%s">%s</label>', esc_attr( $dropdown_id ), $title );
     592                        }
    577593                }
    578594
    579                 $cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h);
     595                $cat_args = array(
     596                        'orderby'      => 'name',
     597                        'show_count'   => $c,
     598                        'hierarchical' => $h
     599                );
    580600
    581601                if ( $d ) {
    582                         $cat_args['show_option_none'] = __('Select Category');
     602                        $cat_args['show_option_none'] = __( 'Select Category' );
     603                        $cat_args['id'] = $dropdown_id;
    583604
    584605                        /**
    585606                         * Filter the arguments for the Categories widget drop-down.
     
    595616
    596617<script type='text/javascript'>
    597618/* <![CDATA[ */
    598         var dropdown = document.getElementById("cat");
     619(function() {
     620        var dropdown = document.getElementById("<?php echo esc_js( $dropdown_id ); ?>");
    599621        function onCatChange() {
    600622                if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
    601623                        location.href = "<?php echo home_url(); ?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
     
    602624                }
    603625        }
    604626        dropdown.onchange = onCatChange;
     627})();
    605628/* ]]> */
    606629</script>
    607630