Browse Source

Merge pull request #750 from ebradbury/file_protocol_push_js

push.js: add file:// urls support
pull/763/head
XhmikosR 10 years ago
parent
commit
ecf938a334
  1. 40
      js/push.js

40
js/push.js

@ -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();
}

Loading…
Cancel
Save