Permalink
Browse files

Merge pull request #1 from aaronsalmon/master

js to fix the ios scaling bug when switching from portrait to landscape.
  • Loading branch information...
2 parents 06f7710 + ade9b3c commit 99bf4a323ef8cc3ecf86db5a8e3b9f83fb9bb784 @dryan committed Nov 20, 2011
Showing with 26 additions and 0 deletions.
  1. +6 −0 demo.html
  2. +20 −0 js/ios-viewport-scaling-bug-fix.js
View
@@ -162,5 +162,11 @@ <h1>Demo</h1>
<div class="columns two-fifths offset-one-fifth"><b>two-fifths offset-one-fifth</b></div>
</div>
</div><!-- end #main -->
+
+ <!--[if !IE]>
+ <!-- Fix for the iOS viewport scaling bug. https://gist.github.com/901295 -->
+ <script src="js/ios-viewport-scaling-bug-fix.js"></script>
+ <!--<![endif]-->
+
</body>
</html>
@@ -0,0 +1,20 @@
+(function(doc) {
+
+ 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 = [.25, 1.6];
+ doc[addEvent](type, fix, true);
+ }
+
+}(document));

0 comments on commit 99bf4a3

Please sign in to comment.