Ticket #98: keyboard-translation-navigation.diff
| File keyboard-translation-navigation.diff, 4.6 KB (added by Nightgunner5, 22 months ago) |
|---|
-
editor.js
4 4 $gp.init(); 5 5 $gp.editor.table = table; 6 6 $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 } 7 12 }, 8 13 original_id_from_row_id: function(row_id) { 9 14 return row_id.split('-')[0]; … … 26 31 $('tr:first', $gp.editor.table).hide(); 27 32 $('textarea:first', editor).focus(); 28 33 }, 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 }, 29 50 next: function() { 30 51 if (!$gp.editor.current) return; 31 //TODO: go to next page if needed32 52 var next = $gp.editor.current.nextAll('tr.editor'); 33 if (next.length) 53 if (next.length) { 34 54 $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 } 37 65 }, 38 66 hide: function(editor) { 39 67 editor = editor? editor : $gp.editor.current; … … 54 82 $('button.ok', 'tr.editor').live('click', $gp.editor.hooks.ok); 55 83 $('tr.preview', $gp.editor.table).live('dblclick', $gp.editor.hooks.show); 56 84 $('select.priority', $gp.editor.table).live('change', $gp.editor.hooks.set_priority); 85 $('textarea', 'tr.editor').live('keydown', $gp.editor.hooks.keydown); 57 86 }, 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 }, 58 104 replace_current: function(html) { 59 105 if (!$gp.editor.current) return; 60 106 $gp.editor.current.after(html); … … 75 121 }).get().join('&'); 76 122 $.ajax({type: "POST", url: $gp_editor_options.url, data: data, dataType: 'json', 77 123 success: function(data){ 78 button. attr('disabled', '');124 button.removeAttr('disabled'); 79 125 $gp.notices.success('Saved!'); 80 126 for(original_id in data) { 81 127 $gp.editor.replace_current(data[original_id]); … … 87 133 } 88 134 }, 89 135 error: function(xhr, msg, error) { 90 button. attr('disabled', '');136 button.removeAttr('disabled'); 91 137 msg = xhr.responseText? 'Error: '+ xhr.responseText : 'Error saving the translation!'; 92 138 $gp.notices.error(msg); 93 139 } … … 101 147 data = {priority: $('option:selected', select).attr('value')}; 102 148 $.ajax({type: "POST", url: $gp_editor_options.set_priority_url.replace('%original-id%', editor.original_id), data: data, 103 149 success: function(data){ 104 select. attr('disabled', '');150 select.removeAttr('disabled'); 105 151 $gp.notices.success('Priority set!'); 106 152 var new_priority_class = 'priority-'+$('option:selected', select).text(); 107 153 $gp.editor.current.addClass(new_priority_class); … … 118 164 if (!$gp.editor.current || !$gp.editor.current.translation_id) return; 119 165 var editor = $gp.editor.current; 120 166 button.attr('disabled', 'disabled'); 121 $gp.notices.notice('Setting status to “'+status+'̶ 2;…');167 $gp.notices.notice('Setting status to “'+status+'”…'); 122 168 var data = {translation_id: editor.translation_id, status: status}; 123 169 $.ajax({type: "POST", url: $gp_editor_options.set_status_url, data: data, 124 170 success: function(data){ 125 button. attr('disabled', '');171 button.removeAttr('disabled'); 126 172 $gp.notices.success('Status set!'); 127 173 $gp.editor.replace_current(data); 128 174 }, … … 130 176 msg = xhr.responseText? 'Error: '+ xhr.responseText : 'Error setting the status!'; 131 177 $gp.notices.error(msg); 132 178 } 133 }); 179 }); 134 180 }, 135 181 discard_warning: function(link) { 136 182 if (!$gp.editor.current) return; … … 196 242 $gp.editor.save($(this)); 197 243 return false; 198 244 }, 245 keydown: function(e) { 246 return $gp.editor.keydown(e); 247 }, 199 248 copy: function() { 200 249 $gp.editor.copy($(this)); 201 250 return false;
