📄 core.ashx
字号:
// Extend prototypes
if(!Array.prototype.push) {
Array.prototype.push = function(o) {
this[this.length] = o;
}
}
Function.prototype.bind = function(o) {
if(!window.__objs) {
window.__objs = [];
window.__funcs = [];
}
var objId = o.__oid;
if(!objId)
__objs[objId = o.__oid = __objs.length] = o;
var me = this;
var funcId = me.__fid;
if(!funcId)
__funcs[funcId = me.__fid = __funcs.length] = me;
if(!o.__closures)
o.__closures = [];
var closure = o.__closures[funcId];
if(closure)
return closure;
o = null;
me = null;
return __objs[objId].__closures[funcId] = function() {
return __funcs[funcId].apply(__objs[objId], arguments);
};
}
Object.extend = function(destination, source) {
for(property in source) {
destination[property] = source[property];
}
return destination;
}
Object.prototype.extend = function(o) {
return Object.extend.apply(this, [this, o]);
}
var Class = {
create: function() {
return function() {
if(typeof this.initialize == "function")
this.initialize.apply(this, arguments);
}
}
}
if(!window.addNamespace) {
window.addNamespace = function(ns) {
var nsParts = ns.split(".");
var root = window;
for(var i=0; i<nsParts.length; i++) {
if(typeof root[nsParts[i]] == "undefined")
root[nsParts[i]] = {};
root = root[nsParts[i]];
}
}
}
var IFrameXmlHttp = function() {
}
IFrameXmlHttp.prototype = {
onreadystatechange: null,
headers: [],
method: "POST",
url: null,
async: true,
iframe: null,
status: 0,
readyState: 0,
responseText: null,
abort: function() {
},
readystatechanged: function() {
var doc = this.iframe.contentDocument || this.iframe.document;
if(doc.readyState == "complete")
{
this.status = 200;
this.readyState = 4;
this.responseText = doc.body.res;
this.onreadystatechange();
return;
}
setTimeout(this.readystatechanged.bind(this), 100);
},
open: function(method, url, async) {
if(async == false) {
alert("Synchronous call using IFrameXMLHttp is not supported.");
return;
}
if(this.iframe == null) {
var iframeID = "hans";
if (document.createElement && document.documentElement &&
(window.opera || navigator.userAgent.indexOf('MSIE 5.0') == -1))
{
var ifr = document.createElement('iframe');
ifr.setAttribute('id', iframeID);
ifr.style.visibility = 'hidden';
ifr.style.position = 'absolute';
ifr.style.width = ifr.style.height = ifr.borderWidth = '0px';
this.iframe = document.getElementsByTagName('body')[0].appendChild(ifr);
ifr = null;
}
else if (document.body && document.body.insertAdjacentHTML)
{
document.body.insertAdjacentHTML('beforeEnd', '<iframe name="' + iframeID + '" id="' + iframeID + '" style="border:1px solid black;xdisplay:none"></iframe>');
}
if (window.frames && window.frames[iframeID]) this.iframe = window.frames[iframeID];
this.iframe.name = iframeID;
this.iframe.document.open();
this.iframe.document.write("<html><body></body></html>");
this.iframe.document.close();
}
this.method = method;
this.url = url;
this.async = async;
},
setRequestHeader: function(name, value) {
for(var i=0; i<this.headers.length; i++) {
if(this.headers[i].name == name) {
this.headers[i].value = value;
return;
}
}
this.headers.push({"name":name,"value":value});
},
addInput: function(doc, form, name, value) {
var ele;
var tag = "input";
if(value.indexOf("\n") >= 0) tag = "textarea";
if(doc.all) {
ele = doc.createElement("<" + tag + " name=\"" + name + "\" />");
}else{
ele = doc.createElement(tag);
ele.setAttribute("name", name);
}
ele.setAttribute("value", value);
form.appendChild(ele);
ele = null;
},
send: function(data) {
if(this.iframe == null) {
// alert("Connection must be opened before sending data.");
return;
}
var doc = this.iframe.contentDocument || this.iframe.document;
var form = doc.createElement("form");
doc.body.appendChild(form);
form.setAttribute("action", this.url);
form.setAttribute("method", this.method);
for(var i=0; i<this.headers.length; i++) {
switch(this.headers[i].name.toLowerCase()) {
case "content-length":
case "accept-encoding":
break;
case "content-type":
form.setAttribute("enctype", this.headers[i].value);
break;
default:
this.addInput(doc, form, this.headers[i].name, this.headers[i].value);
}
}
this.addInput(doc, form, "data", data);
form.submit();
setTimeout(this.readystatechanged.bind(this), 1);
}
};
var lastclsid = null;
if(!window.XMLHttpRequest) {
function getXmlHttp(clsid) {
var xmlHttp = null;
try {
xmlHttp = new ActiveXObject(clsid);
lastclsid = clsid;
return xmlHttp;
} catch(ex) {}
}
window.XMLHttpRequest = function() {
if(lastclsid != null) {
return getXmlHttp(lastclsid);
}
var xmlHttp = null;
var clsids = ["Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.5.0","Msxml2.XMLHTTP.4.0","Msxml2.XMLHTTP.3.0","Msxml2.XMLHTTP.2.6","Microsoft.XMLHTTP.1.0","Microsoft.XMLHTTP.1","Microsoft.XMLHTTP"];
for(var i=0; i<clsids.length && xmlHttp == null; i++) {
xmlHttp = getXmlHttp(clsids[i]);
}
if(xmlHttp == null) {
return new IFrameXmlHttp();
}
return xmlHttp;
}
}
// Event handling methods
function addEvent(o, evType, f, capture) {
if(o.addEventListener) {
o.addEventListener(evType, f, capture);
return true;
} else if (o.attachEvent) {
var r = o.attachEvent("on" + evType, f);
return r;
} else {
// alert("Handler could not be attached");
}
}
function removeEvent(o, evType, f, capture) {
if(o.removeEventListener) {
o.removeEventListener(evType, f, capture);
return true;
} else if (o.detachEvent) {
var r = o.detachEvent("on" + evType, f);
return r;
} else {
// alert("Handler could not be removed");
}
}
// Browser related properties
addNamespace("MS.Browser");
MS.Browser.isIE = (window.navigator.appName.toLowerCase().indexOf('explorer') != -1 || window.navigator.appName.toLowerCase().indexOf('msie') != -1 );
// Debugging
addNamespace("MS.Debug");
MS.Debug.enabled = false;
MS.Debug.trace = function(s){}
// AJAX.NET
addNamespace("AjaxPro");
AjaxPro.noOperation = function() {}
AjaxPro.cryptProvider = null;
AjaxPro.token = "";
AjaxPro.version = "5.11.4.2";
AjaxPro.typeOf = function(o) {
if(o != null && o.__type) {
var ts = this.__type.split(',');
if(ts.length > 0)
return ts[0];
else
return typeof o;
} else {
return typeof o;
}
}
AjaxPro.getInstance = function(className, o) {
if(o == null) o = window;
var c = className.split(".");
if(c.length > 1)
return AjaxPro.getInstance(className.substr(className.indexOf(".") +1), o[c[0]]);
return o[className];
}
AjaxPro.toJSON = function(o) {
if(o == null)
return "null";
switch(o.constructor) {
case String:
var s = o; // .encodeURI();
s = '"' + s.replace(/(["\\])/g, '\\$1') + '"';
s = s.replace(/\n/g,"\\n");
s = s.replace(/\r/g,"\\r");
return s;
case Array:
var v = [];
for(var i=0; i<o.length; i++)
v.push(AjaxPro.toJSON(o[i])) ;
return "[" + v.join(", ") + "]";
case Number:
return isFinite(o) ? o.toString() : AjaxPro.toJSON(null);
case Boolean:
return o.toString();
case Date:
var d = new Object();
d.__type = "System.DateTime";
d.Year = o.getUTCFullYear();
d.Month = o.getUTCMonth() +1;
d.Day = o.getUTCDate();
d.Hour = o.getUTCHours();
d.Minute = o.getUTCMinutes();
d.Second = o.getUTCSeconds();
d.Millisecond = o.getUTCMilliseconds();
d.TimezoneOffset = o.getTimezoneOffset();
return AjaxPro.toJSON(d);
default:
if(o["toJSON"] != null && typeof o["toJSON"] == "function")
return o.toJSON();
if(typeof o == "object") {
var v=[];
for(attr in o) {
if(typeof o[attr] != "function")
v.push('"' + attr + '": ' + AjaxPro.toJSON(o[attr]));
}
if(v.length>0)
return "{" + v.join(", ") + "}";
else
return "{}";
}
return o.toString();
}
}
AjaxPro.Base = function() {};
AjaxPro.Request = Class.create();
AjaxPro.Request.prototype = (new AjaxPro.Base()).extend({
doStateChange: function() {
if(this.onStateChanged != null && typeof this.onStateChanged == "function")
try{ this.onStateChanged(this.xmlHttp.readyState); }catch(e){}
if(this.xmlHttp.readyState != 4)
return;
if(this.xmlHttp.status == 200) {
if(this.timeoutTimer != null) clearTimeout(this.timeoutTimer);
if(typeof this.onLoading == "function") this.onLoading(false);
this.xmlHttp.onreadystatechange = AjaxPro.noOperation;
this.callback(this.createResponse());
this.callback = null;
this.xmlHttp.abort();
}
},
initialize: function(url) {
this.url = url;
this.xmlHttp = new XMLHttpRequest();
this.callback = null;
this.onLoading = null;
this.onError = null;
this.onTimeout = null;
this.onStateChanged = null;
this.timeoutPeriod = 5000; // 5 seconds
},
createResponse: function() {
var r = new Object();
r.error = null;
r.value = null;
var responseText = new String(this.xmlHttp.responseText);
if(AjaxPro.cryptProvider != null && typeof AjaxPro.cryptProvider == "function")
responseText = AjaxPro.cryptProvider.decrypt(responseText);
eval("r.value = " + responseText + ";");
if(r.error != null && this.onError != null && typeof this.onError == "function")
try{ this.onError(r.error); }catch(e){}
responseText = null;
return r;
},
timeout: function() {
this.xmlHttp.abort();
try{ this.onTimeout(); }catch(e){}
},
invoke: function(method, data, callback) {
var async = typeof callback == "function" && callback != AjaxPro.noOperation;
var json = AjaxPro.toJSON(data) + "\r\n";
if(AjaxPro.cryptProvider != null)
json = AjaxPro.cryptProvider.encrypt(json);
this.callback = callback;
if(async) {
this.xmlHttp.onreadystatechange = this.doStateChange.bind(this);
if(typeof this.onLoading == "function") this.onLoading(true);
}
this.xmlHttp.open("POST", this.url, async);
this.xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
this.xmlHttp.setRequestHeader("Content-Length", json.length);
this.xmlHttp.setRequestHeader("Ajax-method", method);
if(AjaxPro.token != null && AjaxPro.token.length > 0)
this.xmlHttp.setRequestHeader("Ajax-token", AjaxPro.token);
if(MS.Browser.isIE)
this.xmlHttp.setRequestHeader("Accept-Encoding", "gzip, deflate");
else
this.xmlHttp.setRequestHeader("Connection", "close"); // Mozilla Bug #246651
if(this.onTimeout != null && typeof this.onTimeout == "function")
this.timeoutTimer = setTimeout(this.timeout.bind(this), this.timeoutPeriod);
this.xmlHttp.send(json);
json = null;
data = null;
delete json;
delete data;
if(!async) {
return this.createResponse();
}
return true;
}
});
addNamespace("Ajax.Web");
Ajax.Web.NameValueCollection = function()
{
this.__type = "System.Collections.Specialized.NameValueCollection";
this.add = function(key, value) {
if(this[key] == null) {
this[key] = value;
}
}
this.getKeys = function() {
var keys = [];
for(key in this)
if(typeof this[key] != "function")
keys.push(key);
return keys;
}
this.getValue = function(key) {
return this[key];
}
this.toJSON = function() {
var o = this;
o.toJSON = null;
delete o.toJSON;
return AjaxPro.toJSON(o);
}
}
addNamespace("Ajax.Web");
Ajax.Web.DataTable = function(columns, rows) {
this.__type = "System.Data.DataTable, System.Data";
this.Columns = new Array();
this.Rows = new Array();
this.addColumn = function(name, type) {
var c = new Object();
c.Name = name;
c.__type = type;
this.Columns.push(c);
}
this.toJSON = function() {
var dt = new Object();
dt.Columns = [];
for(var i=0; i<this.Columns.length; i++)
dt.Columns.push([this.Columns[i].Name, this.Columns[i].__type]);
dt.Rows = [];
for(var i=0; i<this.Rows.length; i++) {
var row = [];
for(var j=0; j<this.Columns.length; j++)
row.push(this.Rows[i][this.Columns[j].Name]);
dt.Rows.push(row);
}
return AjaxPro.toJSON(dt);
}
this.addRow = function(row) {
this.Rows.push(row);
}
if(columns != null) {
for(var i=0; i<columns.length; i++) {
this.addColumn(columns[i][0], columns[i][1]);
}
}
if(rows != null) {
for(var i=0; i<rows.length; i++) {
var row = new Object();
for(var c=0; c<this.Columns.length && c<rows[i].length; c++) {
row[this.Columns[c].Name] = rows[i][c];
}
this.addRow(row);
}
}
}
addNamespace("Ajax.Web");
Ajax.Web.DataSet = function(tables) {
this.__type = "System.Data.DataSet, System.Data";
this.Tables = new Array();
this.addTable = function(table) {
this.Tables.push(table);
}
if(tables != null) {
for(var i=0; i<tables.length; i++) {
this.addTable(tables[i]);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -