WordPress.org

Making WordPress.org

Changeset 6693


Ignore:
Timestamp:
02/18/2018 08:22:43 PM (3 years ago)
Author:
ocean90
Message:

Translate: Wrap project sort filter with a form.

Also add a hidden field to reset the page parameter.

Fixes #2829.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/templates/locale-projects.php

    r6341 r6693  
    8585</div>
    8686<div class="sort-bar">
    87     <select id="sort-filter" disabled="disabled">
    88         <?php
    89             $sorts = array();
    90             if ( is_user_logged_in() && in_array( $project->slug, array( 'waiting', 'wp-themes', 'wp-plugins' ) ) ) {
    91                 $sorts['special'] = 'Untranslated Favorites, Remaining Strings (Most first)';
    92                 $sorts['favorites'] = 'My Favorites';
    93             }
    94             $sorts['strings-remaining'] = 'Remaining Strings (Most first)';
    95             $sorts['strings-remaining-asc'] = 'Remaining Strings (Least first)';
    96             $sorts['strings-waiting-and-fuzzy'] = 'Waiting + Fuzzy (Most first)';
    97             $sorts['strings-waiting-and-fuzzy-asc'] = 'Waiting + Fuzzy (Least first)';
    98             $sorts['percent-completed'] = 'Percent Completed (Most first)';
    99             $sorts['percent-completed-asc'] = 'Percent Completed (Least first)';
    100 
    101             foreach ( $sorts as $value => $text ) {
    102                 printf( '<option value="%s" %s>%s</option>', esc_attr( $value ), ( $value == $filter ? 'selected="selected"' : '' ), esc_attr( $text ) );
    103             }
    104         ?>
    105     </select>
     87    <form id="sort-filter" action="" method="GET">
     88        <input type="hidden" name="page" value="1">
     89        <select id="filter" name="filter">
     90            <?php
     91                $sorts = array();
     92                if ( is_user_logged_in() && in_array( $project->slug, array( 'waiting', 'wp-themes', 'wp-plugins' ) ) ) {
     93                    $sorts['special'] = 'Untranslated Favorites, Remaining Strings (Most first)';
     94                    $sorts['favorites'] = 'My Favorites';
     95                }
     96                $sorts['strings-remaining'] = 'Remaining Strings (Most first)';
     97                $sorts['strings-remaining-asc'] = 'Remaining Strings (Least first)';
     98                $sorts['strings-waiting-and-fuzzy'] = 'Waiting + Fuzzy (Most first)';
     99                $sorts['strings-waiting-and-fuzzy-asc'] = 'Waiting + Fuzzy (Least first)';
     100                $sorts['percent-completed'] = 'Percent Completed (Most first)';
     101                $sorts['percent-completed-asc'] = 'Percent Completed (Least first)';
     102
     103                foreach ( $sorts as $value => $text ) {
     104                    printf( '<option value="%s" %s>%s</option>', esc_attr( $value ), ( $value == $filter ? 'selected="selected"' : '' ), esc_attr( $text ) );
     105                }
     106            ?>
     107        </select>
     108    </form>
    106109</div>
    107110<script>
    108     jQuery('#sort-filter').change( function() {
    109         var current_url = document.location.href;
    110         var filter = this.options[ this.options.selectedIndex ].value;
    111 
    112         if ( current_url.indexOf( 'filter=' ) > -1 ) {
    113             document.location.replace(
    114                 current_url.replace(/([?&]filter=)([^&$]*)/, '$1' + filter )
    115             );
    116         } else {
    117             document.location.replace(
    118                 current_url +
    119                 ( -1 == current_url.indexOf('?') ? '?filter=' : '&filter=' ) +
    120                 filter
    121             );
    122         }
    123     } ).prop('disabled', '');
     111    var filterForm  = document.getElementById( 'sort-filter' );
     112    var filterSelect = document.getElementById( 'filter' );
     113    filterSelect.addEventListener( 'change', function() {
     114        filterForm.submit()
     115    } );
    124116</script>
    125117
Note: See TracChangeset for help on using the changeset viewer.