Ticket #18650: 18650.7.patch
File 18650.7.patch, 3.0 KB (added by , 10 years ago) |
---|
-
src/wp-includes/default-widgets.php
276 276 $c = ! empty( $instance['count'] ) ? '1' : '0'; 277 277 $d = ! empty( $instance['dropdown'] ) ? '1' : '0'; 278 278 279 $dropdown_id = "{$this->id_base}-dropdown-{$this->number}"; 280 279 281 /** This filter is documented in wp-includes/default-widgets.php */ 280 282 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Archives' ) : $instance['title'], $instance, $this->id_base ); 281 283 282 284 echo $args['before_widget']; 283 285 if ( $title ) { 286 if ( $d ) { 287 $title = sprintf( '<label for="%s">%s</label>', esc_attr( $dropdown_id ), $title ); 288 } 284 289 echo $args['before_title'] . $title . $args['after_title']; 285 290 } 286 291 287 292 if ( $d ) { 288 293 ?> 289 <select name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'>294 <select id="<?php echo esc_attr( $dropdown_id ); ?>" name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'> 290 295 <?php 291 296 /** 292 297 * Filter the arguments for the Archives widget drop-down. … … 563 568 } 564 569 565 570 public function widget( $args, $instance ) { 571 static $first_dropdown = true; 566 572 567 573 /** This filter is documented in wp-includes/default-widgets.php */ 568 574 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title'], $instance, $this->id_base ); … … 571 577 $h = ! empty( $instance['hierarchical'] ) ? '1' : '0'; 572 578 $d = ! empty( $instance['dropdown'] ) ? '1' : '0'; 573 579 580 if ( $d ) { 581 $dropdown_id = ( $first_dropdown ) ? 'cat' : "{$this->id_base}-dropdown-{$this->number}"; 582 $first_dropdown = false; 583 } 584 574 585 echo $args['before_widget']; 575 586 if ( $title ) { 587 if ( $d ) { 588 $title = sprintf( '<label for="%s">%s</label>', esc_attr( $dropdown_id ), $title ); 589 } 576 590 echo $args['before_title'] . $title . $args['after_title']; 577 591 } 578 592 579 $cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h); 593 $cat_args = array( 594 'orderby' => 'name', 595 'show_count' => $c, 596 'hierarchical' => $h 597 ); 580 598 581 599 if ( $d ) { 582 $cat_args['show_option_none'] = __('Select Category'); 600 $cat_args['show_option_none'] = __( 'Select Category' ); 601 $cat_args['id'] = $dropdown_id; 583 602 584 603 /** 585 604 * Filter the arguments for the Categories widget drop-down. … … 595 614 596 615 <script type='text/javascript'> 597 616 /* <![CDATA[ */ 598 var dropdown = document.getElementById("cat"); 617 (function() { 618 var dropdown = document.getElementById("<?php echo esc_js( $dropdown_id ); ?>"); 599 619 function onCatChange() { 600 620 if ( dropdown.options[dropdown.selectedIndex].value > 0 ) { 601 621 location.href = "<?php echo home_url(); ?>/?cat="+dropdown.options[dropdown.selectedIndex].value; … … 602 622 } 603 623 } 604 624 dropdown.onchange = onCatChange; 625 })(); 605 626 /* ]]> */ 606 627 </script> 607 628