diff --git a/api/main.js b/api/main.js index 03166a66..72372253 100644 --- a/api/main.js +++ b/api/main.js @@ -211,6 +211,15 @@ the browser behave as if the templated HTML was the regular source. // Positioning this after the last `document.write`. document.close(); + + if (Mobify.studioJS) { + Mobify.studioJS.get('renderHTML', function(markup) { + oldEmitMarkup(markup); + }); + } + + // Bind `orientationchange` listener and add `html` classes. + Mobify.enhance(); }; if (Mobify.isIOS8_0()){ @@ -219,16 +228,6 @@ the browser behave as if the templated HTML was the regular source. } else { write(); } - - if (Mobify.studioJS) { - Mobify.studioJS.get('renderHTML', function(markup) { - oldEmitMarkup(markup); - }); - } - - // Bind `orientationchange` listener and add `html` classes. - Mobify.enhance(); - }; var oldEmitMarkup; if (Mobify.studioJS) { diff --git a/api/util.js b/api/util.js index eb19c172..2acb4bca 100644 --- a/api/util.js +++ b/api/util.js @@ -115,10 +115,17 @@ head.appendChild(meta); if (callback) { - // Wait two paints for the meta tag to take effect. - window.requestAnimationFrame(function() { - window.requestAnimationFrame(callback); - }); + // Wait two paints for the meta viewport tag to take effect. This is + // required for this fix to work, but guard against it being undefined + // anyway just in case. + if (window.requestAnimationFrame) { + window.requestAnimationFrame(function() { + window.requestAnimationFrame(callback); + }); + } + else { + callback(); + } } }; diff --git a/test/util-test.html b/test/util-test.html index eaecb00c..1eaddc85 100644 --- a/test/util-test.html +++ b/test/util-test.html @@ -251,7 +251,24 @@

}); +test("Mobify.ios8_0ScrollFix", function() { + var html = document.createElement('html'); + var head = document.createElement('head'); + html.appendChild(head); + Mobify.ios8_0ScrollFix(html, function() { + var meta = html.getElementsByTagName('meta')[0] + + ok(true, + 'meta tag is appended'); + equal(meta.getAttribute('name'), 'viewport', + 'meta name is viewport'); + equal(meta.getAttribute('content'), 'width=device-width', + 'content is width=device-width'); + + start(); + }); +});