Created
November 13, 2012 21:03
-
-
Save tedw/4068377 to your computer and use it in GitHub Desktop.
iOS Polyfills
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
/* Toggle Zoom on iPhone */ | |
var DisableZoom = function( disable ) { | |
// Check for meta tag | |
var hasMeta = $('head meta[name=viewport]').length, | |
opts = ( disable ? 'minimum-scale=1.0, maximum-scale=1.0' : 'maximum-scale=10'); | |
// Check if meta viewport tag exsits | |
if ( hasMeta ) { | |
// Remove current meta viewport tag | |
$('head meta[name=viewport]').remove(); | |
} | |
// Add new meta viewport tag | |
$('head').prepend('<meta name="viewport" content="width=device-width, initial-scale=1.0, ' + opts + ', user-scalable=yes" />'); | |
}; | |
// Force iOS to honor label "for" attributes | |
$('label').each(function() { | |
$(this).attr('onclick',''); | |
}); | |
// Force iOS to honor label "disabled" attribute | |
$('option[disabled="disabled"]').remove(); | |
// Prevent iOS from zooming when selecting form elements | |
if( isIOS ) { | |
var $el = $('select, input').not('input[type="submit"], input[type="button"]'); | |
$el.on('focus', function() { | |
DisableZoom( true ); | |
}); | |
$el.on('blur', function() { | |
DisableZoom( false ); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment