Created
May 8, 2013 15:17
-
-
Save wpscholar/5541161 to your computer and use it in GitHub Desktop.
jQuery plugin to force a blur event in iOS when a user taps out of an input.
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
$.fn.iosTapOut = function() { | |
return this.each( function() { | |
var $this = $(this); | |
var canTouch = 'ontouchstart' in document.documentElement; | |
if( canTouch ) { | |
$this.data( 'iosTapOut.active', false ); | |
$(document).bind( 'touchstart.iosTapOut', function(e) { | |
if( $this.data('iosTapOut.active') ) { | |
if( ! $(e.target).is($this) ) { | |
$this.data('iosTapOut.active', false); | |
$this.blur(); | |
} | |
} | |
} ); | |
$this.bind( 'touchstart.iosTapOut', function() { | |
$this.data( 'iosTapOut.active', true ); | |
} ); | |
} | |
} ); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment