Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/ratchet.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXhmikosR <xhmikosr@gmail.com>2015-04-01 01:56:05 +0300
committerXhmikosR <xhmikosr@gmail.com>2015-04-01 01:56:05 +0300
commitecf938a3341649cc081de202f362939afd4dcb3c (patch)
tree291627150777d8fc255eb3354353e614e894b6af
parenta75529ac3ce3a0ccdfeddbd0678df42b2c05afd9 (diff)
parent1e021bc5e0681cdb7323f9ebad0759cb50e9b03f (diff)
Merge pull request #750 from ebradbury/file_protocol_push_js
push.js: add file:// urls support
-rw-r--r--js/push.js40
1 files changed, 27 insertions, 13 deletions
diff --git a/js/push.js b/js/push.js
index 9981166..96dd476 100644
--- a/js/push.js
+++ b/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();
}