| | 43 | var hits = 0, |
| | 44 | row_height = $('.language-chooser').find('label').height(); |
| | 45 | max = $fieldset.find('input').length - parseInt( $fieldset.height() / row_height, 10 ); |
| | 46 | $(document).keydown(function(e) { |
| | 47 | if ( e.which !== 38 && e.which !== 40 ) { |
| | 48 | return; |
| | 49 | } |
| | 50 | |
| | 51 | // Hits should be positive value, shouldn't be more than inputs count |
| | 52 | if ( hits >= 0 && hits <= max ) { |
| | 53 | if ( e.which == 38 ) { // Up |
| | 54 | hits--; |
| | 55 | } |
| | 56 | else { // Down |
| | 57 | hits++; |
| | 58 | } |
| | 59 | |
| | 60 | // Fix limit values |
| | 61 | hits = hits < 1 ? 0 : hits; |
| | 62 | hits = hits > max ? max : hits; |
| | 63 | |
| | 64 | $fieldset.scrollTop( row_height * hits ); |
| | 65 | } |
| | 66 | }); |
| | 67 | |