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,6 +107,7 @@ function removeOverlay(){
}, 300) }, 300)
} }
// XXX make this more sensible...
function showInfo(){ function showInfo(){
showInOverlay($( showInOverlay($(
'<div>'+ '<div>'+
@ -115,17 +116,11 @@ function showInfo(){
'</div>')) '</div>'))
} }
var keyboard_config = {
$(document).ready(function(){
// general window behavior...
$(window)
.resize(updateView)
.bind('hashchange', hashChangeHandler)
// keyboard...
$(document)
.keydown(makeKeyboardHandler({
'.overlay': { '.overlay': {
title: 'Overlay mode.',
doc: '',
Esc: function(){ Esc: function(){
removeOverlay() removeOverlay()
return false return false
@ -134,6 +129,9 @@ $(document).ready(function(){
// ignore all keys except Esc here... // ignore all keys except Esc here...
'.inline-editor-mode': { '.inline-editor-mode': {
title: 'Inline editor mode.',
doc: '',
//ignore: '*' //ignore: '*'
Esc: function(){ Esc: function(){
$(':focus').blur() $(':focus').blur()
@ -142,7 +140,7 @@ $(document).ready(function(){
}, },
'.chrome:not(.inline-editor-mode)': { '.chrome:not(.inline-editor-mode)': {
title: 'Global', title: 'Global bindings.',
doc: '', doc: '',
Esc: function(){ Esc: function(){
@ -181,7 +179,18 @@ $(document).ready(function(){
// XXX this should not be in the production viewer... // XXX this should not be in the production viewer...
E: function(){ toggleEditor() }, E: function(){ toggleEditor() },
}, },
}, }
$(document).ready(function(){
// general window behavior...
$(window)
.resize(updateView)
.bind('hashchange', hashChangeHandler)
// keyboard...
$(document)
.keydown(makeKeyboardHandler(keyboard_config,
function(k){console.log(k)})) function(k){console.log(k)}))
window.MagazineScroller = makeScrollHandler($('.viewer'), { window.MagazineScroller = makeScrollHandler($('.viewer'), {
@ -284,6 +293,7 @@ $(document).ready(function(){
<div class="top-toolbar"> <div class="top-toolbar">
<div class="left-set"> <div class="left-set">
<div class="button title"><a href="#home" class="magazine-title-text">Magazine Title</a></div> <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>
<div class="right-set"> <div class="right-set">
<div class="button prev-bookmark"> <div class="button prev-bookmark">

View File

@ -29,6 +29,11 @@ var SPECIAL_KEYS = {
115: 'F4', 119: 'F8', 123: 'F12', 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... // XXX some keys look really wrong...
function toKeyName(code){ function toKeyName(code){
@ -46,7 +51,10 @@ function toKeyName(code){
return null return null
} }
function chr(c){ function toKeyCode(c){
if(c in KEY_CODES){
return KEY_CODES[c]
}
return c.charCodeAt(0) return c.charCodeAt(0)
} }
@ -124,8 +132,15 @@ function makeKeyboardHandler(keybindings, unhandled){
} }
// alias... // alias...
while (typeof(handler) == typeof(123)) { 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] handler = bindings[handler]
} else if(typeof(h) == typeof(1)) {
handler = bindings[toKeyName(handler)]
} else {
handler = bindings[toKeyCode(handler)]
}
} }
// no handler... // no handler...
if(handler == null){ 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 : */ * vim:set ts=4 sw=4 : */

View File

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