Skip to content

Commit

Permalink
blur active input w/ setTimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Bradley committed Feb 17, 2014
1 parent 35ad051 commit f736ae5
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions js/utils/poly.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@

if(ele.tagName === 'INPUT' || ele.tagName === 'TEXTAREA' || ele.tagName === 'SELECT') {
ele.focus();
e.preventDefault();
} else {
ele.blur();
blurActive();
}

// remember the coordinates of this tap so if it happens again we can ignore it
Expand Down Expand Up @@ -103,12 +104,7 @@
// they didn't tap one of the above elements
// if the currently active element is an input, and they tapped outside
// of the current input, then unset its focus (blur) so the keyboard goes away
ele = document.activeElement;
if(ele && (ele.tagName === "INPUT" ||
ele.tagName === "TEXTAREA" ||
ele.tagName === "SELECT")) {
ele.blur();
}
blurActive();
}

function preventGhostClick(e) {
Expand Down Expand Up @@ -159,6 +155,18 @@
return false;
}

function blurActive() {
var ele = document.activeElement;
if(ele && (ele.tagName === "INPUT" ||
ele.tagName === "TEXTAREA" ||
ele.tagName === "SELECT")) {
// using a timeout to prevent funky scrolling while a keyboard hides
setTimeout(function(){
ele.blur();
}, 400);
}
}

function isRecentTap(event) {
// loop through the tap coordinates and see if the same area has been tapped recently
var tapId, existingCoordinates, currentCoordinates,
Expand Down

0 comments on commit f736ae5

Please sign in to comment.