Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Shortcuts are enabled on INPUT, SELECT or TEXTAREA elements with the `keymaster-enabled' class #27

Closed
wants to merge 1 commit into from

5 participants

@ghost

Hello,

I've modified keymaster to allow keybord shortcuts on INPUT, SELECT and TEXTAREA with the `keymaster-enabled' class.

@arextar

This could work across more browsers:

if ((" " + (event.target || event.srcElement).className + " ").indexOf(" keymaster-enabled ") < 0) return
@fluxsaas

funny, i just did the same thing, before i looked in the pull requests :) but i borrowed the jquey hasClass method....

fluxsaas@5ca33f8

@dariocravero

@madrobby any chance of including this on the base code or is there a particular reason why you wouldn't want to implement it?

@ruimarinho

This would be very welcomed!

@madrobby madrobby closed this
@madrobby
Owner

We've taken on an other strategy in #33, so I'm closing this. It should be easy now to base this on CSS classes if you want to.

@dariocravero

Great! :) Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 17, 2011
  1. Shortcuts are enabled on INPUT, SELECT or TEXTAREA elements with the …

    Skami18 authored
    …`keymaster-enabled' class
This page is out of date. Refresh to see the latest.
Showing with 5 additions and 2 deletions.
  1. +3 −1 keymaster.js
  2. +2 −1  test.html
View
4 keymaster.js
@@ -55,7 +55,9 @@
}
// ignore keypressed in any elements that support keyboard data input
- if (tagName == 'INPUT' || tagName == 'SELECT' || tagName == 'TEXTAREA') return;
+ if (tagName == 'INPUT' || tagName == 'SELECT' || tagName == 'TEXTAREA') {
+ if (!(event.target || event.srcElement).classList.contains('keymaster-enabled')) return;
+ }
// abort if no potentially matching shortcuts found
if (!(key in _handlers)) return;
View
3  test.html
@@ -13,6 +13,7 @@
<input type="text" placeholder="a text input"/>
<select><option></option><option>select</option></select>
<textarea placeholder="a textarea"></textarea>
+ <textarea placeholder="Shortcuts are enabled for this textarea" class="keymaster-enabled"></textarea>
<ol>
<li>Press 'c'. Nothing should be logged on console.</li>
@@ -27,7 +28,7 @@
</p>
<p>
- When a input, a select or a textarea element is focused, key inputs should be ignored.
+ When a input, a select or a textarea element is focused, key inputs should be ignored unless this element has the class <code>keymaster-enabled</code>.
</p>
<script>
Something went wrong with that request. Please try again.