keybinds.cb -> keybinds

This commit is contained in:
James Campos 2011-07-31 12:50:37 -07:00
parent 869f554e73
commit 566672afe7
2 changed files with 218 additions and 221 deletions

View File

@ -722,140 +722,138 @@
node = _ref[_i]; node = _ref[_i];
node.removeAttribute('accesskey'); node.removeAttribute('accesskey');
} }
return $.bind(d, 'keydown', keybinds.cb.keydown); return $.bind(d, 'keydown', keybinds.keydown);
}, },
cb: { keydown: function(e) {
keydown: function(e) { var o, range, selEnd, selStart, ta, thread, valEnd, valMid, valStart, value, _ref, _ref2, _ref3;
var o, range, selEnd, selStart, ta, thread, valEnd, valMid, valStart, value, _ref, _ref2, _ref3; if (((_ref = e.target.nodeName) === 'TEXTAREA' || _ref === 'INPUT') && !e.altKey && !e.ctrlKey && !(e.keyCode === 27)) {
if (((_ref = e.target.nodeName) === 'TEXTAREA' || _ref === 'INPUT') && !e.altKey && !e.ctrlKey && !(e.keyCode === 27)) { return;
return;
}
if (!(key = keybinds.cb.keyCode(e))) {
return;
}
thread = nav.getThread();
switch (key) {
case conf.close:
if (o = $('#overlay')) {
$.rm(o);
} else if (qr.el) {
qr.close();
}
break;
case conf.spoiler:
ta = e.target;
if (ta.nodeName !== 'TEXTAREA') {
return;
}
value = ta.value;
selStart = ta.selectionStart;
selEnd = ta.selectionEnd;
valStart = value.slice(0, selStart) + '[spoiler]';
valMid = value.slice(selStart, selEnd);
valEnd = '[/spoiler]' + value.slice(selEnd);
ta.value = valStart + valMid + valEnd;
range = valStart.length + valMid.length;
ta.setSelectionRange(range, range);
break;
case conf.zero:
window.location = "/" + g.BOARD + "/0#0";
break;
case conf.openEmptyQR:
keybinds.qr(thread);
break;
case conf.nextReply:
keybinds.hl.next(thread);
break;
case conf.previousReply:
keybinds.hl.prev(thread);
break;
case conf.expandAllImages:
keybinds.img(thread, true);
break;
case conf.openThread:
keybinds.open(thread);
break;
case conf.expandThread:
expandThread.toggle(thread);
break;
case conf.openQR:
keybinds.qr(thread, true);
break;
case conf.expandImages:
keybinds.img(thread);
break;
case conf.nextThread:
nav.next();
break;
case conf.openThreadTab:
keybinds.open(thread, true);
break;
case conf.previousThread:
nav.prev();
break;
case conf.update:
updater.update();
break;
case conf.watch:
watcher.toggle(thread);
break;
case conf.hide:
threadHiding.toggle(thread);
break;
case conf.nextPage:
if ((_ref2 = $('input[value=Next]')) != null) {
_ref2.click();
}
break;
case conf.previousPage:
if ((_ref3 = $('input[value=Previous]')) != null) {
_ref3.click();
}
break;
case conf.submit:
if (qr.el) {
qr.submit.call($('form', qr.el));
} else {
$('.postarea form').submit();
}
break;
case conf.unreadCountTo0:
unread.replies.length = 0;
unread.updateTitle();
Favicon.update();
break;
default:
return;
}
return e.preventDefault();
},
keyCode: function(e) {
var kc;
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 (kc === 8) {
key = '';
} else {
key = null;
}
if (key) {
if (e.altKey) {
key = 'alt+' + key;
}
if (e.ctrlKey) {
key = 'ctrl+' + key;
}
}
return key;
} }
if (!(key = keybinds.keyCode(e))) {
return;
}
thread = nav.getThread();
switch (key) {
case conf.close:
if (o = $('#overlay')) {
$.rm(o);
} else if (qr.el) {
qr.close();
}
break;
case conf.spoiler:
ta = e.target;
if (ta.nodeName !== 'TEXTAREA') {
return;
}
value = ta.value;
selStart = ta.selectionStart;
selEnd = ta.selectionEnd;
valStart = value.slice(0, selStart) + '[spoiler]';
valMid = value.slice(selStart, selEnd);
valEnd = '[/spoiler]' + value.slice(selEnd);
ta.value = valStart + valMid + valEnd;
range = valStart.length + valMid.length;
ta.setSelectionRange(range, range);
break;
case conf.zero:
window.location = "/" + g.BOARD + "/0#0";
break;
case conf.openEmptyQR:
keybinds.qr(thread);
break;
case conf.nextReply:
keybinds.hl.next(thread);
break;
case conf.previousReply:
keybinds.hl.prev(thread);
break;
case conf.expandAllImages:
keybinds.img(thread, true);
break;
case conf.openThread:
keybinds.open(thread);
break;
case conf.expandThread:
expandThread.toggle(thread);
break;
case conf.openQR:
keybinds.qr(thread, true);
break;
case conf.expandImages:
keybinds.img(thread);
break;
case conf.nextThread:
nav.next();
break;
case conf.openThreadTab:
keybinds.open(thread, true);
break;
case conf.previousThread:
nav.prev();
break;
case conf.update:
updater.update();
break;
case conf.watch:
watcher.toggle(thread);
break;
case conf.hide:
threadHiding.toggle(thread);
break;
case conf.nextPage:
if ((_ref2 = $('input[value=Next]')) != null) {
_ref2.click();
}
break;
case conf.previousPage:
if ((_ref3 = $('input[value=Previous]')) != null) {
_ref3.click();
}
break;
case conf.submit:
if (qr.el) {
qr.submit.call($('form', qr.el));
} else {
$('.postarea form').submit();
}
break;
case conf.unreadCountTo0:
unread.replies.length = 0;
unread.updateTitle();
Favicon.update();
break;
default:
return;
}
return e.preventDefault();
},
keyCode: function(e) {
var kc;
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 (kc === 8) {
key = '';
} else {
key = null;
}
if (key) {
if (e.altKey) {
key = 'alt+' + key;
}
if (e.ctrlKey) {
key = 'ctrl+' + key;
}
}
return key;
}, },
img: function(thread, all) { img: function(thread, all) {
var root, thumb; var root, thumb;
@ -1130,7 +1128,7 @@
keybind: function(e) { keybind: function(e) {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
if ((key = keybinds.cb.keyCode(e)) == null) { if ((key = keybinds.keyCode(e)) == null) {
return; return;
} }
this.value = key; this.value = key;

View File

@ -515,100 +515,99 @@ keybinds =
init: -> init: ->
for node in $$ '[accesskey]' for node in $$ '[accesskey]'
node.removeAttribute 'accesskey' node.removeAttribute 'accesskey'
$.bind d, 'keydown', keybinds.cb.keydown $.bind d, 'keydown', keybinds.keydown
cb: keydown: (e) ->
keydown: (e) -> return if e.target.nodeName in ['TEXTAREA', 'INPUT'] and not e.altKey and not e.ctrlKey and not (e.keyCode is 27)
return if e.target.nodeName in ['TEXTAREA', 'INPUT'] and not e.altKey and not e.ctrlKey and not (e.keyCode is 27) return unless key = keybinds.keyCode e
return unless key = keybinds.cb.keyCode e
thread = nav.getThread() thread = nav.getThread()
switch key switch key
when conf.close when conf.close
if o = $ '#overlay' if o = $ '#overlay'
$.rm o $.rm o
else if qr.el else if qr.el
qr.close() qr.close()
when conf.spoiler when conf.spoiler
ta = e.target ta = e.target
return unless ta.nodeName is 'TEXTAREA' return unless ta.nodeName is 'TEXTAREA'
value = ta.value value = ta.value
selStart = ta.selectionStart selStart = ta.selectionStart
selEnd = ta.selectionEnd selEnd = ta.selectionEnd
valStart = value[0...selStart] + '[spoiler]' valStart = value[0...selStart] + '[spoiler]'
valMid = value[selStart...selEnd] valMid = value[selStart...selEnd]
valEnd = '[/spoiler]' + value[selEnd..] valEnd = '[/spoiler]' + value[selEnd..]
ta.value = valStart + valMid + valEnd ta.value = valStart + valMid + valEnd
range = valStart.length + valMid.length range = valStart.length + valMid.length
ta.setSelectionRange range, range ta.setSelectionRange range, range
when conf.zero when conf.zero
window.location = "/#{g.BOARD}/0#0" window.location = "/#{g.BOARD}/0#0"
when conf.openEmptyQR when conf.openEmptyQR
keybinds.qr thread keybinds.qr thread
when conf.nextReply when conf.nextReply
keybinds.hl.next thread keybinds.hl.next thread
when conf.previousReply when conf.previousReply
keybinds.hl.prev thread keybinds.hl.prev thread
when conf.expandAllImages when conf.expandAllImages
keybinds.img thread, true keybinds.img thread, true
when conf.openThread when conf.openThread
keybinds.open thread keybinds.open thread
when conf.expandThread when conf.expandThread
expandThread.toggle thread expandThread.toggle thread
when conf.openQR when conf.openQR
keybinds.qr thread, true keybinds.qr thread, true
when conf.expandImages when conf.expandImages
keybinds.img thread keybinds.img thread
when conf.nextThread when conf.nextThread
nav.next() nav.next()
when conf.openThreadTab when conf.openThreadTab
keybinds.open thread, true keybinds.open thread, true
when conf.previousThread when conf.previousThread
nav.prev() nav.prev()
when conf.update when conf.update
updater.update() updater.update()
when conf.watch when conf.watch
watcher.toggle thread watcher.toggle thread
when conf.hide when conf.hide
threadHiding.toggle thread threadHiding.toggle thread
when conf.nextPage when conf.nextPage
$('input[value=Next]')?.click() $('input[value=Next]')?.click()
when conf.previousPage when conf.previousPage
$('input[value=Previous]')?.click() $('input[value=Previous]')?.click()
when conf.submit when conf.submit
if qr.el if qr.el
qr.submit.call $ 'form', qr.el qr.submit.call $ 'form', qr.el
else
$('.postarea form').submit()
when conf.unreadCountTo0
unread.replies.length = 0
unread.updateTitle()
Favicon.update()
else else
return $('.postarea form').submit()
e.preventDefault() when conf.unreadCountTo0
unread.replies.length = 0
keyCode: (e) -> unread.updateTitle()
kc = e.keyCode Favicon.update()
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 = ''
else else
key = null return
if key e.preventDefault()
if e.altKey then key = 'alt+' + key
if e.ctrlKey then key = 'ctrl+' + key keyCode: (e) ->
key 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 kc is 8
key = ''
else
key = null
if key
if e.altKey then key = 'alt+' + key
if e.ctrlKey then key = 'ctrl+' + key
key
img: (thread, all) -> img: (thread, all) ->
if all if all
@ -893,7 +892,7 @@ options =
keybind: (e) -> keybind: (e) ->
e.preventDefault() e.preventDefault()
e.stopPropagation() e.stopPropagation()
return unless (key = keybinds.cb.keyCode e)? return unless (key = keybinds.keyCode e)?
@value = key @value = key
$.setValue @name, key $.setValue @name, key
conf[@name] = key conf[@name] = key