Permalink
Browse files

Merge pull request #306 from mobify/ios-preload-hit-fix

Added iOS8 preload-top-hits issue fix for v7 tag
  • Loading branch information...
2 parents f2038d1 + 644c231 commit 4a4ff8a37ea69491fc2345b3c465e01257ae0612 @donnielrt donnielrt committed Sep 24, 2015
Showing with 18 additions and 4 deletions.
  1. +15 −1 tag/v7.js
  2. +3 −3 tag/v7.min.js
View
@@ -202,6 +202,20 @@ Private['loadPreview'] = loadPreview;
@type {null}
*/
var disableTag = function() {
+ // This workaround addresses an iOS fallthrough issue, where
+ // iOS 8's "preload top hits" option will load a Mobified page
+ // in the background when typing in an address into the URL bar.
+ // Safari seems to cancel the mobify.js download, resulting in
+ // us dropping a failure cookie.
+ //
+ // We get around this by ignoring adaptive script failures in a
+ // background tab.
+ //
+ // Related ticket: https://mobify.atlassian.net/browse/RTM-280
+ if (document.visibilityState && document.hidden) {
+ return;
+ }
+
var now = new Date();
// Set now to 5 minutes ahead
now.setTime(now.getTime() + 5*60*1000);
@@ -343,7 +357,7 @@ Tag['init'] = function(options) {
src: opts['url'],
onerror: disableTag,
onload: postloadCallback
- }
+ };
loadScript(options, "mobify");
};
View
@@ -1,3 +1,3 @@
-(function(e,f){function h(a){if(a.mode){var b=g("mobify-mode");b&&a[b]||(b=a.mode(c.ua));return a[b]}return a}function m(){function a(a){e.addEventListener(a,function(){c[a]=+new Date},!1)}e.addEventListener&&(a("DOMContentLoaded"),a("load"))}function n(){var a=new Date;a.setTime(a.getTime()+3E5);f.cookie="mobify-path=; expires="+a.toGMTString()+"; path=/";e.location.reload()}function p(){k({src:"https://preview.mobify.com/v7/"})}function g(a){if(a=f.cookie.match(RegExp("(^|; )"+a+"((=([^;]*))|(; |$))")))return a[4]||
-""}function l(a){f.write('<plaintext style="display:none">');setTimeout(function(){d.capturing=!0;a()},0)}function k(a,b){var e=f.getElementsByTagName("script")[0],c=f.createElement("script"),d;for(d in a)c[d]=a[d];b&&c.setAttribute("class",b);e.parentNode.insertBefore(c,e)}var d=e.Mobify={},c=d.Tag={};d.points=[+new Date];d.tagVersion=[7,0];c.ua=e.navigator.userAgent;c.getOptions=h;c.init=function(a){c.options=a;if(""!==g("mobify-path"))if(m(),a.skipPreview||"true"!=g("mobify-path")&&!/mobify-path=true/.test(e.location.hash)){var b=
-h(a);if(b){var d=function(){b.post&&b.post()};a=function(){b.pre&&b.pre();k({id:"mobify-js",src:b.url,onerror:n,onload:d},"mobify")};!1===b.capture?a():l(a)}}else l(p)}})(window,document);
+(function(e,f){function h(a){if(a.mode){var b=g("mobify-mode");b&&a[b]||(b=a.mode(c.ua));return a[b]}return a}function m(){function a(a){e.addEventListener(a,function(){c[a]=+new Date},!1)}e.addEventListener&&(a("DOMContentLoaded"),a("load"))}function n(){if(!f.visibilityState||!f.hidden){var a=new Date;a.setTime(a.getTime()+3E5);f.cookie="mobify-path=; expires="+a.toGMTString()+"; path=/";e.location.reload()}}function p(){k({src:"https://preview.mobify.com/v7/"})}function g(a){if(a=f.cookie.match(new RegExp("(^|; )"+
+a+"((=([^;]*))|(; |$))")))return a[4]||""}function l(a){f.write('<plaintext style="display:none">');setTimeout(function(){d.capturing=!0;a()},0)}function k(a,b){var e=f.getElementsByTagName("script")[0],c=f.createElement("script"),d;for(d in a)c[d]=a[d];b&&c.setAttribute("class",b);e.parentNode.insertBefore(c,e)}var d=e.Mobify={},c=d.Tag={};d.points=[+new Date];d.tagVersion=[7,0];c.ua=e.navigator.userAgent;c.getOptions=h;c.init=function(a){c.options=a;if(""!==g("mobify-path"))if(m(),a.skipPreview||
+"true"!=g("mobify-path")&&!/mobify-path=true/.test(e.location.hash)){var b=h(a);if(b){var d=function(){b.post&&b.post()};a=function(){b.pre&&b.pre();k({id:"mobify-js",src:b.url,onerror:n,onload:d},"mobify")};!1===b.capture?a():l(a)}}else l(p)}})(window,document);

0 comments on commit 4a4ff8a

Please sign in to comment.