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 var source = window.location.href;
130 source = source.substr(source.lastIndexOf(
'/'));
131 source = source.substr(0,source.indexOf(
'?'));
132 console.log(
"%c" + type +
"-Priority" +
133 ":\t " + Debug.lastLog +
" from " + source +
":\n" +
134 Debug.lastLogger +
"::\t" + str,
135 num == 0?
"color:#F30;"
136 :(num == 1?
"color:#F70"
137 :(num < 99?
"color:#092":
"color:#333")));
141 Debug.errorPop(str,num);
148 function localCallOutDebugLocales(str)
155 while((j = str.indexOf(
'[',i)) > 0 && (k = str.indexOf(
']',i)) > 0)
170 if((str[j-3] ==
'.' && str[j-2] ==
'h') ||
171 ((str[j-4] ==
'.' || str[j-4] ==
'i') &&
172 str[j-3] ==
'c' && str[j-2] ==
'c'))
175 for(l = j-3; l >= i; --l)
176 if(!((str[l] >=
'a' && str[l] <=
'z') ||
177 (str[l] >=
'A' && str[l] <=
'Z') ||
178 (str[l] >=
'0' && str[l] <=
'9') ||
190 returnStr += str.substr(i,l-i);
193 returnStr +=
"<br><label class='" +
194 Debug._errBoxId +
"-localCallOut'>";
197 returnStr += str.substr(l,k+1-l);
200 returnStr +=
"</label><br>";
203 while(k+1 < str.length &&
204 (str[k+1] ==
'\n' || str[k+1] ==
'\t')) ++k;
208 returnStr += str.substr(i,k+1-i);
220 returnStr += str.substr(i);
234 console.log =
function(){};
235 Debug.log =
function(){};
236 Debug.logv =
function(){};
240 Debug.log(
"Debug mode is on at level: " + Debug.level);
241 Debug.log(
"This is an example for posterity that is not printed due to debug priority.",Debug.level+1);
250 Debug._errBoxId =
"Debug-error-box";
251 Debug._errBoxOffX = 0;
252 Debug._errBoxOffY = 0;
253 Debug._errBoxOffW = 0;
254 Debug._errBoxOffH = 0;
257 Debug.errorPopConditionString =
function(str) {
258 return str.replace(/\n/g ,
"<br>").replace(/\t/g,
" ");
264 Debug.errorPop =
function(err,severity) {
266 var errBoxAlpha =
"1.0";
272 var el = document.getElementById(Debug._errBoxId);
275 var body = document.getElementsByTagName(
"BODY")[0];
279 window.setTimeout(
function() { Debug.errorPop(err,severity)}, 1000);
284 el = document.createElement(
"div");
285 el.setAttribute(
"id", Debug._errBoxId);
286 el.style.display =
"none";
287 var str =
"<a class='" +
289 "-header' onclick='javascript:Debug.closeErrorPop();event.stopPropagation();' onmouseup='event.stopPropagation();'>Close Errors</a>";
293 "-moveBar' style='" +
294 "position:absolute;width:100%;height:15px;top:0;left:0;background-color:rgb(128, 128, 128);cursor:move;" +
295 "outline: none; /* to stop firefox selection*/ -webkit-user-select: none; /* prevent selection*/ -moz-user-select: none; user-select: none;" +
297 "onmousedown='javascript:Debug.handleErrorMoveStart(event);event.stopPropagation();' " +
298 "title='Click and drag to reposition this popup window.' " +
302 "<div style='color:white;font-size:16px;padding-bottom:5px;'>" +
303 "Note: Newest messages are at the top." +
304 "<label style='color:white;font-size:11px;'><br>(Press [ESC] to close and [SHIFT + ESC] to re-open)</font>" +
305 "<div id='downloadIconDiv' onmouseup='Debug.downloadMessages()' title='Download messages to text file.' style='float: right; margin: -10px 30px -100px -100px; cursor: pointer'>" +
307 "<div style='display: block; margin-left: 3px; height:7px; width: 6px; background-color: white;'></div>" +
308 "<div style='display: block; width: 0; height: 0; border-left: 6px solid transparent; border-right: 6px solid transparent; border-top: 8px solid white;'></div>" +
309 "<div style='position: relative; top: 5px; width: 12px; height: 2px; display: block; background-color: white;'></div>" +
319 str +=
"<div class='" + Debug._errBoxId +
"-resizeBarLeft' " +
321 "background-color:rgb(128, 128, 128);position:absolute;width:15px;height:15px;top:-1000px;left:0;cursor:nesw-resize;" +
322 "outline: none; /* to stop firefox selection*/ -webkit-user-select: none; /* prevent selection*/ -moz-user-select: none; user-select: none;" +
324 "onmousedown='javascript:Debug.handleErrorResizeStart(event,1,1);event.stopPropagation();' " +
325 "title='Click and drag to resize vertically this popup window.' " +
327 str +=
"<div class='" + Debug._errBoxId +
"-resizeBar' " +
329 "background-color:transparent;position:absolute;width:100%;height:5px;top:-1000px;left:15px;cursor:ns-resize;" +
330 "outline: none; /* to stop firefox selection*/ -webkit-user-select: none; /* prevent selection*/ -moz-user-select: none; user-select: none;" +
332 "onmousedown='javascript:Debug.handleErrorResizeStart(event);event.stopPropagation();' " +
333 "title='Click and drag to resize this popup window.' " +
335 str +=
"<div class='" + Debug._errBoxId +
"-resizeBarRight' " +
337 "background-color:rgb(128, 128, 128);position:absolute;width:15px;height:15px;top:-1000px;left:0;cursor:nwse-resize;" +
338 "outline: none; /* to stop firefox selection*/ -webkit-user-select: none; /* prevent selection*/ -moz-user-select: none; user-select: none;" +
340 "onmousedown='javascript:Debug.handleErrorResizeStart(event,1);event.stopPropagation();' " +
341 "title='Click and drag to resize this popup window.' " +
344 body.appendChild(el);
348 function localDebugKeyDownListener(e)
356 if(!e.shiftKey && e.keyCode == 27)
360 Debug.closeErrorPop();
362 else if(e.shiftKey && e.keyCode == 27)
366 Debug.bringBackErrorPop();
370 document.body.removeEventListener(
"keydown",localDebugKeyDownListener);
371 document.body.addEventListener(
"keydown",localDebugKeyDownListener);
378 css +=
"#" + Debug._errBoxId +
" *" +
379 "{font-family: 'Comfortaa', arial;" +
380 "font-weight: 200;" +
382 "color: rgb(255,200,100);" +
383 "-webkit-user-select: text;" +
384 "-moz-user-select: text;" +
385 "user-select: text;" +
390 css +=
"#" + Debug._errBoxId +
" a" +
391 ", #" + Debug._errBoxId +
" center b" +
392 "{color: white; text-decoration: none; font-weight: bold;" +
393 "font-size: 18px; font-family: 'Comfortaa', arial;" +
395 css +=
"#" + Debug._errBoxId +
" a:hover" +
396 "{text-decoration: underline;" +
401 css +=
"#" + Debug._errBoxId +
" i" +
402 ", #" + Debug._errBoxId +
" u" +
404 "font-size: 18px; font-family: 'Comfortaa', arial;" +
406 css +=
"#" + Debug._errBoxId +
" b" +
408 "font-weight: bold;" +
409 "color: rgb(255, 231, 187);" +
413 css +=
"#" + Debug._errBoxId +
415 "position: absolute; display: none; border: 2px solid gray;" +
416 "background-color: rgba(153,0,51, " + errBoxAlpha +
"); overflow-y: hidden;" +
417 "overflow-x: hidden; padding: 5px; -moz-border-radius: 2px;" +
418 "-webkit-border-radius: 2px; border-radius: 2px;" +
419 "font-size: 18px; z-index: 2147483647;" +
420 "font-family: 'Comfortaa', arial; text-align: center;" +
421 "left: 8px; top: 8px; margin-right: 8px; " +
425 css +=
"#" + Debug._errBoxId +
"-err" +
427 "color: rgb(255,200,100); font-size: 18px;" +
428 "font-family: 'Comfortaa', arial;" +
429 "left: 8px; top: 8px; margin-right: 8px;" +
430 "margin-bottom:-12px;" +
431 "text-align: left;" +
432 "overflow-y: scroll;" +
433 "overflow-x: auto;" +
435 "-webkit-user-select: text;" +
436 "-moz-user-select: text;" +
437 "user-select: text;" +
440 css +=
"#" + Debug._errBoxId +
"-err i" +
442 ",#" + Debug._errBoxId +
"-err u" +
445 "color: rgb(255,200,100); font-size: 18px;" +
446 "font-family: 'Comfortaa', arial;" +
447 "text-align: left;" +
448 "-webkit-user-select: text;" +
449 "-moz-user-select: text;" +
450 "user-select: text;" +
456 "#" + Debug._errBoxId +
"-err div" +
458 "color: rgb(255,200,100); font-size: 18px;" +
459 "font-family: 'Comfortaa', arial;" +
460 "left: 8px, top: 8px; margin-right: 8px;" +
461 "text-align: left;" +
462 "-webkit-user-select: text;" +
463 "-moz-user-select: text;" +
464 "user-select: text;" +
467 css +=
"#" + Debug._errBoxId +
"-err b" +
469 "color: rgb(255,225,200); font-size: 18px;" +
470 "font-family: 'Comfortaa', arial;" +
471 "text-align: left;" +
472 "-webkit-user-select: text;" +
473 "-moz-user-select: text;" +
474 "user-select: text;" +
477 css +=
"#" + Debug._errBoxId +
" ." + Debug._errBoxId +
"-localCallOut" +
478 "{font-size: 10px;}\n\n";
481 var style = document.createElement(
'style');
483 if (style.styleSheet) {
484 style.styleSheet.cssText = css;
486 style.appendChild(document.createTextNode(css));
489 document.getElementsByTagName(
'head')[0].appendChild(style);
491 window.addEventListener(
"resize",localResize);
492 window.addEventListener(
"scroll",localScroll);
493 window.addEventListener(
"mouseup",Debug.handleErrorMoveStop);
494 window.addEventListener(
"mousemove",Debug.handleErrorMove);
501 var el = document.getElementById(Debug._errBoxId +
"-err");
502 var str = el.innerHTML;
504 var wasAlreadyContent =
false;
508 wasAlreadyContent =
true;
510 var tstr = d.toLocaleTimeString();
511 tstr = tstr.substring(0,tstr.lastIndexOf(
' ')) +
512 (tstr[tstr.length-2]==
'A'?
"am":
"pm");
514 if(severity == Debug.TIP_PRIORITY)
516 (wasAlreadyContent?
"<br>...<br>":
"") +
517 "<label style='color:white;font-size:16px;'>" +
518 d.toLocaleDateString() +
519 " " + tstr +
" (Tip) :</label><br>" +
520 Debug.errorPopConditionString(err);
522 str =
"<label style='color:white;font-size:16px;'>" +
523 d.toLocaleDateString() +
525 (severity == Debug.INFO_PRIORITY ?
'(Info)':
'')+
526 (severity == Debug.WARN_PRIORITY ?
'(Warning)':
'') +
528 Debug.errorPopConditionString(err) +
529 (wasAlreadyContent?
"<br>...<br>":
"") +
535 function localResize()
537 Debug._errBoxOffX = 0;
538 Debug._errBoxOffY = 0;
539 Debug._errBoxOffH = 0;
540 Debug._errBoxOffW = 0;
541 Debug.handleErrorResize();
543 function localScroll()
545 Debug.handleErrorResize();
547 Debug.handleErrorResize();
550 Debug._errBox.style.display =
"block";
554 var els = document.getElementsByClassName(Debug._errBoxId +
"-header");
558 case Debug.TIP_PRIORITY:
560 if(wasAlreadyContent &&
561 (el.innerHTML ==
"Close Errors" ||
562 el.innerHTML ==
"Close Warnings" ||
563 el.innerHTML ==
"Close Info"))
565 el.innerHTML =
"Close Tooltip";
566 Debug._errBox.style.backgroundColor =
"rgba(0, 49, 99, " + errBoxAlpha +
")";
568 case Debug.INFO_PRIORITY:
570 if(wasAlreadyContent &&
571 (el.innerHTML ==
"Close Errors" ||
572 el.innerHTML ==
"Close Warnings"))
574 el.innerHTML =
"Close Info";
575 Debug._errBox.style.backgroundColor =
"rgba(0,153,51, " + errBoxAlpha +
")";
577 case Debug.WARN_PRIORITY:
579 if(wasAlreadyContent &&
580 el.innerHTML ==
"Close Errors")
582 el.innerHTML =
"Close Warnings";
583 Debug._errBox.style.backgroundColor =
"rgba(160, 79, 0, " + errBoxAlpha +
")";
586 el.innerHTML =
"Close Errors";
587 Debug._errBox.style.backgroundColor =
"rgba(153,0,51, " + errBoxAlpha +
")";
589 els[1].innerHTML = el.innerHTML;
592 Debug._errBoxLastContent =
"";
595 Debug.closeErrorPop =
function() {
596 document.getElementById(Debug._errBoxId).style.display =
"none";
597 Debug._errBoxLastContent = document.getElementById(Debug._errBoxId +
"-err").innerHTML;
598 document.getElementById(Debug._errBoxId +
"-err").innerHTML =
"";
602 Debug.bringBackErrorPop =
function() {
603 document.getElementById(Debug._errBoxId +
"-err").innerHTML = Debug._errBoxLastContent;
604 document.getElementById(Debug._errBoxId).style.display =
"block";
608 Debug._errBoxOffMoveStartX = -1;
609 Debug._errBoxOffMoveStartY;
610 Debug._errBoxOffResizeStartX = -1;
611 Debug._errBoxOffResizeStartY = -1;
613 Debug.handleErrorMoveStart =
function(e) {
614 Debug.log(
"Move Start");
615 Debug._errBoxOffMoveStartX = e.screenX - Debug._errBoxOffX;
616 Debug._errBoxOffMoveStartY = e.screenY - Debug._errBoxOffY;
620 Debug.handleErrorResizeStart =
function(e,resizeW,moveLeft) {
621 Debug.log(
"Resize Start");
622 Debug._errBoxOffResizeStartY = e.screenY - Debug._errBoxOffH;
625 Debug._errBoxOffMoveStartX = e.screenX - Debug._errBoxOffX;
626 Debug._errBoxOffResizeStartX = e.screenX + Debug._errBoxOffW;
629 Debug._errBoxOffResizeStartX = e.screenX - Debug._errBoxOffW;
634 Debug.handleErrorMoveStop =
function(e) {
637 if(Debug._errBoxOffResizeStartY != -1)
639 Debug.log(
"Resize Stop");
640 Debug._errBoxOffH = e.screenY - Debug._errBoxOffResizeStartY;
641 Debug._errBoxOffResizeStartY = -1;
643 if(Debug._errBoxOffMoveStartX != -1)
645 Debug._errBoxOffX = e.screenX - Debug._errBoxOffMoveStartX;
646 Debug._errBoxOffW = Debug._errBoxOffResizeStartX - e.screenX;
647 Debug._errBoxOffMoveStartX = -1;
648 Debug._errBoxOffResizeStartX = -1;
650 else if(Debug._errBoxOffResizeStartX != -1)
652 Debug._errBoxOffW = e.screenX - Debug._errBoxOffResizeStartX;
653 Debug._errBoxOffResizeStartX = -1;
655 Debug.handleErrorResize();
657 else if(Debug._errBoxOffMoveStartX != -1)
659 Debug.log(
"Move Stop");
660 Debug._errBoxOffX = e.screenX - Debug._errBoxOffMoveStartX;
661 Debug._errBoxOffY = e.screenY - Debug._errBoxOffMoveStartY;
662 Debug._errBoxOffMoveStartX = -1;
663 Debug.handleErrorResize();
670 Debug.handleErrorMove =
function(e) {
672 if(Debug._errBoxOffMoveStartX == -1 &&
673 Debug._errBoxOffResizeStartY == -1)
return;
677 Debug._errBoxOffMoveStartX = -1;
678 Debug._errBoxOffResizeStartY = -1;
679 Debug._errBoxOffResizeStartX = -1;
683 if(Debug._errBoxOffResizeStartY != -1)
685 Debug.log(
"Resize " + e.buttons);
686 Debug._errBoxOffH = e.screenY - Debug._errBoxOffResizeStartY;
688 if(Debug._errBoxOffMoveStartX != -1)
690 Debug._errBoxOffX = e.screenX - Debug._errBoxOffMoveStartX;
691 Debug._errBoxOffW = Debug._errBoxOffResizeStartX - e.screenX;
693 else if(Debug._errBoxOffResizeStartX != -1)
694 Debug._errBoxOffW = e.screenX - Debug._errBoxOffResizeStartX;
696 Debug.handleErrorResize();
698 else if(Debug._errBoxOffMoveStartX != -1)
700 Debug.log(
"Move " + e.buttons);
701 Debug._errBoxOffX = e.screenX - Debug._errBoxOffMoveStartX;
702 Debug._errBoxOffY = e.screenY - Debug._errBoxOffMoveStartY;
703 Debug.handleErrorResize();
709 Debug.handleErrorResize =
function() {
712 var offX = document.documentElement.scrollLeft || document.body.scrollLeft || 0;
713 var offY = document.documentElement.scrollTop || document.body.scrollTop || 0;
718 if(typeof DesktopContent !=
'undefined')
720 w = (DesktopContent.getWindowWidth()-16-14);
721 screenh = (DesktopContent.getWindowHeight()-16-14);
723 else if(typeof Desktop !=
'undefined' && Desktop.desktop)
725 w = (Desktop.desktop.getDesktopWidth()-16-14);
726 screenh = (Desktop.desktop.getDesktopHeight()-16-14);
739 if(w + Debug._errBoxOffW < 200)
741 Debug._errBoxOffW = 200 - w;
743 w += Debug._errBoxOffW;
745 var h = (screenh - 20) + Debug._errBoxOffH;
748 Debug._errBoxOffH = -200;
753 if(Debug._errBoxOffX + w > screenw)
754 Debug._errBoxOffX = screenw - w;
755 if(Debug._errBoxOffX < minx)
756 Debug._errBoxOffX = minx;
757 if(Debug._errBoxOffY + h > screenh)
758 Debug._errBoxOffY = screenh - h;
759 if(Debug._errBoxOffY < 0)
760 Debug._errBoxOffY = 0;
762 Debug._errBox.style.width = (w) +
"px";
763 Debug._errBox.style.height = (h) +
"px";
764 Debug._errBox.style.left = (Debug._errBoxOffX + offX + 8) +
"px";
765 Debug._errBox.style.top = (Debug._errBoxOffY + offY + 8) +
"px";
766 Debug._errBox.style.marginRight = -(w+10) +
"px";
767 Debug._errBox.style.marginBottom = -(h+80) +
"px";
770 var el = document.getElementsByClassName(Debug._errBoxId +
"-resizeBar")[0];
771 el.style.top = (h+6) +
"px";
772 el = document.getElementsByClassName(Debug._errBoxId +
"-resizeBarLeft")[0];
773 el.style.top = (h+6-10) +
"px";
774 el = document.getElementsByClassName(Debug._errBoxId +
"-resizeBarRight")[0];
775 el.style.left = (w-5) +
"px";
776 el.style.top = (h+6-10) +
"px";
778 el = document.getElementsByClassName(Debug._errBoxId +
"-err")[0];
779 el.style.height = (h-115) +
"px";
784 Debug.downloadMessages =
function() {
786 console.log(
"downloading messages...");
789 var dataStr =
"data:text/txt;charset=utf-8,";
791 var lines = Debug._errBox.innerText.split(
'\n');
792 for(var i=2;i<lines.length-2;++i)
794 dataStr += encodeURIComponent(lines[i] +
"\n");
797 var link = document.createElement(
"a");
798 link.setAttribute(
"href", dataStr);
799 link.setAttribute(
"style",
"display:none");
800 link.setAttribute(
"download",
"otsdaq_Messages_download.txt");
801 document.body.appendChild(link);
805 link.parentNode.removeChild(link);