summaryrefslogtreecommitdiff
path: root/media/js/ios-viewport-scaling-bug-fix.js
blob: 4e9a9b38de49da3a710118370caac6b843a3db3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// My rewritten version
// 1) won't restrict viewport if JS is disabled
// 2) uses capture phase
// 3) assumes last viewport meta is the one to edit (incase for some odd reason there is more than one)
// 4) feature inference (no sniffs, behavior should be ignored on other enviros)
// 5) removes event handler after fired
!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, !0);
  }
  if ((meta = meta[meta.length - 1]) && addEvent in doc) {
    fix();
    scales = [.25, 1.6];
    doc[addEvent](type, fix, !0);
  }
}(document);