Ticket #98: keyboard-translation-navigation.diff

File keyboard-translation-navigation.diff, 4.6 KB (added by Nightgunner5, 22 months ago)
  • editor.js

     
    44                $gp.init(); 
    55                $gp.editor.table = table; 
    66                $gp.editor.install_hooks(); 
     7 
     8                if (window.sessionStorage && sessionStorage.gp_select_row) { 
     9                        $gp.editor.show($('a.edit' + sessionStorage.gp_select_row, table)); 
     10                        sessionStorage.gp_select_row = ''; 
     11                } 
    712        }, 
    813        original_id_from_row_id: function(row_id) { 
    914                return row_id.split('-')[0]; 
     
    2631                $('tr:first', $gp.editor.table).hide(); 
    2732                $('textarea:first', editor).focus(); 
    2833        }, 
     34        prev: function() { 
     35                if (!$gp.editor.current) return; 
     36                var prev = $gp.editor.current.prevAll('tr.editor'); 
     37                if (prev.length) { 
     38                        $gp.editor.show(prev.eq(0)); 
     39                } else { 
     40                        if ($('.paging .previous').hasClass('disabled')) { 
     41                                $gp.editor.hide(); 
     42                        } else { 
     43                                if (window.sessionStorage) 
     44                                        sessionStorage.gp_select_row = ':last'; 
     45 
     46                                location.href = $('.paging .previous').attr('href'); 
     47                        } 
     48                } 
     49        }, 
    2950        next: function() { 
    3051                if (!$gp.editor.current) return; 
    31                 //TODO: go to next page if needed 
    3252                var next = $gp.editor.current.nextAll('tr.editor'); 
    33                 if (next.length) 
     53                if (next.length) { 
    3454                        $gp.editor.show(next.eq(0)); 
    35                 else 
    36                         $gp.editor.hide(); 
     55                } else { 
     56                        if ($('.paging .next').hasClass('disabled')) { 
     57                                $gp.editor.hide(); 
     58                        } else { 
     59                                if (window.sessionStorage) 
     60                                        sessionStorage.gp_select_row = ':first'; 
     61 
     62                                location.href = $('.paging .next').attr('href'); 
     63                        } 
     64                } 
    3765        }, 
    3866        hide: function(editor) { 
    3967                editor = editor? editor : $gp.editor.current; 
     
    5482                $('button.ok', 'tr.editor').live('click', $gp.editor.hooks.ok); 
    5583                $('tr.preview', $gp.editor.table).live('dblclick', $gp.editor.hooks.show); 
    5684                $('select.priority', $gp.editor.table).live('change', $gp.editor.hooks.set_priority); 
     85                $('textarea', 'tr.editor').live('keydown', $gp.editor.hooks.keydown); 
    5786        }, 
     87        keydown: function(e) { 
     88                if (e.keyCode == 27) 
     89                        $gp.editor.hide(); 
     90                else if (e.keyCode == 33) 
     91                        $gp.editor.prev(); 
     92                else if (e.keyCode == 34) 
     93                        $gp.editor.next(); 
     94                else if (e.keyCode == 13 && e.shiftKey) { 
     95                        var target = $(e.target); 
     96                        if (target.nextAll('textarea').length) 
     97                                target.nextAll('textarea').eq(0).focus() 
     98                        else 
     99                                $gp.editor.save(target.parents('tr.editor').find('button.ok')); 
     100                } else 
     101                        return true; 
     102                return false; 
     103        }, 
    58104        replace_current: function(html) { 
    59105                if (!$gp.editor.current) return; 
    60106                $gp.editor.current.after(html); 
     
    75121                }).get().join('&'); 
    76122                $.ajax({type: "POST", url: $gp_editor_options.url, data: data, dataType: 'json', 
    77123                        success: function(data){ 
    78                                 button.attr('disabled', ''); 
     124                                button.removeAttr('disabled'); 
    79125                                $gp.notices.success('Saved!'); 
    80126                                for(original_id in data) { 
    81127                                        $gp.editor.replace_current(data[original_id]); 
     
    87133                                } 
    88134                        }, 
    89135                        error: function(xhr, msg, error) { 
    90                                 button.attr('disabled', ''); 
     136                                button.removeAttr('disabled'); 
    91137                                msg = xhr.responseText? 'Error: '+ xhr.responseText : 'Error saving the translation!'; 
    92138                                $gp.notices.error(msg); 
    93139                        } 
     
    101147                data = {priority: $('option:selected', select).attr('value')}; 
    102148                $.ajax({type: "POST", url: $gp_editor_options.set_priority_url.replace('%original-id%', editor.original_id), data: data, 
    103149                        success: function(data){ 
    104                                 select.attr('disabled', ''); 
     150                                select.removeAttr('disabled'); 
    105151                                $gp.notices.success('Priority set!'); 
    106152                                var new_priority_class = 'priority-'+$('option:selected', select).text(); 
    107153                                $gp.editor.current.addClass(new_priority_class); 
     
    118164                if (!$gp.editor.current || !$gp.editor.current.translation_id) return; 
    119165                var editor = $gp.editor.current; 
    120166                button.attr('disabled', 'disabled');             
    121                 $gp.notices.notice('Setting status to “'+status+'„…'); 
     167                $gp.notices.notice('Setting status to “'+status+'”…'); 
    122168                var data = {translation_id: editor.translation_id, status: status}; 
    123169                $.ajax({type: "POST", url: $gp_editor_options.set_status_url, data: data, 
    124170                        success: function(data){ 
    125                                 button.attr('disabled', ''); 
     171                                button.removeAttr('disabled'); 
    126172                                $gp.notices.success('Status set!'); 
    127173                                $gp.editor.replace_current(data); 
    128174                        }, 
     
    130176                                msg = xhr.responseText? 'Error: '+ xhr.responseText : 'Error setting the status!'; 
    131177                                $gp.notices.error(msg); 
    132178                        } 
    133                 });              
     179                }); 
    134180        }, 
    135181        discard_warning: function(link) { 
    136182                if (!$gp.editor.current) return; 
     
    196242                        $gp.editor.save($(this)); 
    197243                        return false; 
    198244                }, 
     245                keydown: function(e) { 
     246                        return $gp.editor.keydown(e); 
     247                }, 
    199248                copy: function() { 
    200249                        $gp.editor.copy($(this)); 
    201250                        return false;