Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/js/index.js
blob: ae0586bc1b010fe6f1c996bc0a80a9880321bcd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
Event.observe(window,'load',tasklistInit);
Event.observe(window,'load',searchInit);

function tasklistInit() {
  Caret.init();
}
function searchInit() {
  if (navigator.appVersion.match(/\bMSIE 6\.0\b/) && $('searchthisproject') && $('reset')) {
    Event.observe('searchthisproject','click',function() {$('reset').remove();});
  }
}
var Caret = {
  init: function () {
    var task = sessionStorage.getItem('current_task') || 'top';
    if (task == 'bottom' || task == 'top') {
      var tab = $('tasklist_table');
      var rows = tab ? tab.getElementsByTagName('tbody')[0].getElementsByTagName('tr') : [];
      Caret.currentRow = (task == 'top' || rows.length == 0) ? rows[0] : rows[rows.length-1];
    }
    else {
      Caret.currentRow = $('task'+task);
    }
    if (Caret.currentRow) {
      Element.addClassName(Caret.currentRow,'current_row');
      Event.observe(document,'keydown',Caret.keypress);
    }
  },
  keypress: function (e) {
    var src = Event.element(e);
    if (/input|select|textarea/.test(src.nodeName.toLowerCase())) {
      // don't do anything if key is pressed in input, select or textarea
      return;
    }
    if ((useAltForKeyboardNavigation && !e.altKey) ||
        (!useAltForKeyboardNavigation && e.altKey) ||
         e.ctrlKey || e.shiftKey) {
      return;
    }
    switch (e.keyCode) {
      case 74:       // user pressed "j" move down
          Element.removeClassName(Caret.currentRow,'current_row');
          Caret.nextRow();
          Element.addClassName(Caret.currentRow,'current_row');
          Event.stop(e);
          break;
      case 75:      // user pressed "k" move up
          Element.removeClassName(Caret.currentRow,'current_row');
          Caret.previousRow();
          Element.addClassName(Caret.currentRow,'current_row');
          Event.stop(e);
          break;
      case 79:     // user pressed "o" open task
          window.location = Caret.currentRow.getElementsByTagName('a')[0].href; // FIXME ambiguous in future: if first a is not a link to the task, e.g. a column with link to task opener 
          Event.stop(e);
          break;
    }
  },
  nextRow: function () {
    var row = Caret.currentRow;
    while ((row = row.nextSibling)) {
      if ('tr' == row.nodeName.toLowerCase()) {
        Caret.currentRow = row;
        return;
      }
    }
    // we've reached the bottom of the list
    if ($('next')) {
      //Cookie.setVar('current_task','top'); // doesn't work well on multitab multiproject usage
      sessionStorage.setItem('current_task','top');
      window.location = $('next').href;
      return;
    }
  },
  previousRow: function () {
    var row = Caret.currentRow;
    while ((row = row.previousSibling)) {
      if ('tr' == row.nodeName.toLowerCase()) {
        Caret.currentRow = row;
        return;
      }
    }
    // we've reached the top of the list
    if ($('previous')) {
      //Cookie.setVar('current_task','bottom'); // doesn't work well on multitab multiproject usage
      sessionStorage.setItem('current_task','bottom');
      window.location = $('previous').href;
      return;
    }
    
  }
};