Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Global DOM element activation

License

NotificationsYou must be signed in to change notification settings

JavaScriptExpert/hotkey

 
 

Repository files navigation

Trigger a action on element when keyboard hotkey is pressed.

Automatically binds hotkeys to any link with adata-hotkeyattribute set. Multiple hotkeys are separated by a,.Key combinations are separated by a+, and key sequencesare separated by a space.

Two-keypress sequences likeg c andg i would be storedunder the 'g' key in a nested object with keys 'c' and 'i'.

mappings =  'c'     : <a href="/rails/rails/issues/new" data-hotkey="c">New Issue</a>  'g'     :    'c'   : <a href="/rails/rails" data-hotkey="g c">Code</a>    'i'   : <a href="/rails/rails/issues" data-hotkey="g i">Issues</a>

So bothg c andc could be available hotkeys on the samepage, butg c andg couldn't coexist. If the user pressesg, thec hotkey will be unavailable for 1500ms while welisten for eitherg c org i.

Installation

$ npm install @github/hotkey

Usage

HTML

<ahref="/page/2"data-hotkey="j">Next</a><ahref="/help"data-hotkey="Control+h">Help</a><ahref="/rails/rails"data-hotkey="g c">Code</a><ahref="/search"data-hotkey="s,/">Search</a>

Seethe list ofKeyboardEvent key values for a list of supported key values.

JS

import{install}from'@github/hotkey'for(constelofdocument.querySelector('[data-hotkey]')){install(el)}

Development

npm installnpm test

License

Distributed under the MIT license. See LICENSE for details.

About

Global DOM element activation

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript100.0%

[8]ページ先頭

©2009-2026 Movatter.jp