Skip to content

Commit

Permalink
push.js: add file:// urls support
Browse files Browse the repository at this point in the history
  • Loading branch information
artemave committed Apr 21, 2014
1 parent dbf6f8f commit 5ccfdd7
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions js/push.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,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]);
Expand All @@ -221,17 +223,21 @@
}

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) {
xhr.status === 200 ? success(xhr, options) : failure(options.url);
}
};
xhr.onreadystatechange = function () {
if (options._timeout) {
clearTimeout(options._timeout);
}
if (xhr.readyState === 4) {
xhr.status === 200 ? success(xhr, options) : failure(options.url);
}
};
}

if (!PUSH.id) {
cacheReplace({
Expand All @@ -249,6 +255,14 @@

xhr.send();

if (isFileProtocol) {
if (xhr.status === 0) {
success(xhr, options);
} else {
failure(options.url);
}
}

if (xhr.readyState && !options.ignorePush) {
cachePush();
}
Expand Down

0 comments on commit 5ccfdd7

Please sign in to comment.