0

I created a new GitHub page using their automatic generator and, in the generated page, found this line from the GitHub template:

<!--[if !IE]><script>fixScale(document);</script><!--<![endif]-->

This being from the good boys and girls at GitHub, I wondered if this is something I might want to adapt from my own HTML. But none of the javascript referenced in that file define such a function and this doesn't seem to be a native (window) function.

So, what does this function do and would I want to include it in my own HTML?

Edward Samson
  • 2,395
  • 2
  • 26
  • 39

2 Answers2

1
>> what does this function do and would I want to include it in my own HTML?

Depends on the actual source code for fixscale().

If it is like https://github.com/cbrandolino/camvas/blob/master/javascripts/scale.fix.js

Then, this code addresses an iOS device (iPhone/iPad) viewport issue.

The meta viewport tag works when the page is initially loaded.

However, when the user subsequently rotates the device their viewport (from landscape to portrait for example) their viewport will resize and will be overly zoomed in.

The scale.fix.js code fixes this problem.

You can call it like this:

<!--[if !IE]><!-->
  <script>
    fixScale(document);                               // fix current scale on iOS devices     
    window.onorientationchange = fixScale(document);  // and when orientation changes
  </script>
<!--<![endif]-->

That syntax looks odd, but it's correct. For details see: if-ie-not-working

Note that the way this is coded fixScale() is globally defined. You probably should look at the something like "module method" for a better way to expose your javascript functions.

On a side note, in order to prevent a jshint error (in scale.fix.js) you should change this:

scales = [.25, 1.6];

to this:

scales = [0.25, 1.6];

For other jshint tips see: http://lexsheehan.blogspot.com/2014/05/suppress-jshint-warnings.html

Community
  • 1
  • 1
l3x
  • 30,760
  • 1
  • 55
  • 36
  • You might have referred to the conditional comments, but `window.onorientationchange = fixScale(document);` is certainly *not* correct… – Bergi Jul 19 '14 at 16:49
  • Great answer. Thanks for taking the time to both describe the use case for the function as well as the how this particular ie-conditional works, and for providing links to relevant documentation! – Scott Offen Jul 19 '14 at 16:51
  • @Bergi - If it is not correct, explain how. The onorientationchange event is valid on iOS, which is the only place this code is expected to execute, so what part is incorrect? – Scott Offen Jul 19 '14 at 16:53
  • The call `fixScale(document)` does return `undefined`, so you're not creating an event handler. – Bergi Jul 19 '14 at 17:40
0

The way this line is written, it is just a plain comment and does nothing.

Edward Samson
  • 2,395
  • 2
  • 26
  • 39