SebastianRose / org-info-js forked from RickMoynihan/org-info-js

Sebastian Rose's org-info-js branched from the Worg project with project history. The intention is to extend support of org-info-js and Emacs org-mode to support the creation of XHTML/Javascript slide shows. The idea is that this'll be S5 for Emacs. Current version just adds an info like view mode and the Org-mode way of folding to the exported XHTML Org-mode files. Searching (with highlighting) and occur is supported too, as well as automatic link creation (Org-mode links and html links, links may point to a certain section or trigger the view mode, occur mode).

This URL has Read+Write access

org-info-js / org-keys.js
100644 125 lines (100 sloc) 4.078 kb
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//
// org-keys.js
//
// Author and Copyright (c) 2009 Sebastian Rose, Hannover, Germany, sebastian_rose gmx de
//
// Contact:
//
// Phone: +49 (0) 173 - 83 93 417
// Email: sebastian_rose gmx de
//
// Released under the GNU General Public License version 3
// see: http://www.gnu.org/licenses/
//
 
 
var OrgKeyReader = {
  EMPTY_START: /^(\s*)(.*)/, // Trim (s. getKey())
  EMPTY_END: /\s$/, // Trim (s. getKey())
  CONSOLE: null,
  CONSOLE_INPUT: null,
  CONSOLE_LABEL: null,
  CONSOLE_OFFSET: "50px",
  REGISTER: {},
 
  init: function()
  {
    this.CONSOLE = document.createElement("div");
    this.CONSOLE.innerHTML = '<form action="" style="margin:0px;padding:0px;" onsubmit="org_html_manager.evalReadCommand(); return false;">'
      +'<table id="org-info-js_console" style="width:100%;margin:0px 0px 0px 0px;border-style:none;" cellpadding="0" cellspacing="0" summary="minibuffer">'
      +'<tbody><tr><td id="org-info-js_console-icon" style="padding:0px 0px 0px 0px;border-style:none;">&#160;</td><td style="width:100%;vertical-align:middle;padding:0px 0px 0px 0px;border-style:none;">'
      +'<table style="width:100%;margin:0px 0px 0px 0px;border-style:none;" cellpadding="0" cellspacing="2">'
      +'<tbody><tr><td id="org-info-js_console-label" style="white-space:nowrap;padding:0px 0px 0px 0px;border-style:none;"></td></tr>'
      +'<tr><td style="width:100%;vertical-align:middle;padding:0px 0px 0px 0px;border-style:none;">'
      +'<input type="text" id="org-info-js_console-input" onkeydown="org_html_manager.getKey();"'
      +' onclick="this.select();" maxlength="150" style="width:100%;padding:0px;margin:0px 0px 0px 0px;border-style:none;"'
      +' value=""/></td></tr></tbody></table></td><td style="padding:0px 0px 0px 0px;border-style:none;">&#160;</td></tr></tbody></table>'
      +'</form>';
    this.CONSOLE.style.position = 'relative';
    this.CONSOLE.style.marginTop = "-" + this.CONSOLE_OFFSET;
    this.CONSOLE.style.top = "-" + this.CONSOLE_OFFSET;
    this.CONSOLE.style.left = '0px';
    this.CONSOLE.style.width = '100%';
    this.CONSOLE.style.height = '40px';
    this.CONSOLE.style.overflow = 'hidden';
    this.CONSOLE.style.verticalAlign = 'middle';
    this.CONSOLE.style.zIndex = '9';
    this.CONSOLE.style.border = "1px solid #cccccc";
    this.CONSOLE.id = 'org-info-js_console-container';
 
    document.body.insertBefore(this.CONSOLE, document.body.firstChild);
    this.MESSAGING = false;
    this.CONSOLE_LABEL = document.getElementById("org-info-js_console-label");
    this.CONSOLE_INPUT = document.getElementById("org-info-js_console-input");
    document.onkeypress=OrgKeyReaderKeyEvent;
 
    var links = document.getElementsByTagName('a');
    for (var i = 0; i < links.length; ++i) {
      var k = links[i].getAttribute('accesskey');
      var h = links[i].getAttribute('href');
      if(k && h) {
        this.registerHref(k, h);
      }
    }
  },
 
 
  getKey: function ()
  {
    var s = this.CONSOLE_INPUT.value;
 
    // empty console again:
    this.CONSOLE_INPUT.value = "";
 
    // trim the string
    if(s.match(this.EMPTY_START))
      s = s.match(this.EMPTY_START)[2];
    if(s.length && s.match(this.EMPTY_END))
      s = s.substr(0, s.length - 1);
 
    // return, if s is empty:
    if(0 == s.length) { return; }
 
    this.CONSOLE_INPUT.blur();
 
 
    // Now use the input:
    if(this.REGISTER[s] && "function" == typeof this.REGISTER[s]) {
      this.REGISTER[s]();
    }
 
  },
 
 
  register: function(key, func)
  {
    this.REGISTER[key] = func;
  },
 
 
  registerHref: function(key, href)
  {
    this.register(key, function(){document.location.href=href;});
  }
 
};
 
 
function OrgKeyReaderKeyEvent (e)
{
  var c;
  if (!e) e = window.event;
  if (e.which) c = e.which;
  else if (e.keyCode) c = e.keyCode;
 
  if(e.ctrlKey) return;
 
  var s = String.fromCharCode(c);
  if(e.shiftKey)
    OrgKeyReader.CONSOLE_INPUT.value = OrgKeyReader.CONSOLE_INPUT.value + s;
  else
    OrgKeyReader.CONSOLE_INPUT.value = OrgKeyReader.CONSOLE_INPUT.value + s.toLowerCase();
 
  OrgKeyReader.getKey();
}