Created
April 27, 2012 13:21
-
-
Save paprikka/2509174 to your computer and use it in GitHub Desktop.
JS: detect caps lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function checkCapslock (e) { | |
var $el = $(this), | |
hasLabel = $el.parent().find('.capslock-on-alert').length > 0 ? true : false; | |
var kc = e.keyCode?e.keyCode:e.which; | |
var sk = e.shiftKey?e.shiftKey:((kc == 16)?true:false); | |
var isCaps = ((kc >= 65 && kc <= 90) && !sk)||((kc >= 97 && kc <= 122) && sk); | |
if(isCaps && !hasLabel) { | |
$el.after('<label for="password" generated="true" class="error capslock-on-alert">Klawisz CAPS LOCK jest włączony.</label>'); | |
} else if(!isCaps && hasLabel) { | |
$('.capslock-on-alert').remove(); | |
} | |
} | |
$('input[type="password"]').live('keypress', checkCapslock); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment