21 var Debug = Debug || {};
29 Debug.lastLogger =
"";
31 Debug.prependMessage =
"";
34 Debug.HIGH_PRIORITY = 0;
35 Debug.WARN_PRIORITY = 1;
36 Debug.INFO_PRIORITY = 2;
37 Debug.TIP_PRIORITY = 3;
38 Debug.MED_PRIORITY = 50;
39 Debug.LOW_PRIORITY = 100;
44 Debug.BROWSER_TYPE = 0;
46 var tmp = (
new Error).stack;
48 Debug.BROWSER_TYPE = 1;
49 else if(tmp[0] ==
'@')
50 Debug.BROWSER_TYPE = 2;
59 Debug.FontInconsolata =
new FontFace(
'Inconsolata',
'url(/WebPath/fonts/inconsolata/Inconsolata-Regular.ttf)');
60 document.fonts.add(Debug.FontInconsolata);
61 }
catch(e){console.log(
"Ignoring font errors: " + e);}
64 Debug.FontComfortaa =
new FontFace(
'Comfortaa',
'url(/WebPath/fonts/comfortaa/Comfortaa-Regular.ttf)');
65 document.fonts.add(Debug.FontComfortaa);
66 }
catch(e){console.log(
"Ignoring font errors: " + e);}
69 Debug.FontInconsolataBold =
new FontFace(
'Inconsolata-Bold',
'url(/WebPath/fonts/inconsolata/Inconsolata-Bold.ttf)');
70 document.fonts.add(Debug.FontInconsolataBold);
71 }
catch(e){console.log(
"Ignoring font errors: " + e);}
74 Debug.FontComfortaaBold =
new FontFace(
'Comfortaa-Bold',
'url(/WebPath/fonts/comfortaa/Comfortaa-Bold.ttf)');
75 document.fonts.add(Debug.FontComfortaaBold);
76 }
catch(e){console.log(
"Ignoring font errors: " + e);}
79 Debug.FontComfortaaLight =
new FontFace(
'Comfortaa-Light',
'url(/WebPath/fonts/comfortaa/Comfortaa-Light.ttf)');
80 document.fonts.add(Debug.FontComfortaaLight);
81 }
catch(e){console.log(
"Ignoring font errors: " + e);}
87 Debug.log = console.log.bind(window.console);
92 Debug.log =
function(str,num) {
94 if(num === undefined) num = Debug.LOW_PRIORITY;
100 returnStr = localCallOutDebugLocales(str);
105 if(Debug.level < 0) Debug.level = 0;
106 if(Debug.mode && num <= Debug.level)
108 str = Debug.prependMessage + str;
111 (num==0?
"High":(num==1?
"Warn":(num==2?
"Info":
"Tip")))
112 :(num<99?
"Med":
"Low");
114 if(Debug.BROWSER_TYPE == 1)
116 Debug.lastLogger = (
new Error).stack.split(
"\n")[2];
117 Debug.lastLog = Debug.lastLogger.slice(0,Debug.lastLogger.indexOf(
' ('));
118 Debug.lastLogger = Debug.lastLogger.slice(Debug.lastLog.length+2,
119 Debug.lastLogger.length-1);
121 else if(Debug.BROWSER_TYPE == 2)
123 Debug.lastLogger = (
new Error).stack.split(
"\n")[1];
124 Debug.lastLog = Debug.lastLogger.slice(0,Debug.lastLogger.indexOf(
'@'));
125 Debug.lastLogger = Debug.lastLogger.slice(Debug.lastLog.length+1,
126 Debug.lastLogger.length);
129 console.log(
"%c" + type +
"-Priority" +
130 ":\t " + Debug.lastLog +
":\n" +
131 Debug.lastLogger +
"::\t" + str,
132 num == 0?
"color:#F30;"
133 :(num == 1?
"color:#F70"
134 :(num < 99?
"color:#092":
"color:#333")));
138 Debug.errorPop(str,num);
145 function localCallOutDebugLocales(str)
152 while((j = str.indexOf(
'[',i)) > 0 && (k = str.indexOf(
']',i)) > 0)
167 if((str[j-3] ==
'.' && str[j-2] ==
'h') ||
168 (str[j-4] ==
'.' && str[j-3] ==
'c' && str[j-2] ==
'c'))
171 for(l = j-3; l >= i; --l)
172 if(!((str[l] >=
'a' && str[l] <=
'z') ||
173 (str[l] >=
'A' && str[l] <=
'Z') ||
174 (str[l] >=
'0' && str[l] <=
'9') ||
186 returnStr += str.substr(i,l-i);
189 returnStr +=
"<br><label class='" +
190 Debug._errBoxId +
"-localCallOut'>";
193 returnStr += str.substr(l,k+1-l);
196 returnStr +=
"</label><br>";
199 while(k+1 < str.length &&
200 (str[k+1] ==
'\n' || str[k+1] ==
'\t')) ++k;
204 returnStr += str.substr(i,k+1-i);
216 returnStr += str.substr(i);
230 console.log =
function(){};
231 Debug.log =
function(){};
232 Debug.logv =
function(){};
236 Debug.log(
"Debug mode is on at level: " + Debug.level);
237 Debug.log(
"This is an example for posterity that is not printed due to debug priority.",Debug.level+1);
246 Debug._errBoxId =
"Debug-error-box";
247 Debug._errBoxOffX = 0;
248 Debug._errBoxOffY = 0;
249 Debug._errBoxOffW = 0;
250 Debug._errBoxOffH = 0;
253 Debug.errorPopConditionString =
function(str) {
254 return str.replace(/\n/g ,
"<br>").replace(/\t/g,
" ");
260 Debug.errorPop =
function(err,severity) {
262 var errBoxAlpha =
"1.0";
268 var el = document.getElementById(Debug._errBoxId);
271 var body = document.getElementsByTagName(
"BODY")[0];
275 window.setTimeout(
function() { Debug.errorPop(err,severity)}, 1000);
280 el = document.createElement(
"div");
281 el.setAttribute(
"id", Debug._errBoxId);
282 el.style.display =
"none";
283 var str =
"<a class='" +
285 "-header' onclick='javascript:Debug.closeErrorPop();event.stopPropagation();' onmouseup='event.stopPropagation();'>Close Errors</a>";
289 "-moveBar' style='" +
290 "position:absolute;width:100%;height:15px;top:0;left:0;background-color:rgb(128, 128, 128);cursor:move;" +
291 "outline: none; /* to stop firefox selection*/ -webkit-user-select: none; /* prevent selection*/ -moz-user-select: none; user-select: none;" +
293 "onmousedown='javascript:Debug.handleErrorMoveStart(event);event.stopPropagation();' " +
294 "title='Click and drag to reposition this popup window.' " +
298 "<div style='color:white;font-size:16px;padding-bottom:5px;'>" +
299 "Note: Newest messages are at the top." +
300 "<label style='color:white;font-size:11px;'><br>(Press [ESC] to close and [SHIFT + ESC] to re-open)</font>" +
301 "<div id='downloadIconDiv' onmouseup='Debug.downloadMessages()' title='Download messages to text file.' style='float: right; margin: -10px 30px -100px -100px; cursor: pointer'>" +
303 "<div style='display: block; margin-left: 3px; height:7px; width: 6px; background-color: white;'></div>" +
304 "<div style='display: block; width: 0; height: 0; border-left: 6px solid transparent; border-right: 6px solid transparent; border-top: 8px solid white;'></div>" +
305 "<div style='position: relative; top: 5px; width: 12px; height: 2px; display: block; background-color: white;'></div>" +
315 str +=
"<div class='" + Debug._errBoxId +
"-resizeBarLeft' " +
317 "background-color:rgb(128, 128, 128);position:absolute;width:15px;height:15px;top:-1000px;left:0;cursor:nesw-resize;" +
318 "outline: none; /* to stop firefox selection*/ -webkit-user-select: none; /* prevent selection*/ -moz-user-select: none; user-select: none;" +
320 "onmousedown='javascript:Debug.handleErrorResizeStart(event,1,1);event.stopPropagation();' " +
321 "title='Click and drag to resize vertically this popup window.' " +
323 str +=
"<div class='" + Debug._errBoxId +
"-resizeBar' " +
325 "background-color:transparent;position:absolute;width:100%;height:5px;top:-1000px;left:15px;cursor:ns-resize;" +
326 "outline: none; /* to stop firefox selection*/ -webkit-user-select: none; /* prevent selection*/ -moz-user-select: none; user-select: none;" +
328 "onmousedown='javascript:Debug.handleErrorResizeStart(event);event.stopPropagation();' " +
329 "title='Click and drag to resize this popup window.' " +
331 str +=
"<div class='" + Debug._errBoxId +
"-resizeBarRight' " +
333 "background-color:rgb(128, 128, 128);position:absolute;width:15px;height:15px;top:-1000px;left:0;cursor:nwse-resize;" +
334 "outline: none; /* to stop firefox selection*/ -webkit-user-select: none; /* prevent selection*/ -moz-user-select: none; user-select: none;" +
336 "onmousedown='javascript:Debug.handleErrorResizeStart(event,1);event.stopPropagation();' " +
337 "title='Click and drag to resize this popup window.' " +
340 body.appendChild(el);
344 function localDebugKeyDownListener(e)
352 if(!e.shiftKey && e.keyCode == 27)
356 Debug.closeErrorPop();
358 else if(e.shiftKey && e.keyCode == 27)
362 Debug.bringBackErrorPop();
366 document.body.removeEventListener(
"keydown",localDebugKeyDownListener);
367 document.body.addEventListener(
"keydown",localDebugKeyDownListener);
374 css +=
"#" + Debug._errBoxId +
" *" +
375 "{font-family: 'Comfortaa', arial;" +
376 "font-weight: 200;" +
378 "color: rgb(255,200,100);" +
383 css +=
"#" + Debug._errBoxId +
" a" +
384 ", #" + Debug._errBoxId +
" center b" +
385 "{color: white; text-decoration: none; font-weight: bold;" +
386 "font-size: 18px; font-family: 'Comfortaa', arial;" +
388 css +=
"#" + Debug._errBoxId +
" a:hover" +
389 "{text-decoration: underline;" +
394 css +=
"#" + Debug._errBoxId +
" i" +
395 ", #" + Debug._errBoxId +
" u" +
397 "font-size: 18px; font-family: 'Comfortaa', arial;" +
399 css +=
"#" + Debug._errBoxId +
" b" +
401 "font-weight: bold;" +
402 "color: rgb(255, 231, 187);" +
406 css +=
"#" + Debug._errBoxId +
408 "position: absolute; display: none; border: 2px solid gray;" +
409 "background-color: rgba(153,0,51, " + errBoxAlpha +
"); overflow-y: hidden;" +
410 "overflow-x: hidden; padding: 5px; -moz-border-radius: 2px;" +
411 "-webkit-border-radius: 2px; border-radius: 2px;" +
412 "font-size: 18px; z-index: 2147483647;" +
413 "font-family: 'Comfortaa', arial; text-align: center;" +
414 "left: 8px; top: 8px; margin-right: 8px; " +
418 css +=
"#" + Debug._errBoxId +
"-err" +
420 "color: rgb(255,200,100); font-size: 18px;" +
421 "font-family: 'Comfortaa', arial;" +
422 "left: 8px; top: 8px; margin-right: 8px;" +
423 "margin-bottom:-12px;" +
424 "text-align: left;" +
425 "overflow-y: scroll;" +
426 "overflow-x: auto;" +
430 css +=
"#" + Debug._errBoxId +
"-err i" +
432 ",#" + Debug._errBoxId +
"-err u" +
435 "color: rgb(255,200,100); font-size: 18px;" +
436 "font-family: 'Comfortaa', arial;" +
437 "text-align: left;" +
443 "#" + Debug._errBoxId +
"-err div" +
445 "color: rgb(255,200,100); font-size: 18px;" +
446 "font-family: 'Comfortaa', arial;" +
447 "left: 8px, top: 8px; margin-right: 8px;" +
448 "text-align: left;" +
451 css +=
"#" + Debug._errBoxId +
"-err b" +
453 "color: rgb(255,225,200); font-size: 18px;" +
454 "font-family: 'Comfortaa', arial;" +
455 "text-align: left;" +
458 css +=
"#" + Debug._errBoxId +
" ." + Debug._errBoxId +
"-localCallOut" +
459 "{font-size: 10px;}\n\n";
462 var style = document.createElement(
'style');
464 if (style.styleSheet) {
465 style.styleSheet.cssText = css;
467 style.appendChild(document.createTextNode(css));
470 document.getElementsByTagName(
'head')[0].appendChild(style);
472 window.addEventListener(
"resize",localResize);
473 window.addEventListener(
"scroll",localScroll);
474 window.addEventListener(
"mouseup",Debug.handleErrorMoveStop);
475 window.addEventListener(
"mousemove",Debug.handleErrorMove);
482 var el = document.getElementById(Debug._errBoxId +
"-err");
483 var str = el.innerHTML;
485 var wasAlreadyContent =
false;
489 wasAlreadyContent =
true;
491 var tstr = d.toLocaleTimeString();
492 tstr = tstr.substring(0,tstr.lastIndexOf(
' ')) +
493 (tstr[tstr.length-2]==
'A'?
"am":
"pm");
495 if(severity == Debug.TIP_PRIORITY)
497 (wasAlreadyContent?
"<br>...<br>":
"") +
498 "<label style='color:white;font-size:16px;'>" +
499 d.toLocaleDateString() +
500 " " + tstr +
" (Tip) :</label><br>" +
501 Debug.errorPopConditionString(err);
503 str =
"<label style='color:white;font-size:16px;'>" +
504 d.toLocaleDateString() +
506 (severity == Debug.INFO_PRIORITY ?
'(Info)':
'')+
507 (severity == Debug.WARN_PRIORITY ?
'(Warning)':
'') +
509 Debug.errorPopConditionString(err) +
510 (wasAlreadyContent?
"<br>...<br>":
"") +
516 function localResize()
518 Debug._errBoxOffX = 0;
519 Debug._errBoxOffY = 0;
520 Debug._errBoxOffH = 0;
521 Debug._errBoxOffW = 0;
522 Debug.handleErrorResize();
524 function localScroll()
526 Debug.handleErrorResize();
528 Debug.handleErrorResize();
531 Debug._errBox.style.display =
"block";
535 var els = document.getElementsByClassName(Debug._errBoxId +
"-header");
539 case Debug.TIP_PRIORITY:
541 if(wasAlreadyContent &&
542 (el.innerHTML ==
"Close Errors" ||
543 el.innerHTML ==
"Close Warnings" ||
544 el.innerHTML ==
"Close Info"))
546 el.innerHTML =
"Close Tooltip";
547 Debug._errBox.style.backgroundColor =
"rgba(0, 49, 99, " + errBoxAlpha +
")";
549 case Debug.INFO_PRIORITY:
551 if(wasAlreadyContent &&
552 (el.innerHTML ==
"Close Errors" ||
553 el.innerHTML ==
"Close Warnings"))
555 el.innerHTML =
"Close Info";
556 Debug._errBox.style.backgroundColor =
"rgba(0,153,51, " + errBoxAlpha +
")";
558 case Debug.WARN_PRIORITY:
560 if(wasAlreadyContent &&
561 el.innerHTML ==
"Close Errors")
563 el.innerHTML =
"Close Warnings";
564 Debug._errBox.style.backgroundColor =
"rgba(160, 79, 0, " + errBoxAlpha +
")";
567 el.innerHTML =
"Close Errors";
568 Debug._errBox.style.backgroundColor =
"rgba(153,0,51, " + errBoxAlpha +
")";
570 els[1].innerHTML = el.innerHTML;
573 Debug._errBoxLastContent =
"";
576 Debug.closeErrorPop =
function() {
577 document.getElementById(Debug._errBoxId).style.display =
"none";
578 Debug._errBoxLastContent = document.getElementById(Debug._errBoxId +
"-err").innerHTML;
579 document.getElementById(Debug._errBoxId +
"-err").innerHTML =
"";
583 Debug.bringBackErrorPop =
function() {
584 document.getElementById(Debug._errBoxId +
"-err").innerHTML = Debug._errBoxLastContent;
585 document.getElementById(Debug._errBoxId).style.display =
"block";
589 Debug._errBoxOffMoveStartX = -1;
590 Debug._errBoxOffMoveStartY;
591 Debug._errBoxOffResizeStartX = -1;
592 Debug._errBoxOffResizeStartY = -1;
594 Debug.handleErrorMoveStart =
function(e) {
595 Debug.log(
"Move Start");
596 Debug._errBoxOffMoveStartX = e.screenX - Debug._errBoxOffX;
597 Debug._errBoxOffMoveStartY = e.screenY - Debug._errBoxOffY;
601 Debug.handleErrorResizeStart =
function(e,resizeW,moveLeft) {
602 Debug.log(
"Resize Start");
603 Debug._errBoxOffResizeStartY = e.screenY - Debug._errBoxOffH;
606 Debug._errBoxOffMoveStartX = e.screenX - Debug._errBoxOffX;
607 Debug._errBoxOffResizeStartX = e.screenX + Debug._errBoxOffW;
610 Debug._errBoxOffResizeStartX = e.screenX - Debug._errBoxOffW;
615 Debug.handleErrorMoveStop =
function(e) {
618 if(Debug._errBoxOffResizeStartY != -1)
620 Debug.log(
"Resize Stop");
621 Debug._errBoxOffH = e.screenY - Debug._errBoxOffResizeStartY;
622 Debug._errBoxOffResizeStartY = -1;
624 if(Debug._errBoxOffMoveStartX != -1)
626 Debug._errBoxOffX = e.screenX - Debug._errBoxOffMoveStartX;
627 Debug._errBoxOffW = Debug._errBoxOffResizeStartX - e.screenX;
628 Debug._errBoxOffMoveStartX = -1;
629 Debug._errBoxOffResizeStartX = -1;
631 else if(Debug._errBoxOffResizeStartX != -1)
633 Debug._errBoxOffW = e.screenX - Debug._errBoxOffResizeStartX;
634 Debug._errBoxOffResizeStartX = -1;
636 Debug.handleErrorResize();
638 else if(Debug._errBoxOffMoveStartX != -1)
640 Debug.log(
"Move Stop");
641 Debug._errBoxOffX = e.screenX - Debug._errBoxOffMoveStartX;
642 Debug._errBoxOffY = e.screenY - Debug._errBoxOffMoveStartY;
643 Debug._errBoxOffMoveStartX = -1;
644 Debug.handleErrorResize();
651 Debug.handleErrorMove =
function(e) {
653 if(Debug._errBoxOffMoveStartX == -1 &&
654 Debug._errBoxOffResizeStartY == -1)
return;
658 Debug._errBoxOffMoveStartX = -1;
659 Debug._errBoxOffResizeStartY = -1;
660 Debug._errBoxOffResizeStartX = -1;
664 if(Debug._errBoxOffResizeStartY != -1)
666 Debug.log(
"Resize " + e.buttons);
667 Debug._errBoxOffH = e.screenY - Debug._errBoxOffResizeStartY;
669 if(Debug._errBoxOffMoveStartX != -1)
671 Debug._errBoxOffX = e.screenX - Debug._errBoxOffMoveStartX;
672 Debug._errBoxOffW = Debug._errBoxOffResizeStartX - e.screenX;
674 else if(Debug._errBoxOffResizeStartX != -1)
675 Debug._errBoxOffW = e.screenX - Debug._errBoxOffResizeStartX;
677 Debug.handleErrorResize();
679 else if(Debug._errBoxOffMoveStartX != -1)
681 Debug.log(
"Move " + e.buttons);
682 Debug._errBoxOffX = e.screenX - Debug._errBoxOffMoveStartX;
683 Debug._errBoxOffY = e.screenY - Debug._errBoxOffMoveStartY;
684 Debug.handleErrorResize();
690 Debug.handleErrorResize =
function() {
693 var offX = document.documentElement.scrollLeft || document.body.scrollLeft || 0;
694 var offY = document.documentElement.scrollTop || document.body.scrollTop || 0;
699 if(typeof DesktopContent !=
'undefined')
701 w = (DesktopContent.getWindowWidth()-16-14);
702 screenh = (DesktopContent.getWindowHeight()-16-14);
704 else if(typeof Desktop !=
'undefined' && Desktop.desktop)
706 w = (Desktop.desktop.getDesktopWidth()-16-14);
707 screenh = (Desktop.desktop.getDesktopHeight()-16-14);
720 if(w + Debug._errBoxOffW < 200)
722 Debug._errBoxOffW = 200 - w;
724 w += Debug._errBoxOffW;
726 var h = (screenh - 20) + Debug._errBoxOffH;
729 Debug._errBoxOffH = -200;
734 if(Debug._errBoxOffX + w > screenw)
735 Debug._errBoxOffX = screenw - w;
736 if(Debug._errBoxOffX < minx)
737 Debug._errBoxOffX = minx;
738 if(Debug._errBoxOffY + h > screenh)
739 Debug._errBoxOffY = screenh - h;
740 if(Debug._errBoxOffY < 0)
741 Debug._errBoxOffY = 0;
743 Debug._errBox.style.width = (w) +
"px";
744 Debug._errBox.style.height = (h) +
"px";
745 Debug._errBox.style.left = (Debug._errBoxOffX + offX + 8) +
"px";
746 Debug._errBox.style.top = (Debug._errBoxOffY + offY + 8) +
"px";
747 Debug._errBox.style.marginRight = -(w+10) +
"px";
748 Debug._errBox.style.marginBottom = -(h+80) +
"px";
751 var el = document.getElementsByClassName(Debug._errBoxId +
"-resizeBar")[0];
752 el.style.top = (h+6) +
"px";
753 el = document.getElementsByClassName(Debug._errBoxId +
"-resizeBarLeft")[0];
754 el.style.top = (h+6-10) +
"px";
755 el = document.getElementsByClassName(Debug._errBoxId +
"-resizeBarRight")[0];
756 el.style.left = (w-5) +
"px";
757 el.style.top = (h+6-10) +
"px";
759 el = document.getElementsByClassName(Debug._errBoxId +
"-err")[0];
760 el.style.height = (h-115) +
"px";
765 Debug.downloadMessages =
function() {
767 console.log(
"downloading messages...");
770 var dataStr =
"data:text/txt;charset=utf-8,";
772 var lines = Debug._errBox.innerText.split(
'\n');
773 for(var i=2;i<lines.length-2;++i)
775 dataStr += encodeURIComponent(lines[i] +
"\n");
778 var link = document.createElement(
"a");
779 link.setAttribute(
"href", dataStr);
780 link.setAttribute(
"style",
"display:none");
781 link.setAttribute(
"download",
"otsdaq_Messages_download.txt");
782 document.body.appendChild(link);
786 link.parentNode.removeChild(link);