TODO in a tweet

by Francisco Presencia Fandos

HTML

<script src="https://unpkg.com/umbrellajs"></script>
<script>
// Store the body in an external variable
const body = u("body");

// Keyboard event handler
const onKey = e => {
  // Pressing ENTER
  if (e.keyCode === 13) {
    // Create a paragraph that toggles the class "x" when clicked
    const p = u(`<p>${e.currentTarget.value}</p>`)
      .on("click", e => u(e.currentTarget).toggleClass("x"));
    body.append(p)
  }
  // Pressing ESCAPE
  if (e.keyCode === 27) {
    // Remove all of the paragraphs
    u("p").remove()
  }
  // Anything else just types as normal
};

// Add a single Input element with an event handler
body.append(u("<input>").on("keyup", onKey));
</script>
<style>.x{text-decoration:line-through}