Created
June 22, 2012 14:57
-
-
Save thebaer/2973279 to your computer and use it in GitHub Desktop.
Detects which method was used to change the value in an HTML5 number input (clicking to increment or entering a number)
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
var key = false; | |
var inp = false; | |
var click = false; | |
// Get the input method | |
$('#inp').bind('input keypress mousedown paste', function(e) { | |
$('#inp').after('<br>' + e.type); | |
if (e.type == 'input') { | |
inp = true; | |
} else if (e.type == 'keypress' || e.type == 'paste') { | |
key = true; | |
click = false; | |
} else if (e.type == 'mousedown') { | |
click = true; | |
key = false; | |
} | |
}); | |
// Determine which was used | |
$('#inp').change(function(e) { | |
if (key && inp) { | |
$('#inp').after('<br>KEYBOARD'); | |
} else if (click && inp) { | |
$('#inp').after('<br>STEP'); | |
} | |
inp = false; | |
key = false; | |
click = false; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment