?? engine.js
字號:
/**
* @private This method is called by Javascript that is emitted by server
*/
DWREngine._handleServerError = function(id, error) {
// Clear this callback out of the list - we don't need it any more
var handlers = DWREngine._handlersMap[id];
DWREngine._handlersMap[id] = null;
if (error.message) {
DWREngine._handleMetaDataError(handlers, error.message, error);
}
else {
DWREngine._handleMetaDataError(handlers, error);
}
};
/**
* @private This is a hack to make the context be this window
*/
DWREngine._eval = function(script) {
return eval(script);
}
/**
* @private Called as a result of a request timeout
*/
DWREngine._abortRequest = function(batch) {
if (batch && batch.metadata != null && !batch.completed) {
DWREngine._clearUp(batch);
if (batch.req) batch.req.abort();
// Call all the timeout errorHandlers
var handlers;
var id;
for (var i = 0; i < batch.ids.length; i++) {
id = batch.ids[i];
handlers = DWREngine._handlersMap[id];
DWREngine._handleMetaDataError(handlers, "Timeout");
}
}
};
/**
* @private A call has finished by whatever means and we need to shut it all down.
*/
DWREngine._clearUp = function(batch) {
if (batch.completed) {
DWREngine._handleWarning("double complete");
return;
}
// Irame tidyup
if (batch.div) batch.div.parentNode.removeChild(batch.div);
if (batch.iframe) {
// If this is a poll frame then stop comet polling
if (batch.iframe == DWREngine._pollFrame) DWREngine._pollFrame = null;
batch.iframe.parentNode.removeChild(batch.iframe);
}
if (batch.form) batch.form.parentNode.removeChild(batch.form);
// XHR tidyup: avoid IE handles increase
if (batch.req) {
// If this is a poll frame then stop comet polling
if (batch.req == DWREngine._pollReq) DWREngine._pollReq = null;
delete batch.req;
}
for (var i = 0; i < batch.postHooks.length; i++) {
batch.postHooks[i]();
}
batch.postHooks = null;
// TODO: There must be a better way???
for (var i = 0; i < DWREngine._batches.length; i++) {
if (DWREngine._batches[i] == batch) {
DWREngine._batches.splice(i, 1);
break;
}
}
batch.completed = true;
};
/**
* @private Generic error handling routing to save having null checks everywhere.
*/
DWREngine._handleError = function(reason, ex) {
if (DWREngine._errorHandler) {
DWREngine._errorHandler(reason, ex);
}
};
/**
* @private Generic error handling routing to save having null checks everywhere.
*/
DWREngine._handleWarning = function(reason, ex) {
if (DWREngine._warningHandler) {
DWREngine._warningHandler(reason, ex);
}
};
/**
* @private Generic error handling routing to save having null checks everywhere.
*/
DWREngine._handleMetaDataError = function(handlers, reason, ex) {
if (handlers && typeof handlers.errorHandler == "function") {
handlers.errorHandler(reason, ex);
}
else {
DWREngine._handleError(reason, ex);
}
};
/**
* @private Marshall a data item
* @param batch A map of variables to how they have been marshalled
* @param referto An array of already marshalled variables to prevent recurrsion
* @param data The data to be marshalled
* @param name The name of the data being marshalled
*/
DWREngine._serializeAll = function(batch, referto, data, name) {
if (data == null) {
batch.map[name] = "null:null";
return;
}
switch (typeof data) {
case "boolean":
batch.map[name] = "boolean:" + data;
break;
case "number":
batch.map[name] = "number:" + data;
break;
case "string":
batch.map[name] = "string:" + encodeURIComponent(data);
break;
case "object":
if (data instanceof String) {
batch.map[name] = "String:" + encodeURIComponent(data);
}
else if (data instanceof Boolean) {
batch.map[name] = "Boolean:" + data;
}
else if (data instanceof Number) {
batch.map[name] = "Number:" + data;
}
else if (data instanceof Date) {
batch.map[name] = "Date:" + data.getTime();
}
else if (data instanceof Array) {
batch.map[name] = DWREngine._serializeArray(batch, referto, data, name);
}
else {
batch.map[name] = DWREngine._serializeObject(batch, referto, data, name);
}
break;
case "function":
// We just ignore functions.
break;
default:
if (DWREngine._warningHandler) {
DWREngine._warningHandler("Unexpected type: " + typeof data + ", attempting default converter.");
}
batch.map[name] = "default:" + data;
break;
}
};
/** @private Have we already converted this object? */
DWREngine._lookup = function(referto, data, name) {
var lookup;
// Can't use a map: http://getahead.ltd.uk/ajax/javascript-gotchas
for (var i = 0; i < referto.length; i++) {
if (referto[i].data == data) {
lookup = referto[i];
break;
}
}
if (lookup) {
return "reference:" + lookup.name;
}
referto.push({ data:data, name:name });
return null;
};
/** @private Marshall an object */
DWREngine._serializeObject = function(batch, referto, data, name) {
var ref = DWREngine._lookup(referto, data, name);
if (ref) return ref;
// This check for an HTML is not complete, but is there a better way.
// Maybe we should add: data.hasChildNodes typeof "function" == true
if (data.nodeName && data.nodeType) {
return DWREngine._serializeXml(batch, referto, data, name);
}
// treat objects as an associative arrays
var reply = "Object:{";
var element;
for (element in data) {
if (element != "dwrSerialize") {
batch.paramCount++;
var childName = "c" + DWREngine._batch.map.callCount + "-e" + batch.paramCount;
DWREngine._serializeAll(batch, referto, data[element], childName);
reply += encodeURIComponent(element);
reply += ":reference:";
reply += childName;
reply += ", ";
}
}
if (reply.substring(reply.length - 2) == ", ") {
reply = reply.substring(0, reply.length - 2);
}
reply += "}";
return reply;
};
/** @private Marshall an object */
DWREngine._serializeXml = function(batch, referto, data, name) {
var ref = DWREngine._lookup(referto, data, name);
if (ref) return ref;
var output;
if (window.XMLSerializer) {
var serializer = new XMLSerializer();
output = serializer.serializeToString(data);
}
else {
output = data.toXml;
}
return "XML:" + encodeURIComponent(output);
};
/** @private Marshall an array */
DWREngine._serializeArray = function(batch, referto, data, name) {
var ref = DWREngine._lookup(referto, data, name);
if (ref) return ref;
var reply = "Array:[";
for (var i = 0; i < data.length; i++) {
if (i != 0) {
reply += ",";
}
batch.paramCount++;
var childName = "c" + DWREngine._batch.map.callCount + "-e" + batch.paramCount;
DWREngine._serializeAll(batch, referto, data[i], childName);
reply += "reference:";
reply += childName;
}
reply += "]";
return reply;
};
/** @private Convert an XML string into a DOM object. */
DWREngine._unserializeDocument = function(xml) {
var dom;
if (window.DOMParser) {
var parser = new DOMParser();
dom = parser.parseFromString(xml, "text/xml");
if (!dom.documentElement || dom.documentElement.tagName == "parsererror") {
var message = dom.documentElement.firstChild.data;
message += "\n" + dom.documentElement.firstChild.nextSibling.firstChild.data;
throw message;
}
return dom;
}
else if (window.ActiveXObject) {
dom = DWREngine._newActiveXObject(DWREngine._DOMDocument);
dom.loadXML(xml);
// What happens on parse fail with IE?
return dom;
}
else {
var div = document.createElement('div');
div.innerHTML = xml;
return div;
}
};
/**
* @private Helper to find an ActiveX object that works.
* @param axarray An array of strings to attempt to create ActiveX objects from
*/
DWREngine._newActiveXObject = function(axarray) {
var returnValue;
for (var i = 0; i < axarray.length; i++) {
try {
returnValue = new ActiveXObject(axarray[i]);
break;
}
catch (ex) {
}
}
return returnValue;
};
/** @private To make up for the lack of encodeURIComponent() on IE5.0 */
if (typeof window.encodeURIComponent === 'undefined') {
DWREngine._utf8 = function(wide) {
wide = "" + wide; // Make sure it is a string
var c;
var s;
var enc = "";
var i = 0;
while (i < wide.length) {
c = wide.charCodeAt(i++);
// handle UTF-16 surrogates
if (c >= 0xDC00 && c < 0xE000) continue;
if (c >= 0xD800 && c < 0xDC00) {
if (i >= wide.length) continue;
s = wide.charCodeAt(i++);
if (s < 0xDC00 || c >= 0xDE00) continue;
c = ((c - 0xD800) << 10) + (s - 0xDC00) + 0x10000;
}
// output value
if (c < 0x80) {
enc += String.fromCharCode(c);
}
else if (c < 0x800) {
enc += String.fromCharCode(0xC0 + (c >> 6), 0x80 + (c & 0x3F));
}
else if (c < 0x10000) {
enc += String.fromCharCode(0xE0 + (c >> 12), 0x80 + (c >> 6 & 0x3F), 0x80 + (c & 0x3F));
}
else {
enc += String.fromCharCode(0xF0 + (c >> 18), 0x80 + (c >> 12 & 0x3F), 0x80 + (c >> 6 & 0x3F), 0x80 + (c & 0x3F));
}
}
return enc;
}
DWREngine._hexchars = "0123456789ABCDEF";
DWREngine._toHex = function(n) {
return DWREngine._hexchars.charAt(n >> 4) + DWREngine._hexchars.charAt(n & 0xF);
}
DWREngine._okURIchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";
window.encodeURIComponent = function(s) {
s = DWREngine._utf8(s);
var c;
var enc = "";
for (var i= 0; i<s.length; i++) {
if (DWREngine._okURIchars.indexOf(s.charAt(i)) == -1) {
enc += "%" + DWREngine._toHex(s.charCodeAt(i));
}
else {
enc += s.charAt(i);
}
}
return enc;
}
}
/** @private To make up for the lack of Array.splice() on IE5.0 */
if (typeof Array.prototype.splice === 'undefined') {
Array.prototype.splice = function(ind, cnt)
{
if (arguments.length == 0) return ind;
if (typeof ind != "number") ind = 0;
if (ind < 0) ind = Math.max(0,this.length + ind);
if (ind > this.length) {
if (arguments.length > 2) ind = this.length;
else return [];
}
if (arguments.length < 2) cnt = this.length-ind;
cnt = (typeof cnt == "number") ? Math.max(0, cnt) : 0;
removeArray = this.slice(ind, ind + cnt);
endArray = this.slice(ind + cnt);
this.length = ind;
for (var i = 2; i < arguments.length; i++) {
this[this.length] = arguments[i];
}
for (i = 0; i < endArray.length; i++) {
this[this.length] = endArray[i];
}
return removeArray;
}
}
/** @private To make up for the lack of Array.shift() on IE5.0 */
if (typeof Array.prototype.shift === 'undefined') {
Array.prototype.shift = function(str) {
var val = this[0];
for (var i = 1; i < this.length; ++i) {
this[i - 1] = this[i];
}
this.length--;
return val;
}
}
/** @private To make up for the lack of Array.unshift() on IE5.0 */
if (typeof Array.prototype.unshift === 'undefined') {
Array.prototype.unshift = function() {
var i = unshift.arguments.length;
for (var j = this.length - 1; j >= 0; --j) {
this[j + i] = this[j];
}
for (j = 0; j < i; ++j) {
this[j] = unshift.arguments[j];
}
}
}
/** @private To make up for the lack of Array.push() on IE5.0 */
if (typeof Array.prototype.push === 'undefined') {
Array.prototype.push = function() {
var sub = this.length;
for (var i = 0; i < push.arguments.length; ++i) {
this[sub] = push.arguments[i];
sub++;
}
}
}
/** @private To make up for the lack of Array.pop() on IE5.0 */
if (typeof Array.prototype.pop === 'undefined') {
Array.prototype.pop = function() {
var lastElement = this[this.length - 1];
this.length--;
return lastElement;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -