[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

/assets/js/ -> translations-page.js (source)

   1  /* global $gp_translations_options, $gp, window, toggleWithKeyboard */
   2  /* eslint camelcase: "off" */
   3  jQuery( function( $ ) {
   4      var $bulkActions = $( '.bulk-action' ),
   5          $bulkPriority = $( '.bulk-priority' ),
   6          lastClicked = false;
   7  
   8      $gp.showhide( '#upper-filters-toolbar a.sort', '#upper-filters-toolbar .filters-expanded.sort', {
   9          show_text: $gp_translations_options.sort + ' ↓',
  10          hide_text: $gp_translations_options.sort + ' ↑',
  11          focus: '#sort\\[by\\]\\[original_date_added\\]',
  12      } );
  13      $gp.showhide( '#upper-filters-toolbar a.filter', '#upper-filters-toolbar .filters-expanded.filters', {
  14          show_text: $gp_translations_options.filter + ' ↓',
  15          hide_text: $gp_translations_options.filter + ' ↑',
  16          focus: '#filters\\[term\\]',
  17      } );
  18  
  19      $bulkActions.on( 'change', function() {
  20          var $optionSelected = $( 'option:selected', this );
  21          $bulkActions.val( $optionSelected.val() );
  22          if ( 'set-priority' === $optionSelected.val() ) {
  23              $bulkPriority.removeClass( 'hidden' );
  24          } else {
  25              $bulkPriority.addClass( 'hidden' );
  26          }
  27      } );
  28  
  29      $( 'form.bulk-actions' ).submit( function() {
  30          var    row_ids = $( 'input:checked', $( 'table#translations th.checkbox' ) ).map( function() {
  31              return $( this ).parents( 'tr.preview' ).attr( 'row' );
  32          } ).get().join( ',' );
  33          $( 'input[name="bulk[row-ids]"]', $( this ) ).val( row_ids );
  34      } );
  35  
  36      ( function() {
  37          var $statusFields = $( '#filter-status-fields' );
  38          var $checkboxes = $statusFields.find( 'input:checkbox' );
  39          var $selectedStatus = $( '#filter-status-selected' );
  40  
  41          $( '#filter-status-select-all' ).on( 'click', function() {
  42              $checkboxes.prop( 'checked', true ).trigger( 'change' );
  43          } );
  44  
  45          $checkboxes.on( 'change', function() {
  46              var checkedStatus = $checkboxes.filter( ':checked' ).map( function() {
  47                  return $( this ).val();
  48              } ).get();
  49  
  50              if ( ! checkedStatus.length ) {
  51                  // Default value used by GP_Translation::for_translation().
  52                  $selectedStatus.val( 'current_or_waiting_or_fuzzy_or_untranslated' );
  53              } else {
  54                  $selectedStatus.val( checkedStatus.join( '_or_' ) );
  55              }
  56          } );
  57      }() );
  58  
  59      $( 'a#export' ).click( function() {
  60          var format = $( '#export-format' ).val();
  61          var what_to_export = $( '#what-to-export' ).val();
  62          var url = '';
  63          if ( what_to_export === 'filtered' ) {
  64              // eslint-disable-next-line vars-on-top
  65              var separator = ( $( this ).attr( 'filters' ).indexOf( '?' ) === -1 ) ? '?' : '&';
  66              url = $( this ).attr( 'filters' ) + separator + 'format=' + format;
  67          } else {
  68              url = $( this ).attr( 'href' ) + '?format=' + format;
  69          }
  70          window.location = url;
  71          return false;
  72      } );
  73  
  74      // Check all checkboxes from WP common.js, synced with [25141]
  75      $( 'tbody' ).children().children( '.checkbox' ).find( ':checkbox' ).click( function( e ) {
  76          var checks, first, last, checked, sliced;
  77  
  78          if ( 'undefined' === e.shiftKey ) {
  79              return true;
  80          }
  81          if ( e.shiftKey ) {
  82              if ( ! lastClicked ) {
  83                  return true;
  84              }
  85              checks = $( lastClicked ).closest( 'table' ).find( ':checkbox' );
  86              first = checks.index( lastClicked );
  87              last = checks.index( this );
  88              checked = $( this ).prop( 'checked' );
  89              if ( 0 < first && 0 < last && first !== last ) {
  90                  sliced = ( last > first ) ? checks.slice( first, last ) : checks.slice( last, first );
  91                  sliced.prop( 'checked', function() {
  92                      if ( $( this ).closest( 'tr' ).is( ':visible' ) ) {
  93                          return checked;
  94                      }
  95  
  96                      return false;
  97                  } );
  98              }
  99          }
 100          lastClicked = this;
 101          return true;
 102      } );
 103  
 104      $( 'thead, tfoot' ).find( '.checkbox :checkbox' ).click( function( e ) {
 105          var c = $( this ).prop( 'checked' ),
 106              kbtoggle = 'undefined' === typeof toggleWithKeyboard ? false : toggleWithKeyboard,
 107              toggle = e.shiftKey || kbtoggle;
 108  
 109          $( this ).closest( 'table' ).children( 'tbody' ).filter( ':visible' )
 110              .children().children( '.checkbox' ).find( ':checkbox' )
 111              .prop( 'checked', function() {
 112                  if ( $( this ).closest( 'tr' ).is( ':hidden' ) ) {
 113                      return false;
 114                  }
 115                  if ( toggle ) {
 116                      return $( this ).prop( 'checked' );
 117                  } else if ( c ) {
 118                      return true;
 119                  }
 120                  return false;
 121              } );
 122  
 123          $( this ).closest( 'table' ).children( 'thead,  tfoot' ).filter( ':visible' )
 124              .children().children( '.checkbox' ).find( ':checkbox' )
 125              .prop( 'checked', function() {
 126                  if ( toggle ) {
 127                      return false;
 128                  } else if ( c ) {
 129                      return true;
 130                  }
 131                  return false;
 132              } );
 133      } );
 134  } );


Generated: Thu Nov 21 01:01:07 2024 Cross-referenced by PHPXref 0.7.1