From a2fe5c781916674686efa3bf2781347b2634834f Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 20 Feb 2013 04:43:07 +0100 Subject: [PATCH] Add the Keybinds settings section. --- 4chan_x.user.js | 36 ++++++++++++++++++++++++++++++++++-- src/features.coffee | 27 +++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index c607afbe8..434c966be 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1273,7 +1273,38 @@ filter: function(section) {}, sauce: function(section) {}, rice: function(section) {}, - keybinds: function(section) {} + keybinds: function(section) { + var arr, input, key, tbody, tr, _ref, _results; + section.innerHTML = "
Keybinds are disabled.
\n
Allowed keys: a-z, 0-9, Enter, Ctrl, Shift, Alt, Meta, Esc, Up, Down, Right, Left.
\n
Press Return to disable a keybind.
\n\n \n
ActionsKeybinds
"; + tbody = $('tbody', section); + _ref = Config.hotkeys; + _results = []; + for (key in _ref) { + arr = _ref[key]; + tr = $.el('tr', { + innerHTML: "" + arr[1] + "" + }); + input = $('input', tr); + input.name = key; + input.value = $.get(key, Conf[key]); + $.on(input, 'keydown', Settings.keybind); + _results.push($.add(tbody, tr)); + } + return _results; + }, + keybind: function(e) { + var key; + if (e.keyCode === 9) { + return; + } + e.preventDefault(); + e.stopPropagation(); + if ((key = Keybinds.keyCode(e)) == null) { + return; + } + this.value = key; + return $.cb.value.call(this); + } }; Fourchan = { @@ -2542,7 +2573,8 @@ default: return; } - return e.preventDefault(); + e.preventDefault(); + return e.stopPropagation(); }, keyCode: function(e) { var kc, key; diff --git a/src/features.coffee b/src/features.coffee index 5ebc70bd9..5f8b4adea 100644 --- a/src/features.coffee +++ b/src/features.coffee @@ -258,8 +258,30 @@ Settings = # XXX TODO keybinds: (section) -> - # XXX TODO - + section.innerHTML = """ +
Keybinds are disabled.
+
Allowed keys: a-z, 0-9, Enter, Ctrl, Shift, Alt, Meta, Esc, Up, Down, Right, Left.
+
Press Return to disable a keybind.
+ + +
ActionsKeybinds
+ """ + tbody = $ 'tbody', section + for key, arr of Config.hotkeys + tr = $.el 'tr', + innerHTML: "#{arr[1]}" + input = $ 'input', tr + input.name = key + input.value = $.get key, Conf[key] + $.on input, 'keydown', Settings.keybind + $.add tbody, tr + keybind: (e) -> + return if e.keyCode is 9 # tab + e.preventDefault() + e.stopPropagation() + return unless (key = Keybinds.keyCode e)? + @value = key + $.cb.value.call @ Fourchan = init: -> @@ -1264,6 +1286,7 @@ Keybinds = else return e.preventDefault() + e.stopPropagation() keyCode: (e) -> key = switch kc = e.keyCode