-
-
Save nelldnine/2ef194cfae5f691bf074a0c27b35c927 to your computer and use it in GitHub Desktop.
iOS 7 fix for not triggering select's onChange event
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
$.fn.quickChange = function(handler) { | |
return this.each(function() { | |
var self = this; | |
self.qcindex = self.selectedIndex; | |
var interval; | |
function handleChange() { | |
if (self.selectedIndex != self.qcindex) { | |
self.qcindex = self.selectedIndex; | |
handler.apply(self); | |
} | |
} | |
$(self).focus(function() { | |
interval = setInterval(handleChange, 100); | |
}).blur(function() { window.clearInterval(interval); }) | |
.change(handleChange); //also wire the change event in case the interval technique isn't supported (chrome on android) | |
}); | |
}; | |
$('select').quickChange(function(e) { | |
$(this).blur(); | |
$('select').focus(); // prevents an extra blur from firing on focus | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment