Skip to content

Latest commit

 

History

History
52 lines (37 loc) · 1.54 KB

README.md

File metadata and controls

52 lines (37 loc) · 1.54 KB

@rubenarakelyan/stimulus-konami-code

CI npm

@rubenarakelyan/stimulus-konami-code is a Stimulus controller to implement the Konami code on a website.

Usage

Register the controller in your application:

import { Application } from "@hotwired/stimulus"
import KonamiCode from "@rubenarakelyan/stimulus-konami-code"

const application = Application.start()
application.register("konami-code", KonamiCode)

Next, define a callback function that will be called whenever the correct keyboard sequence is entered:

function konamiCodeCallback(target) {
  // `target` is the `<body>`
}

Object.assign(window, { konamiCodeCallback })

Then, add the required Stimulus data attributes to your page:

<html data-controller="konami-code" data-konami-code-callback-value="konamiCodeCallback">
  ...
  <body data-action="keydown->konami-code#keydown">
  </body>
  ...
</html>

Now, visit the page and enter the Konami code (↑ ↑ ↓ ↓ ← → ← → b a). Your konamiCodeCallback function will run.

Licence

MIT licence.