diff --git a/index.html b/index.html index e484024..098a226 100755 --- a/index.html +++ b/index.html @@ -107,14 +107,80 @@ function removeOverlay(){ }, 300) } +// XXX make this more sensible... function showInfo(){ showInOverlay($( '
'+ - '

Portable Mag

'+ + '

PortableMag

'+ '

licence and copyright info goes here...

'+ '
')) } +var keyboard_config = { + '.overlay': { + title: 'Overlay mode.', + doc: '', + + Esc: function(){ + removeOverlay() + return false + }, + }, + + // ignore all keys except Esc here... + '.inline-editor-mode': { + title: 'Inline editor mode.', + doc: '', + + //ignore: '*' + Esc: function(){ + $(':focus').blur() + return false + }, + }, + + '.chrome:not(.inline-editor-mode)': { + title: 'Global bindings.', + doc: '', + + Esc: function(){ + if(toggleEditor('?') == 'on'){ + toggleEditor('off') + } else { + togglePageView('off') + } + }, + + Home: firstPage, + End: lastPage, + Left: { + default: prevPage, + ctrl: prevArticle, + }, + Right: { + default: nextPage, + ctrl: nextArticle, + }, + Space: { + default: nextPage, + shift: prevPage + }, + Enter: function(){ togglePageView('on') }, + // combined navigation with actions.. + Up: function(){ togglePageView() }, + Down: function(){ togglePageView() }, + + F: function(){ togglePageFitMode() }, + B: { + default: toggleBookmark, + ctrl: function(){ toggleThemes() }, + }, + + // XXX this should not be in the production viewer... + E: function(){ toggleEditor() }, + }, +} + $(document).ready(function(){ // general window behavior... @@ -124,64 +190,7 @@ $(document).ready(function(){ // keyboard... $(document) - .keydown(makeKeyboardHandler({ - '.overlay': { - Esc: function(){ - removeOverlay() - return false - }, - }, - - // ignore all keys except Esc here... - '.inline-editor-mode': { - //ignore: '*' - Esc: function(){ - $(':focus').blur() - return false - }, - }, - - '.chrome:not(.inline-editor-mode)': { - title: 'Global', - doc: '', - - Esc: function(){ - if(toggleEditor('?') == 'on'){ - toggleEditor('off') - } else { - togglePageView('off') - } - }, - - Home: firstPage, - End: lastPage, - Left: { - default: prevPage, - ctrl: prevArticle, - }, - Right: { - default: nextPage, - ctrl: nextArticle, - }, - Space: { - default: nextPage, - shift: prevPage - }, - Enter: function(){ togglePageView('on') }, - // combined navigation with actions.. - Up: function(){ togglePageView() }, - Down: function(){ togglePageView() }, - - F: function(){ togglePageFitMode() }, - B: { - default: toggleBookmark, - ctrl: function(){ toggleThemes() }, - }, - - // XXX this should not be in the production viewer... - E: function(){ toggleEditor() }, - }, - }, + .keydown(makeKeyboardHandler(keyboard_config, function(k){console.log(k)})) window.MagazineScroller = makeScrollHandler($('.viewer'), { @@ -284,6 +293,7 @@ $(document).ready(function(){
+
diff --git a/lib/keyboard.js b/lib/keyboard.js index 90906dc..12b02dd 100755 --- a/lib/keyboard.js +++ b/lib/keyboard.js @@ -29,6 +29,11 @@ var SPECIAL_KEYS = { 115: 'F4', 119: 'F8', 123: 'F12', } +var KEY_CODES = {} +for(var k in SPECIAL_KEYS){ + KEY_CODES[SPECIAL_KEYS[k]] = k +} + // XXX some keys look really wrong... function toKeyName(code){ @@ -46,7 +51,10 @@ function toKeyName(code){ return null } -function chr(c){ +function toKeyCode(c){ + if(c in KEY_CODES){ + return KEY_CODES[c] + } return c.charCodeAt(0) } @@ -124,8 +132,15 @@ function makeKeyboardHandler(keybindings, unhandled){ } // alias... - while (typeof(handler) == typeof(123)) { - handler = bindings[handler] + while (typeof(handler) == typeof(123) || typeof(handler) == typeof('str')) { + if(handler in bindings){ + // XXX need to take care of that we can always be a number or a string... + handler = bindings[handler] + } else if(typeof(h) == typeof(1)) { + handler = bindings[toKeyName(handler)] + } else { + handler = bindings[toKeyCode(handler)] + } } // no handler... if(handler == null){ @@ -172,6 +187,91 @@ function makeKeyboardHandler(keybindings, unhandled){ } +// helper... +function doc(text, func){ + func.doc = text + return func +} + +/* Build structure ready for conversion to HTML help. +* Structure: +* { +* : { +* doc: ... +* +* : +* ... +* } +* } +* +* - list of key names. +* +*/ +function getKeyHandler(key, keybindings){ +} + + + +function buildKeyindingsHelp(keybindings){ + var res = {} + + for(var selector in keybindings){ + var section = keybindings[selector] + var title = section.title == null ? selector : section.title + var res_sec = { + doc: section.doc, + } + res.title = res_sec + + for(var k in section){ + // handler... + var h = section[k] + var doc + var key = typeof(k) == typeof(1) ? toKeyName(k) : k + + // an alias... + while(typeof(h) == typeof(1) || typeof(h) == typeof('s')){ + if(h in section){ + // XXX need to take care of that we can always be a number or a string... + h = section[h] + } else if(typeof(h) == typeof(1)) { + h = section[toKeyName(h)] + } else { + h = section[toKeyCode(h)] + } + } + + // no handler... + if(h == null){ + doc = 'Nothing' + + // a handler with doc (array)... + } else if(typeof(h) == typeof([]) && handler.constructor.name == 'Array'){ + doc = h[1] + + // complex handler (object)... + } else if(typeof(h) == typeof({})){ + // XXX + + + // simple handler (function)... + } else { + doc = h.doc != null ? h.doc : h + + } + + // push the actual data... + if(doc in res_sec){ + res_sec[doc].push(key) + } else { + res_sec[doc] = [key] + } + } + } + return res +} + + /********************************************************************** * vim:set ts=4 sw=4 : */ diff --git a/magazine-editor.css b/magazine-editor.css index 7b5788d..9b55470 100755 --- a/magazine-editor.css +++ b/magazine-editor.css @@ -127,7 +127,7 @@ .editor-status { display: block; position: fixed; - top: 30px; + top: 35px; left: -200px; z-index: 99999; padding: 5px;