2 * Logger for LoginManager (and general development).
3 * show: - creates the on screen terminal if true
5 * Provides on screen terminal for testing without a developer console.
8 * let log = new Logger(true); // pass true to show output
9 * log.error("write errors like this"); // console.error()
10 * log.normal("write normal logs here"); // console.log()
11 * log.warn("write warning logs here"); // console.warn()
12 * log.debug("write debug logs here"); // console.debug()
15 constructor(show=false) {
16 if (show) $("body").prepend(` <!-- Debug Console -->
17 <div id="console" class="row">
22 <input type="checkbox" checked="true">
23 <span class="lever"></span>
30 <div class="input-field col ">
31 <input id="inputEvent" >
32 <label for="inputEvent">Event</label>
34 <a id="buttonTrigger" class="waves-effect waves-light btn">Trigger</a>
39 <div contentEditable="true" class="terminal"></div>
42 <!-- End Debug Console -->`);
43 this.$log= $("#console .terminal");
44 this.$autoscroll = $("#console input");
45 this.$buttonTrigger = $("#buttonTrigger");
47 window.onerror = (e) => {
51 $(document).ready(() => {
54 this.$log.keypress(function(e) {
57 this.$buttonTrigger.click(() => {
58 let e = $("#inputEvent").val();
59 log.debug("triggering: " + e);
60 $(greeter).trigger(e);
66 if (typeof str == "object") str = JSON.stringify(str,null, 2);
68 str = "[" + moment().format("hh:mm:ss") + "] " + str;
69 str = "<text style='color: " + color + "'>" + str + "</text>";
70 return this.$log.html() + str;
74 this.$log.html(this._parse(str,"white"));
75 if (this.$autoscroll.prop('checked'))
76 this.$log[0].scrollTop = this.$log[0].scrollHeight;
80 this.$log.html(this._parse(str,"red"));
81 if (this.$autoscroll.prop('checked'))
82 this.$log[0].scrollTop = this.$log[0].scrollHeight;
86 this.$log.html(this._parse(str,"yellow"));
87 if (this.$autoscroll.prop('checked'))
88 this.$log[0].scrollTop = this.$log[0].scrollHeight;
92 this.$log.html(this._parse(str,"lightblue"));
93 if (this.$autoscroll.prop('checked'))
94 this.$log[0].scrollTop = this.$log[0].scrollHeight;
98 /************************ Basic Utility Functions *************************/
101 * Scale an image up or down until it's larger than or equal to the viewport
102 * and then center it.
104 var adjustBackground = function ($img) {
105 var viewportWidth = screen.width;
106 var viewportHeight = screen.height;
107 var viewportAspect = viewportWidth/viewportHeight;
108 var imgWidth = $img.width();
109 var imgHeight = $img.height();
110 var imgAspect = imgWidth/imgHeight;
112 /* First determine what is
113 the limiting factor (ie. if the image is wider, then the height is
114 is the limiting factor and needs to be adjustested */
115 if (imgAspect < viewportAspect) {
116 /* The view port is wider compared to its height than
117 the image is compared to the image height meaning
118 the width is the limiting dimension. Therefore we
119 set image width = view ports width use the aspect
120 ratio to set the correct height */
121 $img.width(viewportWidth);
122 $img.height(viewportWidth/imgAspect);
124 /* The image is wider than it is tall compared to the
125 viewport so we adjust the to fit */
126 $img.height(viewportHeight);
127 $img.width(viewportHeight*imgAspect);
129 this.centerImage($img);
132 * Center an image in the viewport
134 var centerImage = function($img) {
135 var overlapWidth = $img.width() - screen.width;
136 var overlapHeight = $img.height() - screen.height;
139 // image overlaps viewport, move the image back
140 // half the length of the overlap
142 position: "relative",
143 right: overlapWidth/2,
144 bottom: overlapHeight/2