Widgets: Pre-select currently viewed archive in the Archives dropdown widget, for consistency with the Categories widget.

Props robobot3000, audrasjb, afercia, Themonic.
Fixes #40662.

git-svn-id: https://develop.svn.wordpress.org/trunk@44897 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2019-03-14 19:30:59 +00:00
parent 45faac902d
commit 9265ff8a2f
2 changed files with 48 additions and 15 deletions

View File

@@ -58,7 +58,7 @@ class WP_Widget_Archives extends WP_Widget {
$dropdown_id = "{$this->id_base}-dropdown-{$this->number}";
?>
<label class="screen-reader-text" for="<?php echo esc_attr( $dropdown_id ); ?>"><?php echo $title; ?></label>
<select id="<?php echo esc_attr( $dropdown_id ); ?>" name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'>
<select id="<?php echo esc_attr( $dropdown_id ); ?>" name="archive-dropdown">
<?php
/**
* Filters the arguments for the Archives widget drop-down.
@@ -104,6 +104,21 @@ class WP_Widget_Archives extends WP_Widget {
<?php wp_get_archives( $dropdown_args ); ?>
</select>
<script type='text/javascript'>
/* <![CDATA[ */
(function() {
var dropdown = document.getElementById( "<?php echo esc_js( $dropdown_id ); ?>" );
function onSelectChange() {
if ( dropdown.options[ dropdown.selectedIndex ].value !== '' ) {
document.location.href = this.options[ this.selectedIndex ].value;
}
}
dropdown.onchange = onSelectChange;
})();
/* ]]> */
</script>
<?php } else { ?>
<ul>
<?php