📄 ext-base.js
字号:
useDefaultHeader:true,
defaultPostHeader:'application/x-www-form-urlencoded',
useDefaultXhrHeader:true,
defaultXhrHeader:'XMLHttpRequest',
hasDefaultHeaders:true,
defaultHeaders:{},
poll:{},
timeout:{},
pollInterval:50,
transactionId:0,
setProgId:function(id)
{
this.activeX.unshift(id);
},
setDefaultPostHeader:function(b)
{
this.useDefaultHeader = b;
},
setDefaultXhrHeader:function(b)
{
this.useDefaultXhrHeader = b;
},
setPollingInterval:function(i)
{
if (typeof i == 'number' && isFinite(i)) {
this.pollInterval = i;
}
},
createXhrObject:function(transactionId)
{
var obj,http;
try
{
http = new XMLHttpRequest();
obj = { conn:http, tId:transactionId };
}
catch(e)
{
for (var i = 0; i < this.activeX.length; ++i) {
try
{
http = new ActiveXObject(this.activeX[i]);
obj = { conn:http, tId:transactionId };
break;
}
catch(e) {
}
}
}
finally
{
return obj;
}
},
getConnectionObject:function()
{
var o;
var tId = this.transactionId;
try
{
o = this.createXhrObject(tId);
if (o) {
this.transactionId++;
}
}
catch(e) {
}
finally
{
return o;
}
},
asyncRequest:function(method, uri, callback, postData)
{
var o = this.getConnectionObject();
if (!o) {
return null;
}
else {
o.conn.open(method, uri, true);
if (this.useDefaultXhrHeader) {
if (!this.defaultHeaders['X-Requested-With']) {
this.initHeader('X-Requested-With', this.defaultXhrHeader, true);
}
}
if(postData && this.useDefaultHeader){
this.initHeader('Content-Type', this.defaultPostHeader);
}
if (this.hasDefaultHeaders || this.hasHeaders) {
this.setHeader(o);
}
this.handleReadyState(o, callback);
o.conn.send(postData || null);
return o;
}
},
handleReadyState:function(o, callback)
{
var oConn = this;
if (callback && callback.timeout) {
this.timeout[o.tId] = window.setTimeout(function() {
oConn.abort(o, callback, true);
}, callback.timeout);
}
this.poll[o.tId] = window.setInterval(
function() {
if (o.conn && o.conn.readyState == 4) {
window.clearInterval(oConn.poll[o.tId]);
delete oConn.poll[o.tId];
if (callback && callback.timeout) {
window.clearTimeout(oConn.timeout[o.tId]);
delete oConn.timeout[o.tId];
}
oConn.handleTransactionResponse(o, callback);
}
}
, this.pollInterval);
},
handleTransactionResponse:function(o, callback, isAbort)
{
if (!callback) {
this.releaseObject(o);
return;
}
var httpStatus, responseObject;
try
{
if (o.conn.status !== undefined && o.conn.status != 0) {
httpStatus = o.conn.status;
}
else {
httpStatus = 13030;
}
}
catch(e) {
httpStatus = 13030;
}
if (httpStatus >= 200 && httpStatus < 300) {
responseObject = this.createResponseObject(o, callback.argument);
if (callback.success) {
if (!callback.scope) {
callback.success(responseObject);
}
else {
callback.success.apply(callback.scope, [responseObject]);
}
}
}
else {
switch (httpStatus) {
case 12002:
case 12029:
case 12030:
case 12031:
case 12152:
case 13030:
responseObject = this.createExceptionObject(o.tId, callback.argument, (isAbort ? isAbort : false));
if (callback.failure) {
if (!callback.scope) {
callback.failure(responseObject);
}
else {
callback.failure.apply(callback.scope, [responseObject]);
}
}
break;
default:
responseObject = this.createResponseObject(o, callback.argument);
if (callback.failure) {
if (!callback.scope) {
callback.failure(responseObject);
}
else {
callback.failure.apply(callback.scope, [responseObject]);
}
}
}
}
this.releaseObject(o);
responseObject = null;
},
createResponseObject:function(o, callbackArg)
{
var obj = {};
var headerObj = {};
try
{
var headerStr = o.conn.getAllResponseHeaders();
var header = headerStr.split('\n');
for (var i = 0; i < header.length; i++) {
var delimitPos = header[i].indexOf(':');
if (delimitPos != -1) {
headerObj[header[i].substring(0, delimitPos)] = header[i].substring(delimitPos + 2);
}
}
}
catch(e) {
}
obj.tId = o.tId;
obj.status = o.conn.status;
obj.statusText = o.conn.statusText;
obj.getResponseHeader = headerObj;
obj.getAllResponseHeaders = headerStr;
obj.responseText = o.conn.responseText;
obj.responseXML = o.conn.responseXML;
if (typeof callbackArg !== undefined) {
obj.argument = callbackArg;
}
return obj;
},
createExceptionObject:function(tId, callbackArg, isAbort)
{
var COMM_CODE = 0;
var COMM_ERROR = 'communication failure';
var ABORT_CODE = -1;
var ABORT_ERROR = 'transaction aborted';
var obj = {};
obj.tId = tId;
if (isAbort) {
obj.status = ABORT_CODE;
obj.statusText = ABORT_ERROR;
}
else {
obj.status = COMM_CODE;
obj.statusText = COMM_ERROR;
}
if (callbackArg) {
obj.argument = callbackArg;
}
return obj;
},
initHeader:function(label, value, isDefault)
{
var headerObj = (isDefault) ? this.defaultHeaders : this.headers;
if (headerObj[label] === undefined) {
headerObj[label] = value;
}
else {
headerObj[label] = value + "," + headerObj[label];
}
if (isDefault) {
this.hasDefaultHeaders = true;
}
else {
this.hasHeaders = true;
}
},
setHeader:function(o)
{
if (this.hasDefaultHeaders) {
for (var prop in this.defaultHeaders) {
if (this.defaultHeaders.hasOwnProperty(prop)) {
o.conn.setRequestHeader(prop, this.defaultHeaders[prop]);
}
}
}
if (this.hasHeaders) {
for (var prop in this.headers) {
if (this.headers.hasOwnProperty(prop)) {
o.conn.setRequestHeader(prop, this.headers[prop]);
}
}
this.headers = {};
this.hasHeaders = false;
}
},
resetDefaultHeaders:function() {
delete this.defaultHeaders;
this.defaultHeaders = {};
this.hasDefaultHeaders = false;
},
abort:function(o, callback, isTimeout)
{
if (this.isCallInProgress(o)) {
o.conn.abort();
window.clearInterval(this.poll[o.tId]);
delete this.poll[o.tId];
if (isTimeout) {
delete this.timeout[o.tId];
}
this.handleTransactionResponse(o, callback, true);
return true;
}
else {
return false;
}
},
isCallInProgress:function(o)
{
if (o.conn) {
return o.conn.readyState != 4 && o.conn.readyState != 0;
}
else {
return false;
}
},
releaseObject:function(o)
{
o.conn = null;
o = null;
},
activeX:[
'MSXML2.XMLHTTP.3.0',
'MSXML2.XMLHTTP',
'Microsoft.XMLHTTP'
]
};
Ext.lib.Region = function(t, r, b, l) {
this.top = t;
this[1] = t;
this.right = r;
this.bottom = b;
this.left = l;
this[0] = l;
};
Ext.lib.Region.prototype = {
contains : function(region) {
return ( region.left >= this.left &&
region.right <= this.right &&
region.top >= this.top &&
region.bottom <= this.bottom );
},
getArea : function() {
return ( (this.bottom - this.top) * (this.right - this.left) );
},
intersect : function(region) {
var t = Math.max(this.top, region.top);
var r = Math.min(this.right, region.right);
var b = Math.min(this.bottom, region.bottom);
var l = Math.max(this.left, region.left);
if (b >= t && r >= l) {
return new Ext.lib.Region(t, r, b, l);
} else {
return null;
}
},
union : function(region) {
var t = Math.min(this.top, region.top);
var r = Math.max(this.right, region.right);
var b = Math.max(this.bottom, region.bottom);
var l = Math.min(this.left, region.left);
return new Ext.lib.Region(t, r, b, l);
},
constrainTo : function(r) {
this.top = this.top.constrain(r.top, r.bottom);
this.bottom = this.bottom.constrain(r.top, r.bottom);
this.left = this.left.constrain(r.left, r.right);
this.right = this.right.constrain(r.left, r.right);
return this;
},
adjust : function(t, l, b, r) {
this.top += t;
this.left += l;
this.right += r;
this.bottom += b;
return this;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -