[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 /* 2 DynAPI Distribution 3 Debugger 4 The DynAPI Distribution is distributed under the terms of the GNU LGPL license. 5 */ 6 // Note: Debugger does not have to be a DynObject - very important for blueprinted layers 7 function Debugger() { 8 this._mode='normal'; 9 this.win = null; 10 this._watch={}; 11 this._evalBuffer=''; 12 this._buffer = dynapi._debugBuffer; 13 dynapi._debugBuffer = ''; 14 // close the debug window on unload 15 this.closeOnUnLoad = false; 16 dynapi.onUnload(function() { 17 if (dynapi.debug.closeOnUnLoad) dynapi.debug.close(); 18 }); 19 this.open(); 20 } 21 var p = Debugger.prototype; //dynapi.setPrototype('Debugger','DynObject'); 22 p.close = function() { 23 if (this.isLoaded()) { 24 this.win.close(); 25 this.win = null; 26 } 27 }; 28 // error - output a browser generated error to the debug window 29 p.error = function(msg, url, lno) { 30 if (url && url.indexOf(dynapi.documentPath)==0) { 31 url = url.substring(dynapi.documentPath.length); 32 } 33 this.print('Error:'+ (lno? ' Line '+lno : '') +' ['+url+']\n '+msg); 34 }; 35 // evaluates an expression in the scope of the main dynapi window 36 p.evaluate = function(str) { 37 dynapi.frame.eval(str); 38 this.setEvalHistory(str); 39 }; 40 // get evaluation history 41 p.getEvalHistory=function(n){ 42 if(!this.isLoaded()) return; 43 var t,f=this.win.document.debugform; 44 if(n>=1) { 45 var lim=this.win.evalHistory.length-1; 46 this.win.evalIndex++; 47 if (this.win.evalIndex>lim) this.win.evalIndex=(lim<0)?0:lim; 48 t=this.win.evalHistory[this.win.evalIndex]; 49 if(t)f.eval.value=t; 50 }else if(n<=0){ 51 this.win.evalIndex--; 52 if(this.win.evalIndex<0) this.win.evalIndex=0; 53 t=this.win.evalHistory[this.win.evalIndex]; 54 if(t)f.eval.value=t; 55 } 56 }; 57 // lists all known properties of an object 58 p.inspect = function(obj,showFunctions) { 59 this.print('Inspecting:'); 60 var v; 61 if (typeof(obj)=='string') obj=eval(obj); 62 if (typeof(obj)=='object') { 63 for (var i in obj) { 64 if (obj[i]==null) v = 'null' 65 else if (typeof(obj[i])=='undefined') v = 'null'; 66 else if (typeof(obj[i])=='function') { 67 if (showFunctions==false) continue; 68 else v = '[Function]'; 69 } 70 else if (typeof(obj[i])=='object' && typeof(obj[i].length)!='undefined') v = 'Array';// ['+obj[i]+']'; 71 else if (typeof(obj[i])=='object') v = '[Object]'; 72 else v = obj[i]; 73 this.print(' '+i+' = '+v); 74 } 75 } 76 else this.print(' undefined'); 77 }; 78 p.isLoaded = function() { 79 return (this.win!=null && this.win.document && typeof(this.win.document.debugform)=="object"); 80 }; 81 // opens the debugger window 82 p.open = function() { 83 var p = dynapi.library.path; 84 if (!this.isLoaded() && p) { 85 // Modified by Raphael Pereira 86 //var url = dynapi.documentPath+p+'ext/debug.html#'; 87 var url = p+'ext/debug.html#'; 88 var w = (dynapi.ua.def||dynapi.ua.dom)? 350:355 //dynapi.ua.mac? (dynapi.ua.ie?330:300) : 350; 89 var h = (dynapi.ua.def||dynapi.ua.dom)? 432:485 //dynapi.ua.mac? (dynapi.ua.ie?405:365) : (dynapi.ua.def||dynapi.ua.dom)? 420:476; 90 this.win = window.open(url,'debugwin','width='+w+',height='+h+',scrollbars=no,status=no,toolbar=no'); //,resizable=no 91 this.win.opener=window; 92 this.win.evalHistory=[]; 93 this.win.evalIndex=0; 94 this.print(); 95 /* dynapi.frame.onerror = function(msg, url, lno) { 96 dynapi.debug.error(msg, url, lno); 97 }; 98 */ 99 } 100 }; 101 // output text to the debug window 102 p.print = function(s) { 103 if (s==null) s = ''; 104 else s = s + '\n'; 105 if (this.isLoaded()) { 106 this.switchMode('normal'); 107 if (this._buffer != '') { // dump buffer 108 s = this._buffer + s; 109 this._buffer = ''; 110 } 111 this.win.document.debugform.print.value += s; 112 this._normalModeData = this.win.document.debugform.print.value; 113 114 // Does mozilla has something like this? 115 if (dynapi.ua.ie) { 116 var po = this.win.document.debugform.print; 117 po.scrollTop = po.scrollHeight; 118 var range = po.createTextRange(); 119 range.collapse(false); 120 range.select(); 121 } 122 } 123 else this._buffer += s; 124 }; 125 // reloads selected javascripts, packages or html pages 126 p.reload=function(t){ 127 if (!this.isLoaded) return; 128 t=t+''; 129 if(t.substr(0,3).toLowerCase()=='go:') { 130 t=t.substr(3).replace(/\\/g,'/'); 131 dynapi.frame.location.href=t; 132 return; 133 } 134 var i,f=t.split(';'); 135 for(i=0;i<f.length;i++){ 136 t=f[i]; 137 if(t.indexOf('.js')<0) dynapi.library.load(t,null,true); 138 else { 139 var lib=dynapi.library; 140 if (!lib.scripts[t]) lib.loadScript(t); 141 else lib.reloadScript(t,null,true); 142 } 143 } 144 if(this.win.focus) this.win.focus(); 145 else this.win.setZIndex({topmost:true}); 146 }; 147 p.reset=function(section){ 148 if (!this.isLoaded) return; 149 this._oldWatchSrc=''; 150 if(!section) { 151 this.win.document.debugform.reset(); 152 this._normalModeData=''; 153 this.switchMode('normal'); 154 }else{ 155 var t=this.win.document.debugform[section]; 156 if(t) t.value=''; 157 } 158 }; 159 p.status = function(str) { 160 if (this.isLoaded()) { 161 for (var i=1;i<arguments.length;i++) { 162 str += ', '+arguments[i]; 163 } 164 this.win.document.debugform.stat.value = str; 165 }; 166 }; 167 // Set Mode 168 p.switchMode=function(m){ 169 if (!this.isLoaded) return; 170 if(m=='watch'||(this._mode=='normal' && m!='normal')) { 171 this._normalModeData = this.win.document.debugform.print.value; 172 this._mode='watch'; 173 this._enableWatch(); 174 }else if(m=='normal'||(this._mode=='watch' && m!='watch')){ 175 this.win.document.debugform.print.value=(this._normalModeData)?this._normalModeData:''; 176 this._mode='normal'; 177 this._disableWatch(); 178 } 179 }; 180 // enters text to the evaluate field in the debugger widnow 181 p.setEvaluate = function(str) { 182 if (!this.isLoaded()) this._evalBuffer=str; 183 else { 184 if (!str) str = ''; 185 if(this._evalBuffer!='') { 186 str =this._evalBuffer+str; 187 this._evalBuffer=''; 188 } 189 this.win.document.debugform.eval.value = str; 190 this.setEvalHistory(str); 191 } 192 }; 193 // Set previous evaluation information 194 p.setEvalHistory=function(s){ 195 if(!this.isLoaded()) return; 196 var i,found; 197 if(s){ 198 for(i=0;i<this.win.evalHistory.length;i++){ 199 if(this.win.evalHistory[i]==s) {found=i;break;} 200 } 201 if(found!=null) this.win.evalHistory=dynapi.functions.removeFromArray(this.win.evalHistory,found); 202 this.win.evalHistory[this.win.evalHistory.length]=s; 203 this.win.evalIndex=this.win.evalHistory.length-1; 204 } 205 }; 206 p.showHelp=function(){ 207 var t='' 208 +'-----------------------\n' 209 +'Quick Help\n' 210 +'-----------------------\n' 211 +'1) To inspect an Object enter the name\n' 212 +'of the object in the "Inspect Variable/Object"\n' 213 +'textbox and then click on the "Inspect" button\n\n' 214 +'2) To Load/Reload a DynAPI Package,\n' 215 +'javascript or html page enter the name\n' 216 +'of the package or javascript in the reload\n' 217 +'text. For HTML pages type the prefix Go:\n' 218 +'before the page name.\n' 219 +'------------------------------------------------'; 220 this.print(t); 221 }; 222 // watch object variables; 223 p.watch = function(name,value){ 224 if(arguments.length>1) this._watch[name]=value; 225 else if(dynapi.frame.eval(name)) this._watch[name]='_watch object_'; 226 else this._watch[name]='_watch object_'; 227 }; 228 p._disableWatch = function(){ 229 this._oldWatchSrc=''; 230 if(this._timerWatch) { 231 window.clearTimeout(this._timerWatch); 232 this._timerWatch=0; 233 } 234 }; 235 p._enableWatch = function(){ 236 if(this._mode!='watch') return; 237 var src,row,v; 238 src='Name\t \t \t Value\n---------------------------------------\n'; 239 for(i in this._watch){ 240 if(this._watch[i]=='_watch object_') v=dynapi.frame.eval(i); 241 else v=this._watch[i]; 242 if(v==null) v='null'; 243 if(typeof(v)=='string') v=v.replace(/\n/g,' '); 244 src+=(i+' ').substr(0,22)+'\t '+v+'\n'; 245 } 246 if(src!=this._oldWatchSrc){ 247 this.win.document.debugform.print.value=this._oldWatchSrc=src; 248 } 249 if(this._timerWatch) window.clearTimeout(this._timerWatch); 250 this._timerWatch=window.setTimeout(this+'._enableWatch()',200); 251 }; 252 dynapi.debug = new Debugger(); 253 var t='------------------------------\n' 254 +'Click "?" for help\n' 255 +'------------------------------\n'; 256 dynapi.debug.print(t);
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |