This commit is contained in:
Namhyeon Go 2020-11-25 16:57:30 +09:00
parent cfc883aab6
commit d9dbdd8d74
2 changed files with 37 additions and 30 deletions

View File

@ -45,28 +45,32 @@ var FILE = require('lib/file');
};
}(),
ajax = function(url, callback) {
var pos = url.indexOf('://');
var scheme = (pos < 0) ? "" : url.substring(0, pos);
var pos = url.indexOf('://');
var scheme = (pos < 0) ? "" : url.substring(0, pos);
if (scheme == 'http' || scheme == 'https') {
var req = xmlHttp();
if (!req) {
return;
}
req.open("GET", url, true);
req.onreadystatechange = function() {
if (req.readyState !== 4 || req.status !== 200 && req.status !== 304) {
switch (scheme) {
case "http":
case "https":
var req = xmlHttp();
if (!req) {
return;
}
callback(req.responseText);
};
if (req.readyState === 4) {
return;
}
req.send(null);
} else {
responseText = FILE.readFile(url, "utf-8");
callback(responseText);
req.open("GET", url, true);
req.onreadystatechange = function() {
if (req.readyState !== 4 || req.status !== 200 && req.status !== 304) {
return;
}
callback(req.responseText);
};
if (req.readyState === 4) {
return;
}
req.send(null);
break;
default:
responseText = FILE.readFile(url, "utf-8");
callback(responseText);
}
};
respond.ajax = ajax;
@ -271,4 +275,4 @@ var FILE = require('lib/file');
} else if (w.attachEvent) {
w.attachEvent("onresize", callMedia);
}
})(this);
})(this);

View File

@ -389,16 +389,19 @@ var FILE = require('lib/file');
// --[ loadStyleSheet() ]-----------------------------------------------
function loadStyleSheet(url) {
var pos = url.indexOf('://');
var scheme = (pos < 0) ? "" : url.substring(0, pos);
var pos = url.indexOf('://');
var scheme = (pos < 0) ? "" : url.substring(0, pos);
if (scheme == 'http' || scheme == 'https') {
xhr.open("GET", url, false);
xhr.send();
return (xhr.status == 200) ? xhr.responseText : EMPTY_STRING;
} else {
var responseText = FILE.readFile(url, "utf-8");
return responseText;
switch (scheme) {
case "http":
case "https":
xhr.open("GET", url, false);
xhr.send();
return (xhr.status == 200) ? xhr.responseText : EMPTY_STRING;
default:
var responseText = FILE.readFile(url, "utf-8");
return responseText;
}
};
@ -576,4 +579,4 @@ var FILE = require('lib/file');
addEvent(win, "load", init);
}
};
})(this);
})(this);