2010-04-13 15:28:53 +01:00
|
|
|
if ((!window.console) || (! /__debug__$/i.test(document.location.href))) {
|
2010-05-05 21:40:05 +01:00
|
|
|
// non-debug mode, an empty function
|
2010-04-13 15:28:53 +01:00
|
|
|
window.console = window.console || {};
|
|
|
|
window.console.log = function(message) {};
|
2010-04-19 00:43:03 +01:00
|
|
|
window.console.warn = function(message) {};
|
|
|
|
window.console.error = function(message) {};
|
2010-04-13 15:28:53 +01:00
|
|
|
}
|
|
|
|
|
2010-04-18 22:28:54 +01:00
|
|
|
function dirObj(obj, depth, parent) {
|
2010-04-13 15:28:53 +01:00
|
|
|
var msg = "";
|
|
|
|
var val = "";
|
|
|
|
if (! depth) { depth=2; }
|
|
|
|
if (! parent) { parent= ""; }
|
|
|
|
|
|
|
|
// Print the properties of the passed-in object
|
|
|
|
for (var i in obj) {
|
|
|
|
if ((depth > 1) && (typeof obj[i] == "object")) {
|
|
|
|
// Recurse attributes that are objects
|
2010-04-18 22:28:54 +01:00
|
|
|
msg += dirObj(obj[i], depth-1, parent + "." + i);
|
2010-04-13 15:28:53 +01:00
|
|
|
} else {
|
|
|
|
val = new String(obj[i]).replace("\n", " ");
|
|
|
|
if (val.length > 30) {
|
|
|
|
val = val.substr(0,30) + "...";
|
|
|
|
}
|
|
|
|
msg += parent + "." + i + ": " + val + "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return msg;
|
|
|
|
}
|
2010-05-15 20:55:33 +01:00
|
|
|
|
2010-06-15 17:10:18 +01:00
|
|
|
/*
|
|
|
|
* Cross-browser positioning
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Get DOM element position on page
|
|
|
|
function getPosition(obj) {
|
|
|
|
var x = 0, y = 0;
|
|
|
|
if (obj.offsetParent) {
|
|
|
|
do {
|
|
|
|
x += obj.offsetLeft;
|
|
|
|
y += obj.offsetTop;
|
|
|
|
} while (obj = obj.offsetParent);
|
|
|
|
}
|
|
|
|
return {'x': x, 'y': y};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get mouse event position in DOM element
|
|
|
|
function getEventPosition(e, obj) {
|
|
|
|
var evt, docX, docY, pos;
|
|
|
|
//if (!e) evt = window.event;
|
|
|
|
evt = e.event || window.event;
|
|
|
|
if (evt.pageX || evt.pageY) {
|
|
|
|
docX = evt.pageX;
|
|
|
|
docY = evt.pageY;
|
|
|
|
} else if (evt.clientX || evt.clientY) {
|
|
|
|
docX = evt.clientX + document.body.scrollLeft +
|
|
|
|
document.documentElement.scrollLeft;
|
|
|
|
docY = evt.clientY + document.body.scrollTop +
|
|
|
|
document.documentElement.scrollTop;
|
|
|
|
}
|
|
|
|
pos = getPosition(obj);
|
|
|
|
return {'x': docX - pos.x, 'y': docY - pos.y};
|
|
|
|
}
|
|
|
|
|
2010-05-15 20:55:33 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Make arrays quack
|
|
|
|
*/
|
|
|
|
|
|
|
|
Array.prototype.shift8 = function () {
|
|
|
|
return this.shift();
|
|
|
|
};
|
|
|
|
Array.prototype.push8 = function (num) {
|
|
|
|
this.push(num & 0xFF);
|
|
|
|
};
|
|
|
|
|
|
|
|
Array.prototype.shift16 = function () {
|
|
|
|
return (this.shift() << 8) +
|
|
|
|
(this.shift() );
|
|
|
|
};
|
|
|
|
Array.prototype.push16 = function (num) {
|
|
|
|
this.push((num >> 8) & 0xFF,
|
|
|
|
(num ) & 0xFF );
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Array.prototype.shift32 = function () {
|
|
|
|
return (this.shift() << 24) +
|
|
|
|
(this.shift() << 16) +
|
|
|
|
(this.shift() << 8) +
|
|
|
|
(this.shift() );
|
|
|
|
};
|
|
|
|
Array.prototype.get32 = function (off) {
|
|
|
|
return (this[off ] << 24) +
|
|
|
|
(this[off + 1] << 16) +
|
|
|
|
(this[off + 2] << 8) +
|
|
|
|
(this[off + 3] );
|
|
|
|
};
|
|
|
|
Array.prototype.push32 = function (num) {
|
|
|
|
this.push((num >> 24) & 0xFF,
|
|
|
|
(num >> 16) & 0xFF,
|
|
|
|
(num >> 8) & 0xFF,
|
|
|
|
(num ) & 0xFF );
|
|
|
|
};
|
|
|
|
|
|
|
|
Array.prototype.shiftStr = function (len) {
|
|
|
|
var arr = this.splice(0, len);
|
|
|
|
return arr.map(function (num) {
|
|
|
|
return String.fromCharCode(num); } ).join('');
|
|
|
|
};
|
|
|
|
Array.prototype.pushStr = function (str) {
|
|
|
|
var i, n = str.length;
|
|
|
|
for (i=0; i < n; i++) {
|
|
|
|
this.push(str.charCodeAt(i));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Array.prototype.shiftBytes = function (len) {
|
|
|
|
return this.splice(0, len);
|
|
|
|
};
|
|
|
|
|