Permalink
Browse files

Mathias Bynens' iOS viewport scaling bugfix js.

  • Loading branch information...
1 parent c2be80d commit 6a7dc39cf0002bf49b723cb633790d8b3e6706f5 Dougal Campbell committed May 4, 2011
Showing with 30 additions and 0 deletions.
  1. +30 −0 js/ios-scaling-bug-fix.js
View
@@ -0,0 +1,30 @@
+/**
+ * iOS viewport scaling bug fix
+ * See:
+ * http://filamentgroup.com/examples/iosScaleBug/
+ * https://gist.github.com/901295
+ *
+ * Rewritten version
+ * By @mathias, @cheeaun and @jdalton
+ */
+
+(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 6a7dc39

Please sign in to comment.