Last active
March 28, 2017 16:52
-
-
Save tmosest/2a0d4d565418811d305f64bf1d168487 to your computer and use it in GitHub Desktop.
Mobile Device Fix Blur Hide Keyboard iPhone Android Angular JS
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 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