Skip to content

Instantly share code, notes, and snippets.

@tmosest
Last active March 28, 2017 16:52
Show Gist options
  • Save tmosest/2a0d4d565418811d305f64bf1d168487 to your computer and use it in GitHub Desktop.
Save tmosest/2a0d4d565418811d305f64bf1d168487 to your computer and use it in GitHub Desktop.
Mobile Device Fix Blur Hide Keyboard iPhone Android Angular JS
function isTextInput(node) {
return ['INPUT', 'TEXTAREA'].indexOf(node.nodeName) !== -1;
}
angular.element($document[0]).on('touchstart', function(e) {
var activeElement = angular.element($document[0].activeElement)[0];
if(!isTextInput(e.target) && isTextInput(activeElement)) {
activeElement.blur();
}
});
/*
document.addEventListener('touchstart', function(e) {
if(!isTextInput(e.target) && isTextInput(document.activeElement)) {
document.activeElement.blur();
}
}, false);
*/
if($document[0].activeElement) {
$document[0].activeElement.blur();
}
$timeout(function() {
angular.element('input').blur();
}, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment