~nhanb/pytaku

54f973f94af0dda21a6e052be7fa97a2b60323ce — Bùi Thành Nhân 20 days ago 8a01764
j-k scrolling because why not
1 files changed, 13 insertions(+), 1 deletions(-)

M src/pytaku/js-src/routes/chapter.js
M src/pytaku/js-src/routes/chapter.js => src/pytaku/js-src/routes/chapter.js +13 -1
@@ 5,6 5,8 @@ const KEYCODE_PLUS = 43;
const KEYCODE_MINUS = 45;
const KEYCODE_ZERO = 48;
const KEYCODE_QUESTION_MARK = 63;
const KEYCODE_J = 106;
const KEYCODE_K = 107;

const LoadingPlaceholder = {
  view: () => m("h2", [m("i.icon.icon-loader.spin")]),


@@ 78,6 80,8 @@ function Chapter(initialVNode) {
  let pageMaxWidth = 100; // in percent

  function onKeyPress(event) {
    if (event.target.tagName === "INPUT") return;

    switch (event.keyCode) {
      case KEYCODE_PLUS:
        if (pageMaxWidth <= 85) pageMaxWidth += 15;


@@ 92,7 96,15 @@ function Chapter(initialVNode) {
        window.alert(`Keyboard shortcuts:
    - to decrease page size
    + to increase page size (max 100%)
    0 (zero) to reset page size`);
    0 (zero) to reset page size
    j to scroll down
    k to scroll up`);
        break;
      case KEYCODE_J:
        window.scrollBy({ top: 350, behavior: "smooth" });
        break;
      case KEYCODE_K:
        window.scrollBy({ top: -350, behavior: "smooth" });
        break;
    }
    m.redraw();