|
From: Robert R. <rai...@us...> - 2002-04-10 18:31:06
|
Update of /cvsroot/dynapi/dynapi2x/src/ext
In directory usw-pr-cvs1:/tmp/cvs-serv19326/src/ext
Added Files:
debug.html debug.js functions.js library.html library.js
Log Message:
initial import
--- NEW FILE ---
<html>
<title>DynAPI Debugger</title>
<script>
var dynapi = window.opener.dynapi;
function handleError(msg, url, lno) {
dynapi.debug.error(msg, "Debugger", lno);
};
var win = this;
win.onload = function() {
// move the debug window to the right edge?
//dynapi.debug.win.clientWidth = 200;
//win.document.body.style.width = 200; //clientWidth=200
//alert(win.setSize)
//alert(win.document.body.clientWidth)
var w = dynapi.ua.mac? (dynapi.ua.ie?330:300) : 360;
if (dynapi.ua.ie) {
var f = dynapi.frame;
var b = f.document.body;
var x = Math.min(f.screenLeft+b.clientWidth+20,screen.width-w-10);
dynapi.debug.win.moveTo(x,f.screenTop-50);
}
else if (dynapi.ua.ns4) {
var f = dynapi.frame;
dynapi.debug.win.moveTo(f.screenX+f.outerWidth,f.screenY);
}
dynapi.debug.print();
}
if (!dynapi.ua.ns6) self.onerror = handleError;
</script>
<style type="text/css">
</style>
<body bgcolor="#D4D0C8" leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0" scrolling=no style="overflow:hidden">
<script>
var stat = 'DynAPI '+dynapi.version+' ['+dynapi.ua.b+' '+dynapi.ua.v+']';
var str='<form name=debugform><font face="'+(dynapi.ua.mac?'Monaco':'Courier')+'" size="1">'+
'<table cellspacing=0 cellpadding=0 border=0><tr><td colspan=2>'+
'<textarea name="print" cols="'+(dynapi.ua.mac? (dynapi.ua.ie?42:42) :40)+'" rows="'+(dynapi.ua.ie?12:13)+'" wrap="off"></textarea><br>'+
'<input type=text name="stat" size="'+(dynapi.ua.mac? (dynapi.ua.ie?44:46) :42)+'" style="font-family:'+(dynapi.ua.mac?'Monaco':'Courier')+';" value="'+stat+'"><br>'+
'<textarea name="eval" cols="'+(dynapi.ua.mac? (dynapi.ua.ie?42:42) :40)+'" rows="'+(dynapi.ua.ie?7:8)+'" wrap="off"></textarea><br>'+
'</td></tr><tr>'+
'<td><input type=button value="Evaluate" onclick="window.opener.DynAPI.debug.evaluate(this.form.eval.value)"></td>'+
'<td align=right><input type="button" value="Clear" onclick="{this.form.print.value=\'\'; this.form.stat.value=\'\'; this.form.eval.value=\'\';}"></td></tr></table>'+
'</font></form>';
document.open();
document.write(str);
document.close();
</script>
</body>
</html>
--- NEW FILE ---
/*
DynAPI Distribution
Debugger
The DynAPI Distribution is distributed under the terms of the GNU LGPL license.
*/
function Debugger() {
this.inherit('DynObject');
this.win = null;
this._buffer = dynapi._debugBuffer;
dynapi._debugBuffer = null;
// close the debug window on unload
this.closeOnUnLoad = false;
dynapi.onUnload(function() {
if (dynapi.debug.closeOnUnLoad) dynapi.debug.close();
});
this.open();
}
dynapi.setPrototype('Debugger','DynObject');
Debugger.prototype.isLoaded = function() {
return (this.win!=null && typeof(this.win.document.debugform)=="object");
};
Debugger.prototype.status = function(str) {
if (this.isLoaded()) {
for (var i=1;i<arguments.length;i++) {
str += ', '+arguments[i];
}
this.win.document.debugform.stat.value = str;
};
};
// lists all known properties of an object
Debugger.prototype.inspect = function(obj,showFunctions) {
this.print('Inspecting:');
var v;
if (typeof(obj)=='object') {
for (var i in obj) {
if (typeof(obj[i])=='undefined') v = "null";
else if (typeof(obj[i])=='function') {
if (showFunctions==false) continue;
else v = '[Function]';
}
else if (typeof(obj[i])=='object' && typeof(obj[i].length)!='undefined') v = 'Array ['+obj[i]+']';
else if (typeof(obj[i])=='object') v = '[Object]';
else v = obj[i];
this.print(' '+i+' = '+v);
}
}
else this.print(' undefined');
};
// output text to the debug window
Debugger.prototype.print = function(s) {
if (!s) s = '';
else s = s + '\n';
if (this.isLoaded()) {
if (this._buffer != '') { // dump buffer
s = this._buffer + s;
this._buffer = '';
}
this.win.document.debugform.print.value += s;
// Does mozilla has something like this?
if (dynapi.ua.ie) {
var po = this.win.document.debugform.print;
po.scrollTop = po.scrollHeight;
var range = po.createTextRange();
range.collapse(false);
range.select();
}
}
else this._buffer += s;
};
// output a browser generated error to the debug window
Debugger.prototype.error = function(msg, url, lno) {
if (url && url.indexOf(dynapi.documentPath)==0) {
url = url.substring(dynapi.documentPath.length);
}
this.print('Error:'+ (lno? ' Line '+lno : '') +' ['+url+']\n '+msg);
};
// evaluates an expression in the scope of the main dynapi window
Debugger.prototype.evaluate = function(str) {
dynapi.frame.eval(str);
};
// enters text to the evaluate field in the debugger widnow
Debugger.prototype.setEvaluate = function(str) {
if (this.isLoaded()) this.win.document.debugform.eval.value = str
};
// opens the debugger window
Debugger.prototype.open = function() {
var p = dynapi.library.path;
if (!this.isLoaded() && p) {
var url = dynapi.documentPath+p+'ext/debug.html#';
var w = dynapi.ua.mac? (dynapi.ua.ie?330:300) : 350;
var h = dynapi.ua.mac? (dynapi.ua.ie?405:365) : dynapi.ua.ie? 420:465;
this.win = window.open(url,'debugwin','width='+w+',height='+h+',scrollbars=no,status=no,toolbar=no'); //,resizable=no
this.win.focus();
this.print();
dynapi.frame.onerror = function(msg, url, lno) {
dynapi.debug.error(msg, url, lno);
};
}
};
Debugger.prototype.close = function() {
if (this.isLoaded()) {
this.win.close();
this.win = null;
}
};
dynapi.debug = new Debugger();
--- NEW FILE ---
/*
DynAPI Distribution
dynapi.functions extension
The DynAPI Distribution is distributed under the terms of the GNU LGPL license.
*/
dynapi.functions.DecToHex = function(val){
lo=val%16;
val-=lo;
lo+=48;
if (lo>57) lo+=7;
hi=val/16;
hi+=48;
if (hi>57) hi+=7;
return String.fromCharCode(hi,lo);
};
dynapi.functions.getColor = function(r,g,b) {
return '#'+dynapi.functions.DecToHex(r)+dynapi.functions.DecToHex(g)+dynapi.functions.DecToHex(b);
};
dynapi.functions.getRandomColor = function() {
var s = '';
for (var i=0;i<3;i++) s += dynapi.functions.DecToHex(Math.floor(255*Math.random()));
return s;
};
dynapi.functions.createRedPal = function(pal) {
var r=g=b=0;
for (var i=0; i<256; i++){
pal[i]=dynapi.functions.getColor(r,g,b);
r+=8;
if (r>255) { r=255; g+=6; b+=2; }
if (g>255) { g=255; b+=2; }
if (b>255) { b=255; }
}
};
dynapi.functions.createGrayPal = function(pal) {
var r=0;
for (var i=0; i<256; i++){
pal[i]=dynapi.functions.getColor(r,r,r);
r+=4;
if (r>255) { r=255; }
}
};
dynapi.functions.createBluePal = function(pal){
var r=g=b=0;
for (var i=0; i<256; i++){
pal[i]=dynapi.functions.getColor(r,g,b);
b+=6;
if (b>255) { b=255; g+=2; }
if (g>255) { g=255; r+=2; }
}
};
dynapi.functions.createGreenPal = function(pal) {
var r=g=b=0;
for (var i=0; i<256; i++){
pal[i]=dynapi.functions.getColor(r,g,b);
g+=6;
if (g>255) { g=255; b+=2; }
if (b>255) { b=255; r+=2; }
}
};
dynapi.functions.radianToDegree = function(radian) {
return radian*180/Math.PI
};
dynapi.functions.degreeToRadian = function(degree) {
return degree*Math.PI/180
};
dynapi.functions.sintable = function(lsin) {
for (var i=0; i<361; i+=1) lsin[i]=Math.sin((i/180)*Math.PI);
};
dynapi.functions.costable = function(lcos) {
for (var i=0; i<361; i+=1) lcos[i]=Math.cos((i/180)*Math.PI);
};
--- NEW FILE ---
<script>
dynapi.library._handleLoad(this);
</script>
--- NEW FILE ---
/*
DynAPI Distribution
Dynamic Loading extension to dynapi.library
The DynAPI Distribution is distributed under the terms of the GNU LGPL license.
*/
// begin loading the object
DynAPILibrary.prototype.load = function(n,fn) {
var list = this._queue(n,null,arguments[2]);
//return dynapi.debug.print('going to load: '+list);
if (list.length) {
var s,src;
for (var i=0;i<list.length;i++) {
src = list[i];
s = this.scripts[list[i]];
if (i==list.length-1 && fn!=null) s.fn = fn;
this.loadList[this.loadList.length] = src;
}
this._load();
}
else if (fn) fn();
};
// reload the object
DynAPILibrary.prototype.reload = function(n,fn,force) {
var s = this.objects[n];
if (s) {
s.loaded = false;
this.load(n,fn,force);
}
};
// load a script that is not added to the library
DynAPILibrary.prototype.loadScript = function(src,fn) {
if (!this.scripts[src]) {
var n = 'unnamed'+this._c++;
s = this.add(n,src); // generate a name for the script
s.unnamed = true;
s.fn = null;
s.dep = [];
this.load(n,fn);
}
};
// inserts the script element into the page
DynAPILibrary.prototype._load = function() {
if (this.busy) return; // dynapi.debug.print('Library Warning: busy');
else {
if (this.loadIndex<this.loadList.length-1) {
this.busy = true;
this.loadIndex++;
var src = this.loadList[this.loadIndex];
//if (!confirm('load: '+src+' ?')) return;
var rsrc = src + '?'+Math.random(); // random ensures cached files are not loaded
var s = this.scripts[src];
if (dynapi.ua.ns4) {
// delete the constructors
for (var j=0;j<s.objects.length;j++) {
var n = s.objects[j];
if (dynapi.frame[n]) {
dynapi.frame[n] = null;
if (s.pkg) dynapi.frame[s.pkg+'.'+n] = null;
}
}
this.elm.src = dynapi._path+'ext/library.html?js='+src;
}
else if (dynapi.ua.ie && (dynapi.ua.v==4 || dynapi.ua.mac)) {
dynapi.frame.document.body.insertAdjacentHTML('beforeEnd','<script language="javascript" src="'+rsrc+'" defer><\/script>');
this._export(src);
}
else {
var elm = s.elm = dynapi.frame.document.createElement('script');
elm.src = rsrc;
elm.type = 'text/javascript';
elm.defer = true;
if (dynapi.ua.ie) {
elm.C = 0;
var o = this;
elm.onreadystatechange = function() {
elm.C++;
if (elm.C==2 || elm.readyState=="complete") { // use 2nd statechange for onload
o._export(src);
}
}
}
dynapi.frame.document.getElementsByTagName('head')[0].appendChild(elm);
// I could not find way to know when the script is complete in Moz v0.9.3
if (dynapi.ua.ns6) setTimeout(this+'._export("'+src+'")',100);
}
}
}
};
// executed after a script is finished loading, run main() functions
DynAPILibrary.prototype._export = function(src) {
var src = this.loadList[this.loadIndex];
var s = this.scripts[src];
if (s) {
this._register(s);
// run elm.main)() before global main()
if (dynapi.ua.ns4 && typeof(this.elm.main)=="function") {
this.elm.main();
this.elm.main = null;
}
// run global main() if available
if (typeof(main)=="function") {
main();
main = null;
}
// clear out all functions in the layer's scope
if (dynapi.ua.ns4) {
for (var i in this.elm) {
if (typeof(this.elm[i])=="function") delete this.elm[i];
}
}
this.busy = false;
// load next file
this._load();
}
//else return alert('Library Error: unknown script '+src);
};
// registers the script as loaded, exports the objects
DynAPILibrary.prototype._register = function(s) {
//dynapi.debug.print('loaded "'+s.src+'"');
s.loaded = true;
s.queued = false;
if (!s.unnamed) {
var n,found;
// loop through each object that the script contains
for (var i=0;i<s.objects.length;i++) {
found = false;
n = s.objects[i];
// scope local objects in the layer to the DynAPI frame
if (dynapi.ua.ns4 && this.elm && typeof(this.elm[n])!="undefined") {
dynapi.frame[n] = this.elm[n];
found = true;
}
else if (typeof(dynapi.frame[n])!="undefined") found = true;
else if (n.indexOf('.')>0) {
var ns = n.split('.'), o = dynapi.frame, b = false;
for (var j=0;j<ns.length;j++) {
o = o[ns[j]];
}
if (typeof(o)!="undefined") found = true;
}
else if (typeof(dynapi[n])!="undefined") found = true;
if (found) {
if (s.pkg) {
// make package link: dynapi.api.DynLayer = DynLayer
if (s.pkg!="dynapi") this.packages[s.pkg][n] = dynapi.frame[n];
n = s.pkg+'.'+n;
}
dynapi.debug.print('loaded ['+n+']');
}
else {
dynapi.debug.print('Library Error: could not find ['+n+']');
}
}
}
// run handler if available
if (s.fn) {
s.fn();
delete s.fn;
}
};
// called from /lib/dynapi/library.html to write the <script>, NS4 only
DynAPILibrary.prototype._handleLoad = function(elm) {
var args = dynapi.functions.getURLArguments(elm.src);
var js = args["js"];
if (js) {
if (js.indexOf('http')!=0) {
var l = dynapi.frame.document.location;
if (js.substr(0,1)=='/') js = l.port+'//'+host+src;
else js = dynapi.documentPath+js;
}
elm.document.write('<script language="JavaScript" src="'+js+'?r'+Math.random()+'"><\/script>');
elm.document.close();
elm.onload = function() {
dynapi.library._export(js);
}
}
};
// inserts the layer for NS4, register included scripts
DynAPILibrary.prototype._create = function() {
// ensure a previous main function is wiped out
if (typeof(main)=="function") main = null;
// register objects from scripts included by dynapi.library.include() or manually
var s;
for (var i in this.scripts) {
s = this.scripts[i];
if (s.loaded || (s.objects[0] && dynapi.frame[s.objects[0]])) this._register(s);
}
// create NS4 layer to load scripts into
if (dynapi.ua.ns4) this.elm = new Layer(0, dynapi.frame);
this.busy = false;
// load any scripts before proceeding
if (this.loadList.length) {
var s = this.scripts[this.loadList[this.loadList.length-1]];
s.fn = function() {
setTimeout('dynapi._onLoad()',1);
}
this._load();
}
else setTimeout('dynapi._onLoad()',1);
};
|