Created
January 26, 2012 20:46
-
-
Save michsch/1685003 to your computer and use it in GitHub Desktop.
Disable zooming for iPhone using jQuery
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
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() |
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
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