Refactor, rm keypress binding.

This commit is contained in:
Nicolas Stepien 2011-06-24 23:40:29 +02:00
parent 4ad2d51195
commit cd20db879e
2 changed files with 36 additions and 53 deletions

View File

@ -740,23 +740,12 @@
keybinds.expandImages = (key = $.getValue('key/expandImages', 0)).length >= 0 ? key : 'm'; keybinds.expandImages = (key = $.getValue('key/expandImages', 0)).length >= 0 ? key : 'm';
keybinds.expandAllImages = (key = $.getValue('key/expandAllImages', 0)).length >= 0 ? key : 'M'; keybinds.expandAllImages = (key = $.getValue('key/expandAllImages', 0)).length >= 0 ? key : 'M';
keybinds.update = (key = $.getValue('key/update', 0)).length >= 0 ? key : 'u'; keybinds.update = (key = $.getValue('key/update', 0)).length >= 0 ? key : 'u';
$.bind(d, 'keydown', keybinds.cb.keydown); return $.bind(d, 'keydown', keybinds.cb.keydown);
return $.bind(d, 'keypress', keybinds.cb.keypress);
}, },
cb: { cb: {
keydown: function(e) { keydown: function(e) {
var kc, key, o, qr, range, selEnd, selStart, ta, thread, valEnd, valMid, valStart, value, _ref, _ref2; var key, o, qr, range, selEnd, selStart, ta, thread, valEnd, valMid, valStart, value, _ref, _ref2;
kc = e.keyCode; key = keybinds.cb.keyCode(e);
if ((65 <= kc && kc <= 90)) {
key = String.fromCharCode(kc);
if (!e.shiftKey) {
key = key.toLowerCase();
}
} else if ((48 <= kc && kc <= 57)) {
key = String.fromCharCode(kc);
} else if (kc === 27) {
key = 'Esc';
}
if (e.altKey) { if (e.altKey) {
key = 'alt+' + key; key = 'alt+' + key;
} }
@ -855,8 +844,22 @@
} }
return e.preventDefault(); return e.preventDefault();
}, },
keypress: function(e) { keyCode: function(e, options) {
return keybinds.mode(e); var kc, key;
kc = e.keyCode;
if ((65 <= kc && kc <= 90)) {
key = String.fromCharCode(kc);
if (!e.shiftKey) {
key = key.toLowerCase();
}
} else if ((48 <= kc && kc <= 57)) {
key = String.fromCharCode(kc);
} else if (kc === 27) {
key = 'Esc';
} else if (options && kc === 8) {
key = '';
}
return key;
} }
}, },
img: function(thread, all) { img: function(thread, all) {
@ -1132,22 +1135,10 @@
return g.hiddenReplies = {}; return g.hiddenReplies = {};
}, },
keybind: function(e) { keybind: function(e) {
var kc, key; var key;
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
kc = e.keyCode; key = keybinds.cb.keyCode(e, true);
if ((65 <= kc && kc <= 90)) {
key = String.fromCharCode(kc);
if (!e.shiftKey) {
key = key.toLowerCase();
}
} else if ((48 <= kc && kc <= 57)) {
key = String.fromCharCode(kc);
} else if (kc === 27) {
key = 'Esc';
} else if (kc === 8) {
key = '';
}
if (key != null) { if (key != null) {
if (key) { if (key) {
if (e.altKey) { if (e.altKey) {

View File

@ -535,19 +535,10 @@ keybinds =
keybinds.update = if (key = $.getValue 'key/update', 0).length >= 0 then key else 'u' keybinds.update = if (key = $.getValue 'key/update', 0).length >= 0 then key else 'u'
$.bind d, 'keydown', keybinds.cb.keydown $.bind d, 'keydown', keybinds.cb.keydown
$.bind d, 'keypress', keybinds.cb.keypress
cb: cb:
keydown: (e) -> keydown: (e) ->
kc = e.keyCode key = keybinds.cb.keyCode e
if 65 <= kc <= 90 #A-Z
key = String.fromCharCode kc
if !e.shiftKey
key = key.toLowerCase()
else if 48 <= kc <= 57 #0-9
key = String.fromCharCode kc
else if kc is 27
key = 'Esc'
if e.altKey then key = 'alt+' + key if e.altKey then key = 'alt+' + key
if e.ctrlKey then key = 'ctrl+' + key if e.ctrlKey then key = 'ctrl+' + key
keybinds.key = key keybinds.key = key
@ -617,8 +608,19 @@ keybinds =
return return
e.preventDefault() e.preventDefault()
keypress: (e) -> keyCode: (e, options) ->
keybinds.mode e kc = e.keyCode
if 65 <= kc <= 90 #A-Z
key = String.fromCharCode kc
if !e.shiftKey
key = key.toLowerCase()
else if 48 <= kc <= 57 #0-9
key = String.fromCharCode kc
else if kc is 27
key = 'Esc'
else if options and kc is 8
key = ''
key
img: (thread, all) -> img: (thread, all) ->
if all if all
@ -906,17 +908,7 @@ options =
keybind: (e) -> keybind: (e) ->
e.preventDefault() e.preventDefault()
e.stopPropagation() e.stopPropagation()
kc = e.keyCode key = keybinds.cb.keyCode e, true
if 65 <= kc <= 90 #A-Z
key = String.fromCharCode kc
if !e.shiftKey
key = key.toLowerCase()
else if 48 <= kc <= 57 #0-9
key = String.fromCharCode kc
else if kc is 27
key = 'Esc'
else if kc is 8
key = ''
if key? if key?
if key if key