Created
July 20, 2015 02:01
-
-
Save jsguy/21e71fda6b4076901a67 to your computer and use it in GitHub Desktop.
Allow click to work even when keyboard is shown on mobile device
This file contains hidden or 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
/* | |
Make the submit button "click" even when the keyboard is shown | |
http://stackoverflow.com/questions/24306818/form-submit-button-event-is-not-captured-when-keyboard-is-up-ios-7 | |
http://stackoverflow.com/questions/12690620/checking-if-touchend-comes-after-a-drag | |
Note: requires jQuery | |
*/ | |
$(function(){ | |
// Check if the user is dragging | |
var isDragging; | |
$(document).on("touchstart", function () { | |
isDragging = false; | |
}); | |
$(document).on("touchmove", function () { | |
isDragging = true; | |
}); | |
// The touchend even fires, even when keyboard is open | |
$(document).on('touchend', 'form :input[type=submit]', function (e) { | |
if (isDragging) { | |
return false; | |
} | |
// Fire the associated click event | |
$(this).click(); | |
e.preventDefault(); | |
return false; | |
}); | |
}(window.jQuery || $)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment