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-4] ==
'i') &&
169 str[j-3] ==
'c' && str[j-2] ==
'c'))
172 for(l = j-3; l >= i; --l)
173 if(!((str[l] >=
'a' && str[l] <=
'z') ||
174 (str[l] >=
'A' && str[l] <=
'Z') ||
175 (str[l] >=
'0' && str[l] <=
'9') ||
187 returnStr += str.substr(i,l-i);
190 returnStr +=
"<br><label class='" +
191 Debug._errBoxId +
"-localCallOut'>";
194 returnStr += str.substr(l,k+1-l);
197 returnStr +=
"</label><br>";
200 while(k+1 < str.length &&
201 (str[k+1] ==
'\n' || str[k+1] ==
'\t')) ++k;
205 returnStr += str.substr(i,k+1-i);
217 returnStr += str.substr(i);
231 console.log =
function(){};
232 Debug.log =
function(){};
233 Debug.logv =
function(){};
237 Debug.log(
"Debug mode is on at level: " + Debug.level);
238 Debug.log(
"This is an example for posterity that is not printed due to debug priority.",Debug.level+1);
247 Debug._errBoxId =
"Debug-error-box";
248 Debug._errBoxOffX = 0;
249 Debug._errBoxOffY = 0;
250 Debug._errBoxOffW = 0;
251 Debug._errBoxOffH = 0;
254 Debug.errorPopConditionString =
function(str) {
255 return str.replace(/\n/g ,
"<br>").replace(/\t/g,
" ");
261 Debug.errorPop =
function(err,severity) {
263 var errBoxAlpha =
"1.0";
269 var el = document.getElementById(Debug._errBoxId);
272 var body = document.getElementsByTagName(
"BODY")[0];
276 window.setTimeout(
function() { Debug.errorPop(err,severity)}, 1000);
281 el = document.createElement(
"div");
282 el.setAttribute(
"id", Debug._errBoxId);
283 el.style.display =
"none";
284 var str =
"<a class='" +
286 "-header' onclick='javascript:Debug.closeErrorPop();event.stopPropagation();' onmouseup='event.stopPropagation();'>Close Errors</a>";
290 "-moveBar' style='" +
291 "position:absolute;width:100%;height:15px;top:0;left:0;background-color:rgb(128, 128, 128);cursor:move;" +
292 "outline: none; /* to stop firefox selection*/ -webkit-user-select: none; /* prevent selection*/ -moz-user-select: none; user-select: none;" +
294 "onmousedown='javascript:Debug.handleErrorMoveStart(event);event.stopPropagation();' " +
295 "title='Click and drag to reposition this popup window.' " +
299 "<div style='color:white;font-size:16px;padding-bottom:5px;'>" +
300 "Note: Newest messages are at the top." +
301 "<label style='color:white;font-size:11px;'><br>(Press [ESC] to close and [SHIFT + ESC] to re-open)</font>" +
302 "<div id='downloadIconDiv' onmouseup='Debug.downloadMessages()' title='Download messages to text file.' style='float: right; margin: -10px 30px -100px -100px; cursor: pointer'>" +
304 "<div style='display: block; margin-left: 3px; height:7px; width: 6px; background-color: white;'></div>" +
305 "<div style='display: block; width: 0; height: 0; border-left: 6px solid transparent; border-right: 6px solid transparent; border-top: 8px solid white;'></div>" +
306 "<div style='position: relative; top: 5px; width: 12px; height: 2px; display: block; background-color: white;'></div>" +
316 str +=
"<div class='" + Debug._errBoxId +
"-resizeBarLeft' " +
318 "background-color:rgb(128, 128, 128);position:absolute;width:15px;height:15px;top:-1000px;left:0;cursor:nesw-resize;" +
319 "outline: none; /* to stop firefox selection*/ -webkit-user-select: none; /* prevent selection*/ -moz-user-select: none; user-select: none;" +
321 "onmousedown='javascript:Debug.handleErrorResizeStart(event,1,1);event.stopPropagation();' " +
322 "title='Click and drag to resize vertically this popup window.' " +
324 str +=
"<div class='" + Debug._errBoxId +
"-resizeBar' " +
326 "background-color:transparent;position:absolute;width:100%;height:5px;top:-1000px;left:15px;cursor:ns-resize;" +
327 "outline: none; /* to stop firefox selection*/ -webkit-user-select: none; /* prevent selection*/ -moz-user-select: none; user-select: none;" +
329 "onmousedown='javascript:Debug.handleErrorResizeStart(event);event.stopPropagation();' " +
330 "title='Click and drag to resize this popup window.' " +
332 str +=
"<div class='" + Debug._errBoxId +
"-resizeBarRight' " +
334 "background-color:rgb(128, 128, 128);position:absolute;width:15px;height:15px;top:-1000px;left:0;cursor:nwse-resize;" +
335 "outline: none; /* to stop firefox selection*/ -webkit-user-select: none; /* prevent selection*/ -moz-user-select: none; user-select: none;" +
337 "onmousedown='javascript:Debug.handleErrorResizeStart(event,1);event.stopPropagation();' " +
338 "title='Click and drag to resize this popup window.' " +
341 body.appendChild(el);
345 function localDebugKeyDownListener(e)
353 if(!e.shiftKey && e.keyCode == 27)
357 Debug.closeErrorPop();
359 else if(e.shiftKey && e.keyCode == 27)
363 Debug.bringBackErrorPop();
367 document.body.removeEventListener(
"keydown",localDebugKeyDownListener);
368 document.body.addEventListener(
"keydown",localDebugKeyDownListener);
375 css +=
"#" + Debug._errBoxId +
" *" +
376 "{font-family: 'Comfortaa', arial;" +
377 "font-weight: 200;" +
379 "color: rgb(255,200,100);" +
380 "-webkit-user-select: text;" +
381 "-moz-user-select: text;" +
382 "user-select: text;" +
387 css +=
"#" + Debug._errBoxId +
" a" +
388 ", #" + Debug._errBoxId +
" center b" +
389 "{color: white; text-decoration: none; font-weight: bold;" +
390 "font-size: 18px; font-family: 'Comfortaa', arial;" +
392 css +=
"#" + Debug._errBoxId +
" a:hover" +
393 "{text-decoration: underline;" +
398 css +=
"#" + Debug._errBoxId +
" i" +
399 ", #" + Debug._errBoxId +
" u" +
401 "font-size: 18px; font-family: 'Comfortaa', arial;" +
403 css +=
"#" + Debug._errBoxId +
" b" +
405 "font-weight: bold;" +
406 "color: rgb(255, 231, 187);" +
410 css +=
"#" + Debug._errBoxId +
412 "position: absolute; display: none; border: 2px solid gray;" +
413 "background-color: rgba(153,0,51, " + errBoxAlpha +
"); overflow-y: hidden;" +
414 "overflow-x: hidden; padding: 5px; -moz-border-radius: 2px;" +
415 "-webkit-border-radius: 2px; border-radius: 2px;" +
416 "font-size: 18px; z-index: 2147483647;" +
417 "font-family: 'Comfortaa', arial; text-align: center;" +
418 "left: 8px; top: 8px; margin-right: 8px; " +
422 css +=
"#" + Debug._errBoxId +
"-err" +
424 "color: rgb(255,200,100); font-size: 18px;" +
425 "font-family: 'Comfortaa', arial;" +
426 "left: 8px; top: 8px; margin-right: 8px;" +
427 "margin-bottom:-12px;" +
428 "text-align: left;" +
429 "overflow-y: scroll;" +
430 "overflow-x: auto;" +
432 "-webkit-user-select: text;" +
433 "-moz-user-select: text;" +
434 "user-select: text;" +
437 css +=
"#" + Debug._errBoxId +
"-err i" +
439 ",#" + Debug._errBoxId +
"-err u" +
442 "color: rgb(255,200,100); font-size: 18px;" +
443 "font-family: 'Comfortaa', arial;" +
444 "text-align: left;" +
445 "-webkit-user-select: text;" +
446 "-moz-user-select: text;" +
447 "user-select: text;" +
453 "#" + Debug._errBoxId +
"-err div" +
455 "color: rgb(255,200,100); font-size: 18px;" +
456 "font-family: 'Comfortaa', arial;" +
457 "left: 8px, top: 8px; margin-right: 8px;" +
458 "text-align: left;" +
459 "-webkit-user-select: text;" +
460 "-moz-user-select: text;" +
461 "user-select: text;" +
464 css +=
"#" + Debug._errBoxId +
"-err b" +
466 "color: rgb(255,225,200); font-size: 18px;" +
467 "font-family: 'Comfortaa', arial;" +
468 "text-align: left;" +
469 "-webkit-user-select: text;" +
470 "-moz-user-select: text;" +
471 "user-select: text;" +
474 css +=
"#" + Debug._errBoxId +
" ." + Debug._errBoxId +
"-localCallOut" +
475 "{font-size: 10px;}\n\n";
478 var style = document.createElement(
'style');
480 if (style.styleSheet) {
481 style.styleSheet.cssText = css;
483 style.appendChild(document.createTextNode(css));
486 document.getElementsByTagName(
'head')[0].appendChild(style);
488 window.addEventListener(
"resize",localResize);
489 window.addEventListener(
"scroll",localScroll);
490 window.addEventListener(
"mouseup",Debug.handleErrorMoveStop);
491 window.addEventListener(
"mousemove",Debug.handleErrorMove);
498 var el = document.getElementById(Debug._errBoxId +
"-err");
499 var str = el.innerHTML;
501 var wasAlreadyContent =
false;
505 wasAlreadyContent =
true;
507 var tstr = d.toLocaleTimeString();
508 tstr = tstr.substring(0,tstr.lastIndexOf(
' ')) +
509 (tstr[tstr.length-2]==
'A'?
"am":
"pm");
511 if(severity == Debug.TIP_PRIORITY)
513 (wasAlreadyContent?
"<br>...<br>":
"") +
514 "<label style='color:white;font-size:16px;'>" +
515 d.toLocaleDateString() +
516 " " + tstr +
" (Tip) :</label><br>" +
517 Debug.errorPopConditionString(err);
519 str =
"<label style='color:white;font-size:16px;'>" +
520 d.toLocaleDateString() +
522 (severity == Debug.INFO_PRIORITY ?
'(Info)':
'')+
523 (severity == Debug.WARN_PRIORITY ?
'(Warning)':
'') +
525 Debug.errorPopConditionString(err) +
526 (wasAlreadyContent?
"<br>...<br>":
"") +
532 function localResize()
534 Debug._errBoxOffX = 0;
535 Debug._errBoxOffY = 0;
536 Debug._errBoxOffH = 0;
537 Debug._errBoxOffW = 0;
538 Debug.handleErrorResize();
540 function localScroll()
542 Debug.handleErrorResize();
544 Debug.handleErrorResize();
547 Debug._errBox.style.display =
"block";
551 var els = document.getElementsByClassName(Debug._errBoxId +
"-header");
555 case Debug.TIP_PRIORITY:
557 if(wasAlreadyContent &&
558 (el.innerHTML ==
"Close Errors" ||
559 el.innerHTML ==
"Close Warnings" ||
560 el.innerHTML ==
"Close Info"))
562 el.innerHTML =
"Close Tooltip";
563 Debug._errBox.style.backgroundColor =
"rgba(0, 49, 99, " + errBoxAlpha +
")";
565 case Debug.INFO_PRIORITY:
567 if(wasAlreadyContent &&
568 (el.innerHTML ==
"Close Errors" ||
569 el.innerHTML ==
"Close Warnings"))
571 el.innerHTML =
"Close Info";
572 Debug._errBox.style.backgroundColor =
"rgba(0,153,51, " + errBoxAlpha +
")";
574 case Debug.WARN_PRIORITY:
576 if(wasAlreadyContent &&
577 el.innerHTML ==
"Close Errors")
579 el.innerHTML =
"Close Warnings";
580 Debug._errBox.style.backgroundColor =
"rgba(160, 79, 0, " + errBoxAlpha +
")";
583 el.innerHTML =
"Close Errors";
584 Debug._errBox.style.backgroundColor =
"rgba(153,0,51, " + errBoxAlpha +
")";
586 els[1].innerHTML = el.innerHTML;
589 Debug._errBoxLastContent =
"";
592 Debug.closeErrorPop =
function() {
593 document.getElementById(Debug._errBoxId).style.display =
"none";
594 Debug._errBoxLastContent = document.getElementById(Debug._errBoxId +
"-err").innerHTML;
595 document.getElementById(Debug._errBoxId +
"-err").innerHTML =
"";
599 Debug.bringBackErrorPop =
function() {
600 document.getElementById(Debug._errBoxId +
"-err").innerHTML = Debug._errBoxLastContent;
601 document.getElementById(Debug._errBoxId).style.display =
"block";
605 Debug._errBoxOffMoveStartX = -1;
606 Debug._errBoxOffMoveStartY;
607 Debug._errBoxOffResizeStartX = -1;
608 Debug._errBoxOffResizeStartY = -1;
610 Debug.handleErrorMoveStart =
function(e) {
611 Debug.log(
"Move Start");
612 Debug._errBoxOffMoveStartX = e.screenX - Debug._errBoxOffX;
613 Debug._errBoxOffMoveStartY = e.screenY - Debug._errBoxOffY;
617 Debug.handleErrorResizeStart =
function(e,resizeW,moveLeft) {
618 Debug.log(
"Resize Start");
619 Debug._errBoxOffResizeStartY = e.screenY - Debug._errBoxOffH;
622 Debug._errBoxOffMoveStartX = e.screenX - Debug._errBoxOffX;
623 Debug._errBoxOffResizeStartX = e.screenX + Debug._errBoxOffW;
626 Debug._errBoxOffResizeStartX = e.screenX - Debug._errBoxOffW;
631 Debug.handleErrorMoveStop =
function(e) {
634 if(Debug._errBoxOffResizeStartY != -1)
636 Debug.log(
"Resize Stop");
637 Debug._errBoxOffH = e.screenY - Debug._errBoxOffResizeStartY;
638 Debug._errBoxOffResizeStartY = -1;
640 if(Debug._errBoxOffMoveStartX != -1)
642 Debug._errBoxOffX = e.screenX - Debug._errBoxOffMoveStartX;
643 Debug._errBoxOffW = Debug._errBoxOffResizeStartX - e.screenX;
644 Debug._errBoxOffMoveStartX = -1;
645 Debug._errBoxOffResizeStartX = -1;
647 else if(Debug._errBoxOffResizeStartX != -1)
649 Debug._errBoxOffW = e.screenX - Debug._errBoxOffResizeStartX;
650 Debug._errBoxOffResizeStartX = -1;
652 Debug.handleErrorResize();
654 else if(Debug._errBoxOffMoveStartX != -1)
656 Debug.log(
"Move Stop");
657 Debug._errBoxOffX = e.screenX - Debug._errBoxOffMoveStartX;
658 Debug._errBoxOffY = e.screenY - Debug._errBoxOffMoveStartY;
659 Debug._errBoxOffMoveStartX = -1;
660 Debug.handleErrorResize();
667 Debug.handleErrorMove =
function(e) {
669 if(Debug._errBoxOffMoveStartX == -1 &&
670 Debug._errBoxOffResizeStartY == -1)
return;
674 Debug._errBoxOffMoveStartX = -1;
675 Debug._errBoxOffResizeStartY = -1;
676 Debug._errBoxOffResizeStartX = -1;
680 if(Debug._errBoxOffResizeStartY != -1)
682 Debug.log(
"Resize " + e.buttons);
683 Debug._errBoxOffH = e.screenY - Debug._errBoxOffResizeStartY;
685 if(Debug._errBoxOffMoveStartX != -1)
687 Debug._errBoxOffX = e.screenX - Debug._errBoxOffMoveStartX;
688 Debug._errBoxOffW = Debug._errBoxOffResizeStartX - e.screenX;
690 else if(Debug._errBoxOffResizeStartX != -1)
691 Debug._errBoxOffW = e.screenX - Debug._errBoxOffResizeStartX;
693 Debug.handleErrorResize();
695 else if(Debug._errBoxOffMoveStartX != -1)
697 Debug.log(
"Move " + e.buttons);
698 Debug._errBoxOffX = e.screenX - Debug._errBoxOffMoveStartX;
699 Debug._errBoxOffY = e.screenY - Debug._errBoxOffMoveStartY;
700 Debug.handleErrorResize();
706 Debug.handleErrorResize =
function() {
709 var offX = document.documentElement.scrollLeft || document.body.scrollLeft || 0;
710 var offY = document.documentElement.scrollTop || document.body.scrollTop || 0;
715 if(typeof DesktopContent !=
'undefined')
717 w = (DesktopContent.getWindowWidth()-16-14);
718 screenh = (DesktopContent.getWindowHeight()-16-14);
720 else if(typeof Desktop !=
'undefined' && Desktop.desktop)
722 w = (Desktop.desktop.getDesktopWidth()-16-14);
723 screenh = (Desktop.desktop.getDesktopHeight()-16-14);
736 if(w + Debug._errBoxOffW < 200)
738 Debug._errBoxOffW = 200 - w;
740 w += Debug._errBoxOffW;
742 var h = (screenh - 20) + Debug._errBoxOffH;
745 Debug._errBoxOffH = -200;
750 if(Debug._errBoxOffX + w > screenw)
751 Debug._errBoxOffX = screenw - w;
752 if(Debug._errBoxOffX < minx)
753 Debug._errBoxOffX = minx;
754 if(Debug._errBoxOffY + h > screenh)
755 Debug._errBoxOffY = screenh - h;
756 if(Debug._errBoxOffY < 0)
757 Debug._errBoxOffY = 0;
759 Debug._errBox.style.width = (w) +
"px";
760 Debug._errBox.style.height = (h) +
"px";
761 Debug._errBox.style.left = (Debug._errBoxOffX + offX + 8) +
"px";
762 Debug._errBox.style.top = (Debug._errBoxOffY + offY + 8) +
"px";
763 Debug._errBox.style.marginRight = -(w+10) +
"px";
764 Debug._errBox.style.marginBottom = -(h+80) +
"px";
767 var el = document.getElementsByClassName(Debug._errBoxId +
"-resizeBar")[0];
768 el.style.top = (h+6) +
"px";
769 el = document.getElementsByClassName(Debug._errBoxId +
"-resizeBarLeft")[0];
770 el.style.top = (h+6-10) +
"px";
771 el = document.getElementsByClassName(Debug._errBoxId +
"-resizeBarRight")[0];
772 el.style.left = (w-5) +
"px";
773 el.style.top = (h+6-10) +
"px";
775 el = document.getElementsByClassName(Debug._errBoxId +
"-err")[0];
776 el.style.height = (h-115) +
"px";
781 Debug.downloadMessages =
function() {
783 console.log(
"downloading messages...");
786 var dataStr =
"data:text/txt;charset=utf-8,";
788 var lines = Debug._errBox.innerText.split(
'\n');
789 for(var i=2;i<lines.length-2;++i)
791 dataStr += encodeURIComponent(lines[i] +
"\n");
794 var link = document.createElement(
"a");
795 link.setAttribute(
"href", dataStr);
796 link.setAttribute(
"style",
"display:none");
797 link.setAttribute(
"download",
"otsdaq_Messages_download.txt");
798 document.body.appendChild(link);
802 link.parentNode.removeChild(link);