started work on keyboard doc generator...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2013-03-05 22:19:48 +04:00
parent ac559c9e32
commit 0607c2dd74
3 changed files with 173 additions and 63 deletions

View File

@ -107,14 +107,80 @@ function removeOverlay(){
}, 300)
}
// XXX make this more sensible...
function showInfo(){
showInOverlay($(
'<div>'+
'<h1>Portable Mag</h1>'+
'<h1>PortableMag</h1>'+
'<p>licence and copyright info goes here...</p>'+
'</div>'))
}
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(){
<div class="top-toolbar">
<div class="left-set">
<div class="button title"><a href="#home" class="magazine-title-text">Magazine Title</a></div>
<!--div class="button title magazine-title-text" contenteditable="false">Magazine Title</div-->
</div>
<div class="right-set">
<div class="button prev-bookmark">

View File

@ -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:
* {
* <section-title>: {
* doc: ...
*
* <handler-doc>: <keys-spec>
* ...
* }
* }
*
* <keys-spec> - 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 : */

View File

@ -127,7 +127,7 @@
.editor-status {
display: block;
position: fixed;
top: 30px;
top: 35px;
left: -200px;
z-index: 99999;
padding: 5px;