Skip to content

Instantly share code, notes, and snippets.

@michsch
Created January 26, 2012 20:46
Show Gist options
  • Save michsch/1685003 to your computer and use it in GitHub Desktop.
Save michsch/1685003 to your computer and use it in GitHub Desktop.
Disable zooming for iPhone using jQuery
jQuery(document).ready ($) ->
###*
* Init function for domready
*
* @return boolean true
###
init = ->
resetViewportMeta()
true
###*
* Gets the window width
*
* @return integer width in pixel
###
getWindowWidth = ->
windowWidth = window.innerWidth
if !windowWidth
windowWidth = $('body').width()
windowWidth
###*
* Reset the viewport meta definition
*
* @param integer minimum width in pixel to disable zooming
* @return boolean true
###
resetViewportMeta = (minSize = 480) ->
if getWindowWidth() <= minSize
$('head meta[name=viewport]').attr 'content', 'width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0"
true
init()
jQuery(document).ready(function($) {
/**
* Init function for domready
*
* @return boolean true
*/
var getWindowWidth, init, resetViewportMeta;
init = function() {
resetViewportMeta();
return true;
};
/**
* Gets the window width
*
* @return integer width in pixel
*/
getWindowWidth = function() {
var windowWidth;
windowWidth = window.innerWidth;
if (!windowWidth) {
windowWidth = $('body').width();
}
return windowWidth;
};
/**
* Reset the viewport meta definition
*
* @param integer minimum width in pixel to disable zooming
* @return boolean true
*/
resetViewportMeta = function(minSize) {
if (minSize == null) {
minSize = 480;
}
if (getWindowWidth() <= minSize) {
$('head meta[name=viewport]').attr('content', 'width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0');
}
return true;
};
return init();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment