add debugging/console capability to devices where it is not available or easily accessibile

This commit is contained in:
Stefan Breunig
2013-02-12 10:01:21 +01:00
parent 52306b033d
commit 331d9a3781
4 changed files with 82 additions and 2 deletions

View File

@ -193,6 +193,8 @@ window.setupSidebarToggle = function() {
// BOOTING ///////////////////////////////////////////////////////////
function boot() {
window.debug.console.overwriteNativeIfRequired();
console.log('loading done, booting');
window.setupStyles();
window.setupMap();

View File

@ -496,8 +496,12 @@ window.chat.request = function() {
window.chat.needMoreMessages = function() {
var activeChat = $('#chat > :visible');
if(scrollBottom(activeChat) !== 0 || activeChat.scrollTop() !== 0) return;
var activeTab = $('#chatcontrols .active').text();
if(activeTab === 'debug') return;
console.log('no scrollbar in active chat, requesting more msgs');
if($('#chatcontrols a:last.active').length)
if(activeTab === 'faction')
chat.requestOldFaction();
else
chat.requestOldPublic();
@ -507,6 +511,7 @@ window.chat.needMoreMessages = function() {
window.chat.chooser = function(event) {
var t = $(event.target);
var tt = t.text();
var span = $('#chatinput span');
$('#chatcontrols .active').removeClass('active');
@ -537,6 +542,8 @@ window.chat.chooser = function(event) {
break;
}
if(!elm) throw('chat button handled by chat.chooser, yet it is null');
elm.show();
if(elm.data('needsScrollTop')) {
elm.data('ignoreNextScroll', true);
@ -580,7 +587,10 @@ window.chat.setup = function() {
$('#chatcontrols, #chat, #chatinput').show();
$('#chatcontrols a:first').click(window.chat.toggle);
$('#chatcontrols a:not(:first)').click(window.chat.chooser);
$('#chatcontrols a').each(function(ind, elm) {
if($.inArray($(elm).text(), ['automated', 'public', 'faction']) !== -1)
$(elm).click(window.chat.chooser);
});
$('#chatinput').click(function() {
@ -665,6 +675,8 @@ window.chat.postMsg = function() {
var msg = $.trim($('#chatinput input').val());
if(!msg || msg === '') return;
if(c === 'debug') return new Function (msg)();
var public = c === 'public';
var latlng = map.getCenter();

View File

@ -42,3 +42,68 @@ window.debug.forceSync = function() {
updateGameScore();
requestData();
}
window.debug.console = function() {
$('#debugconsole').text();
}
window.debug.console.create = function() {
if($('#debugconsole').length) return;
$('#chatcontrols').append('<a>debug</a>');
$('#chatcontrols a:last').click(function() {
$('#chatinput span').css('cssText', 'color: #bbb !important').text('debug:');
$('#chat > div').hide();
$('#debugconsole').show();
$('#chatcontrols .active').removeClass('active');
$(this).addClass('active');
});
$('#chat').append('<div id="debugconsole" style="display: none"></div>');
}
window.debug.console.renderLine = function(text, errorType) {
debug.console.create();
switch(errorType) {
case 'error': var color = '#FF424D'; break;
case 'warning': var color = '#FFDE42'; break;
case 'alert': var color = '#42FF90'; break;
default: var color = '#eee';
}
if(typeof text !== 'string' && typeof text !== 'number') text = JSON.stringify(text);
var d = new Date();
var ta = d.toLocaleTimeString(); // print line instead maybe?
var tb = d.toLocaleString();
var t = '<time title="'+tb+'" data-timestamp="'+d.getTime()+'">'+ta+'</time>';
var s = 'style="color:'+color+'"';
var l = '<p>'+t+'<mark '+s+'>'+errorType+'</mark><span>'+text+'</span></p>';
$('#debugconsole').prepend(l);
}
window.debug.console.log = function(text) {
debug.console.renderLine(text, 'notice');
}
window.debug.console.warn = function(text) {
debug.console.renderLine(text, 'warning');
}
window.debug.console.error = function(text) {
debug.console.renderLine(text, 'error');
}
window.debug.console.alert = function(text) {
debug.console.renderLine(text, 'alert');
}
window.debug.console.overwriteNative = function() {
window.debug.console.create();
window.console = function() {}
window.console.log = window.debug.console.log;
window.console.warn = window.debug.console.warn;
window.console.error = window.debug.console.error;
window.alert = window.debug.console.alert;
}
window.debug.console.overwriteNativeIfRequired = function() {
if(!window.console || L.Browser.mobile)
window.debug.console.overwriteNative();
}

View File

@ -224,6 +224,7 @@ time {
display: inline-block;
width: 44px;
color: #bbb;
overflow: hidden;
}
mark {