Wegwichtel/api/console.js
2026-06-16 09:17:23 +02:00

56 lines
1.9 KiB
JavaScript
Executable File

/****************************************************************************************************************
* CLASS console: helper to make console-object available if not present *
* implemented as singleton-object *
* *
* methods: debug(args: variable number and type of arguments):void - dump parameters to console *
* *
* remarks: creates a css-styled div fixed on bottom of visible screen, if console-object is created *
****************************************************************************************************************/
if (!console)
{
console = {
create: function() {
$('body').append($('<div id="console"></div>'));
$('head').append($([
'<style type="text/css">',
' #console {',
' position: fixed;',
' bottom: 0;',
' left: 0;',
' right: 0;',
' z-index: 9998;',
' height: 12em;',
' line-height: 1.2em;',
' font-size: 0.8em;',
' background-color: rgb(220,220,220);',
' overflow-y: scroll;',
' }',
'</style>'
].join("\n")));
},
debug: function() {
var time = new Date();
$.each(arguments, function(key, data) {
$('#console').html(
$('#console').html()
+(
'('
+ ('0' + time.getHours()).substr(-2)
+ ':'
+ ('0' + time.getMinutes()).substr(-2)
+ ':'
+ ('0' + time.getSeconds()).substr(-2)
+ ') '
+ JSON.stringify(data)
+ ' ['
+ typeof(data)
+ ']'
).replace(/[\r\n]{1,1}/g, '<br />')
+'<br />'
).scrollTop($("#console").prop("scrollHeight"))
});
}
}
}