-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.js
56 lines (46 loc) · 1.75 KB
/
log.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
function addLog( msg, st ) { /** Log a message */
var tbl = $( '#eventLogBody' )[0];
var row = tbl.insertRow();
$( row ).attr( 'id', context.logItems );
var theTimeIsNow = thisDate();
newCell( row, 0, theTimeIsNow );
newCell( row, 1, msg );
newCell( row, 2, st );
$( '#logTime' ).html( theTimeIsNow );
setBottom();
}
function thisDate() { /** Construct a timestamp */
// now in form yyyy-dd-mm hh:mm:ss
var dte = new Date();
var dteFmt = dte.getFullYear() + "-" + zp( dte.getMonth() + 1 ) + "-" + zp( dte.getDate() ) + " " +
zp( dte.getHours() ) + ":" + zp( dte.getMinutes() ) + ":" + zp( dte.getSeconds() );
return dteFmt;
}
// async
function toast( msg, st ){ /** Post up message then log it */
toastWho( "#toaster", msg, st )
}
function toastWho( toste, msg, st ) {
$( toste ).html( msg );
addLog( msg, st );
$( toste ).addClass( 'show' );
console.log( msg );
setTimeout( function(){ // After 5 seconds, remove the show class from DIV
$( toste ).removeClass( 'show' );
}, 5000 );
}
function zp( num ) { /** Zero pad 2 digit numbers */
return ( "0" + num ).slice( -2 );
}
function newCell( row, idx, val ) { /** Append cell to table row */
var cell = row.insertCell( idx );
cell.innerHTML = val;
$( cell ).addClass( 'col-' + idx );
return cell;
}
function setBottom() { /** auto scroll to bottom */
context.bottom = $( "input[name='bottomFeeder']:checked" ).val();
if( context.bottom == 'on' ) {
$( '.logBody' ).scrollTop( $( '.logBody' )[0].scrollHeight );
}
}