forked from 0x2620/oxjs
various documentation-related changes
This commit is contained in:
parent
b6fdf0c28b
commit
a6ed310087
13 changed files with 880 additions and 301 deletions
|
|
@ -5,46 +5,7 @@
|
|||
|
||||
(function() {
|
||||
|
||||
var buffer = '',
|
||||
// the dot notation ('0.numpad') makes the keyboard event ('key_0.numpad')
|
||||
// namespaced, so that binding to 'key_0' will catch 'key_0.numpad' too
|
||||
keyNames = {
|
||||
0: 'section', 8: 'backspace', 9: 'tab', 12: 'clear', 13: 'enter',
|
||||
16: 'shift', 17: 'control', 18: 'alt', 20: 'capslock', 27: 'escape',
|
||||
32: 'space', 33: 'pageup', 34: 'pagedown', 35: 'end', 36: 'home',
|
||||
37: 'left', 38: 'up', 39: 'right', 40: 'down',
|
||||
45: 'insert', 46: 'delete', 47: 'help',
|
||||
48: '0', 49: '1', 50: '2', 51: '3', 52: '4',
|
||||
53: '5', 54: '6', 55: '7', 56: '8', 57: '9',
|
||||
65: 'a', 66: 'b', 67: 'c', 68: 'd', 69: 'e',
|
||||
70: 'f', 71: 'g', 72: 'h', 73: 'i', 74: 'j',
|
||||
75: 'k', 76: 'l', 77: 'm', 78: 'n', 79: 'o',
|
||||
80: 'p', 81: 'q', 82: 'r', 83: 's', 84: 't',
|
||||
85: 'u', 86: 'v', 87: 'w', 88: 'x', 89: 'y', 90: 'z',
|
||||
// fixme: this is usually 91: window.left, 92: window.right, 93: select
|
||||
91: 'meta.left', 92: 'meta.right', 93: 'meta.right',
|
||||
96: '0.numpad', 97: '1.numpad', 98: '2.numpad', 99: '3.numpad',
|
||||
100: '4.numpad', 101: '5.numpad', 102: '6.numpad', 103: '7.numpad',
|
||||
104: '8.numpad', 105: '9.numpad', 106: 'asterisk.numpad', 107: 'plus.numpad',
|
||||
109: 'minus.numpad', 108: 'enter.numpad', 110: 'dot.numpad', 111: 'slash.numpad',
|
||||
112: 'f1', 113: 'f2', 114: 'f3', 115: 'f4', 116: 'f5',
|
||||
117: 'f6', 118: 'f7', 119: 'f8', 120: 'f9', 121: 'f10',
|
||||
122: 'f11', 123: 'f12', 124: 'f13', 125: 'f14', 126: 'f15', 127: 'f16',
|
||||
144: 'numlock', 145: 'scrolllock',
|
||||
186: 'semicolon', 187: 'equal', 188: 'comma', 189: 'minus',
|
||||
190: 'dot', 191: 'slash', 192: 'backtick', 219: 'openbracket',
|
||||
220: 'backslash', 221: 'closebracket', 222: 'quote', 224: 'meta'
|
||||
// see dojo, for ex.
|
||||
},
|
||||
// meta comes last so that we can differentiate between
|
||||
// alt_control_shift_meta.left and alt_control_shift_meta.right
|
||||
modifierNames = {
|
||||
altKey: 'alt', // Mac: option
|
||||
ctrlKey: 'control',
|
||||
shiftKey: 'shift',
|
||||
metaKey: 'meta', // Mac: command
|
||||
},
|
||||
resetTimeout, triggerTimeout;
|
||||
var buffer = '', resetTimeout, triggerTimeout;
|
||||
|
||||
/*
|
||||
Ox.UI.ready(function() {
|
||||
|
|
@ -59,10 +20,10 @@
|
|||
if ($element.length) {
|
||||
if (
|
||||
(
|
||||
keyNames[event.keyCode] == 'up' &&
|
||||
Ox.KEYS[event.keyCode] == 'up' &&
|
||||
$element[0].selectionStart + $element[0].selectionEnd == 0
|
||||
) || (
|
||||
keyNames[event.keyCode] == 'down' &&
|
||||
Ox.KEYS[event.keyCode] == 'down' &&
|
||||
$element[0].selectionStart == $element.val().length &&
|
||||
$element[0].selectionEnd == $element.val().length
|
||||
)
|
||||
|
|
@ -82,27 +43,41 @@
|
|||
});
|
||||
|
||||
function keydown(event) {
|
||||
|
||||
var focused = Ox.Focus.focused(),
|
||||
key,
|
||||
keyName = keyNames[event.keyCode] || '',
|
||||
keyName = Ox.KEYS[event.keyCode] || '',
|
||||
keyNames = keyName ? [keyName] : [],
|
||||
keyBasename = keyName.split('.')[0],
|
||||
keys = keyName ? [keyName] : [];
|
||||
Ox.forEach(modifierNames, function(v, k) {
|
||||
ret = true;
|
||||
|
||||
Ox.forEach(Ox.MODIFIER_KEYS, function(v, k) {
|
||||
// avoid pushing modifier twice
|
||||
if (event[k] && keyBasename != v) {
|
||||
keys.splice(-1, 0, v);
|
||||
keyNames.splice(-1, 0, v);
|
||||
}
|
||||
});
|
||||
key = keys.join('_');
|
||||
if (/^(shift_)?[a-z]$|^\d(\.numpad)?$|space/.test(key)) {
|
||||
key = keyNames.join('_');
|
||||
if (focused !== null) {
|
||||
Ox.UI.elements[focused].triggerEvent('key_' + key);
|
||||
// prevent Chrome from going back in history, or scrolling
|
||||
if (
|
||||
[
|
||||
'backspace', 'down', 'left', 'right', 'space', 'up'
|
||||
].indexOf(keyBasename) > -1 &&
|
||||
!Ox.UI.elements[focused].hasClass('OxInput')
|
||||
) {
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (/^[\w\d](\.numpad)?$|space/.test(key)) {
|
||||
// don't register leading spaces or trailing double spaces
|
||||
if (!(keyName == 'space' && (buffer == '' || / $/.test(buffer)))) {
|
||||
buffer += keyName == 'space' ? ' ' : keyBasename;
|
||||
Ox.print('buffer', buffer)
|
||||
// clear the trigger timeout only if the key went into the buffer
|
||||
clearTimeout(triggerTimeout);
|
||||
triggerTimeout = setTimeout(function() {
|
||||
Ox.print('buffer', buffer)
|
||||
focused !== null && Ox.UI.elements[focused].triggerEvent('keys', {
|
||||
keys: buffer
|
||||
});
|
||||
|
|
@ -114,16 +89,10 @@
|
|||
resetTimeout = setTimeout(function() {
|
||||
buffer = '';
|
||||
}, 1000);
|
||||
if (focused !== null) {
|
||||
Ox.UI.elements[focused].triggerEvent('key_' + key);
|
||||
// prevent Chrome from going back in history, or scrolling
|
||||
if (
|
||||
['backspace', 'down', 'left', 'right', 'space', 'up'].indexOf(key) > -1 &&
|
||||
!Ox.UI.elements[focused].hasClass('OxInput')
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Ox.print(ret)
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue