diff options
author | artemave <artemave@gmail.com> | 2014-04-22 01:50:30 +0400 |
---|---|---|
committer | Elliot Bradbury <ebradbury@gmail.com> | 2015-02-14 19:25:13 +0300 |
commit | 1e021bc5e0681cdb7323f9ebad0759cb50e9b03f (patch) | |
tree | cd7b2adaffbf84e08a2e00eb96a6512b0511f70c | |
parent | 91535d4876d0b6f3d057fde202e2f9df8011462d (diff) |
push.js: add file:// urls support
Fix for Android
Android was not working because the status is set to 200, not 0.
-rw-r--r-- | js/push.js | 40 |
1 files changed, 27 insertions, 13 deletions
@@ -213,6 +213,8 @@ options.container = options.container || options.transition ? document.querySelector('.content') : document.body; + var isFileProtocol = /^file:/.test(window.location.protocol); + for (key in bars) { if (bars.hasOwnProperty(key)) { options[key] = options[key] || document.querySelector(bars[key]); @@ -225,21 +227,25 @@ } xhr = new XMLHttpRequest(); - xhr.open('GET', options.url, true); - xhr.setRequestHeader('X-PUSH', 'true'); + if (isFileProtocol) { + xhr.open('GET', options.url, false); + } else { + xhr.open('GET', options.url, true); + xhr.setRequestHeader('X-PUSH', 'true'); - xhr.onreadystatechange = function () { - if (options._timeout) { - clearTimeout(options._timeout); - } - if (xhr.readyState === 4) { - if (xhr.status === 200) { - success(xhr, options); - } else { - failure(options.url); + xhr.onreadystatechange = function () { + if (options._timeout) { + clearTimeout(options._timeout); } - } - }; + if (xhr.readyState === 4) { + if (xhr.status === 200) { + success(xhr, options); + } else { + failure(options.url); + } + } + }; + } if (!PUSH.id) { cacheReplace({ @@ -259,6 +265,14 @@ xhr.send(); + if (isFileProtocol) { + if (xhr.status === 0 || xhr.status === 200) { + success(xhr, options); + } else { + failure(options.url); + } + } + if (xhr.readyState && !options.ignorePush) { cachePush(); } |