Comment

Comment by foobar2k

You could trivially restructure the code to factor out global page actions into an object, like this:

    // Make a global page actions object
    PageActions = {
      selectAll: function (event, context) {...},
      nextPage: function (event, context) {...},
      prevPage: function (event, context) {...},
    };

    // Hook up clicks to global actions
    // Eg: <a href="#" data-action="selectAll">All</a>
    $("[data-action]").click(function () {
      var action = $(this).data("action");
      PageActions.selectAll("click", this);
    });

    // Hook up keypresses to global actions
    Mousetrap.bind("a", function () {
      PageActions.selectAll("keypress", this);
    });
This would help with code structure and organization, at the cost of flexibility.
parent foobar2k 13 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton