📄 ext-base.js
字号:
{
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;
}
};
Ext.lib.Region.getRegion = function(el) {
var p = Ext.lib.Dom.getXY(el);
var t = p[1];
var r = p[0] + el.offsetWidth;
var b = p[1] + el.offsetHeight;
var l = p[0];
return new Ext.lib.Region(t, r, b, l);
};
Ext.lib.Point = function(x, y) {
if (Ext.isArray(x)) {
y = x[1];
x = x[0];
}
this.x = this.right = this.left = this[0] = x;
this.y = this.top = this.bottom = this[1] = y;
};
Ext.lib.Point.prototype = new Ext.lib.Region();
Ext.lib.Anim = {
scroll : function(el, args, duration, easing, cb, scope) {
return this.run(el, args, duration, easing, cb, scope, Ext.lib.Scroll);
},
motion : function(el, args, duration, easing, cb, scope) {
return this.run(el, args, duration, easing, cb, scope, Ext.lib.Motion);
},
color : function(el, args, duration, easing, cb, scope) {
return this.run(el, args, duration, easing, cb, scope, Ext.lib.ColorAnim);
},
run : function(el, args, duration, easing, cb, scope, type) {
type = type || Ext.lib.AnimBase;
if (typeof easing == "string") {
easing = Ext.lib.Easing[easing];
}
var anim = new type(el, args, duration, easing);
anim.animateX(function() {
Ext.callback(cb, scope);
});
return anim;
}
};
function fly(el) {
if (!libFlyweight) {
libFlyweight = new Ext.Element.Flyweight();
}
libFlyweight.dom = el;
return libFlyweight;
}
if(Ext.isIE) {
function fnCleanUp() {
var p = Function.prototype;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -