From 566672afe720b663f6162507d8fb2990863c6d6a Mon Sep 17 00:00:00 2001 From: James Campos Date: Sun, 31 Jul 2011 12:50:37 -0700 Subject: [PATCH] keybinds.cb -> keybinds --- 4chan_x.user.js | 264 ++++++++++++++++++++++++------------------------ script.coffee | 175 ++++++++++++++++---------------- 2 files changed, 218 insertions(+), 221 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 1f6cd3e7d..ddd792d59 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -722,140 +722,138 @@ node = _ref[_i]; node.removeAttribute('accesskey'); } - return $.bind(d, 'keydown', keybinds.cb.keydown); + return $.bind(d, 'keydown', keybinds.keydown); }, - cb: { - keydown: function(e) { - 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)) { - 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; + keydown: function(e) { + 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)) { + return; } + 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) { var root, thumb; @@ -1130,7 +1128,7 @@ keybind: function(e) { e.preventDefault(); e.stopPropagation(); - if ((key = keybinds.cb.keyCode(e)) == null) { + if ((key = keybinds.keyCode(e)) == null) { return; } this.value = key; diff --git a/script.coffee b/script.coffee index af298c196..adda1ebc2 100644 --- a/script.coffee +++ b/script.coffee @@ -515,100 +515,99 @@ keybinds = init: -> for node in $$ '[accesskey]' node.removeAttribute 'accesskey' - $.bind d, 'keydown', keybinds.cb.keydown + $.bind d, 'keydown', keybinds.keydown - cb: - 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 unless key = keybinds.cb.keyCode 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 unless key = keybinds.keyCode e - thread = nav.getThread() - switch key - when conf.close - if o = $ '#overlay' - $.rm o - else if qr.el - qr.close() - when conf.spoiler - ta = e.target - return unless ta.nodeName is 'TEXTAREA' + thread = nav.getThread() + switch key + when conf.close + if o = $ '#overlay' + $.rm o + else if qr.el + qr.close() + when conf.spoiler + ta = e.target + return unless ta.nodeName is 'TEXTAREA' - value = ta.value - selStart = ta.selectionStart - selEnd = ta.selectionEnd + value = ta.value + selStart = ta.selectionStart + selEnd = ta.selectionEnd - valStart = value[0...selStart] + '[spoiler]' - valMid = value[selStart...selEnd] - valEnd = '[/spoiler]' + value[selEnd..] + valStart = value[0...selStart] + '[spoiler]' + valMid = value[selStart...selEnd] + valEnd = '[/spoiler]' + value[selEnd..] - ta.value = valStart + valMid + valEnd - range = valStart.length + valMid.length - ta.setSelectionRange range, range - when conf.zero - window.location = "/#{g.BOARD}/0#0" - when conf.openEmptyQR - keybinds.qr thread - when conf.nextReply - keybinds.hl.next thread - when conf.previousReply - keybinds.hl.prev thread - when conf.expandAllImages - keybinds.img thread, true - when conf.openThread - keybinds.open thread - when conf.expandThread - expandThread.toggle thread - when conf.openQR - keybinds.qr thread, true - when conf.expandImages - keybinds.img thread - when conf.nextThread - nav.next() - when conf.openThreadTab - keybinds.open thread, true - when conf.previousThread - nav.prev() - when conf.update - updater.update() - when conf.watch - watcher.toggle thread - when conf.hide - threadHiding.toggle thread - when conf.nextPage - $('input[value=Next]')?.click() - when conf.previousPage - $('input[value=Previous]')?.click() - when conf.submit - if qr.el - qr.submit.call $ 'form', qr.el - else - $('.postarea form').submit() - when conf.unreadCountTo0 - unread.replies.length = 0 - unread.updateTitle() - Favicon.update() + ta.value = valStart + valMid + valEnd + range = valStart.length + valMid.length + ta.setSelectionRange range, range + when conf.zero + window.location = "/#{g.BOARD}/0#0" + when conf.openEmptyQR + keybinds.qr thread + when conf.nextReply + keybinds.hl.next thread + when conf.previousReply + keybinds.hl.prev thread + when conf.expandAllImages + keybinds.img thread, true + when conf.openThread + keybinds.open thread + when conf.expandThread + expandThread.toggle thread + when conf.openQR + keybinds.qr thread, true + when conf.expandImages + keybinds.img thread + when conf.nextThread + nav.next() + when conf.openThreadTab + keybinds.open thread, true + when conf.previousThread + nav.prev() + when conf.update + updater.update() + when conf.watch + watcher.toggle thread + when conf.hide + threadHiding.toggle thread + when conf.nextPage + $('input[value=Next]')?.click() + when conf.previousPage + $('input[value=Previous]')?.click() + when conf.submit + if qr.el + qr.submit.call $ 'form', qr.el else - return - e.preventDefault() - - keyCode: (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 kc is 8 - key = '' + $('.postarea form').submit() + when conf.unreadCountTo0 + unread.replies.length = 0 + unread.updateTitle() + Favicon.update() else - key = null - if key - if e.altKey then key = 'alt+' + key - if e.ctrlKey then key = 'ctrl+' + key - key + return + e.preventDefault() + + keyCode: (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 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) -> if all @@ -893,7 +892,7 @@ options = keybind: (e) -> e.preventDefault() e.stopPropagation() - return unless (key = keybinds.cb.keyCode e)? + return unless (key = keybinds.keyCode e)? @value = key $.setValue @name, key conf[@name] = key