summaryrefslogtreecommitdiff
path: root/js/details.js
blob: 6ee1472cabe5411ef5e50e513414d34620406500 (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
Event.observe(window,'load',detailsInit);

function detailsInit() {

  // set current task
  var title = document.getElementsByTagName('title')[0];
  title = title.textContent || title.text; //IE uses .text
  var arr = /(#)(\d+)/.exec(title);
  if( arr != null){
    sessionStorage.setItem('current_task', arr[2]);
    
    // make sure the page is not in edit mode, 'details' is id of description textarea
    if (!document.getElementById('details')) {
      Event.observe(document,'keydown',keyboardNavigation);
    }
  }
}
function keyboardNavigation(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) ||
       e.ctrlKey || e.shiftKey) {
    return;
  }
  switch (e.keyCode) {
    case 85:  // "u" get back to task list
        window.location = $('indexlink').href;
        Event.stop(e);
        break;
    case 80:  // "p" move to previous task
        if ($('prev')) {
          window.location = $('prev').href;
          Event.stop(e);
        }
        break;
    case 78: // "n" move to next task
        if ($('next')) {
          window.location = $('next').href;
          Event.stop(e);
        }
        break;
  }
}