📄 textloader.js
字号:
// Description: js.io.TextLoader 文本资源加载器,实现客户端的高速缓存
// Author: Changhua.Wan
// Version: 2004.03.06.01
_package("js.lang");
_import("js.lang.Object");
_import("js.net.Encoder");
function js.io.TextLoader() {
var cache = new function() {
var _dict = new ActiveXObject("Scripting.Dictionary");
this.get = function(_name) {
if (!_dict.Exists(_name))
return null;
else
return _dict.Item(_name);
};
this.put = function(_name, _value) {
if (_dict.Exists(_name)) _dict.Item(_name) = _value;
else _dict.Add(_name, _value);
};
this.remove = function(_name) {
if (_dict.Exists(_name)) _dict.Remove(_name);
};
};
this.load = function(_respath, _reload) {
try {
if (typeof(_reload) != "boolean") _reload = false;
var _resname = _respath;
var _res = null;
if (_reload == true || null == (_res = cache.get(_resname))) {
_res = this.loadResourceFromServer(_respath);
if (_res != null)cache.put(_resname, _res);
}
return _res;
} catch(ex) {
_throw(ex);
}
};
this.loadResourceFromServer = function(_respath) {
var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.open("GET", _respath, false);
xmlHttp.send();
if (xmlHttp.status == 200 || xmlHttp.status == 0) {
// 如果编码类型是 ASCII ,且含有中文必须进行编码
// 如果编码类型是 UNICODE,UTF-8 直接 return(xmlHttp.responseText) 即可
var _charset = js.net.Encoder.getCharset(xmlHttp.responseBody);
if (_charset == "ASCII")
return js.net.Encoder.ascToStr(xmlHttp.responseBody);
else
return xmlHttp.responseText;
} else {
_throw(0x0F04, "js.io.TextLoader/loadResourceFromServer():不能加载 "
+ _respath
+ " 资源 {HTTP-STATUS:"
+ xmlHttp.status
+"}"
);
return null;
}
};
}
var _p = js.io.TextLoader._extends("js.lang.Object");
var _c = js.io.TextLoader;
_c.defaultInstance = null;
_c.getInstance = function() {
var _c = js.io.TextLoader;
if (_c.defaultInstance == null) {
_c.defaultInstance = new js.io.TextLoader();
}
return _c.defaultInstance;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -