Created
August 12, 2014 16:32
-
-
Save bernardodiasc/f487148dfd02d2e3dcb3 to your computer and use it in GitHub Desktop.
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
/** | |
* | |
* Don't break scale on iPad rotate. | |
* | |
* By default iPad re-zooms the page when the device orientation changes. | |
* | |
* The heuristics here do not work always; our page got zoomed in | |
* though it should be max zoomed out. | |
* | |
* This snippet fixes the situation so that you can still zoom in, but when | |
* the device is rotated the scale is restored. | |
* | |
*/ | |
(function(doc) { | |
'use strict'; | |
var addEvent = 'addEventListener', | |
type = 'gesturestart', | |
qsa = 'querySelectorAll', | |
scales = [1, 1], | |
meta = qsa in doc ? doc[qsa]('meta[name=viewport]') : []; | |
function fix() { | |
meta.content = 'width=device-width,minimum-scale=' + scales[0] + ',maximum-scale=' + scales[1]; | |
doc.removeEventListener(type, fix, true); | |
} | |
if ((meta = meta[meta.length - 1]) && addEvent in doc) { | |
fix(); | |
scales = [0.25, 1.6]; | |
doc[addEvent](type, fix, true); | |
} | |
}(document)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment