From 331d9a378198881dcd8c07163be2353d41febe4c Mon Sep 17 00:00:00 2001 From: Stefan Breunig Date: Tue, 12 Feb 2013 10:01:21 +0100 Subject: [PATCH] add debugging/console capability to devices where it is not available or easily accessibile --- code/boot.js | 2 ++ code/chat.js | 16 ++++++++++-- code/debugging.js | 65 +++++++++++++++++++++++++++++++++++++++++++++++ style.css | 1 + 4 files changed, 82 insertions(+), 2 deletions(-) diff --git a/code/boot.js b/code/boot.js index f27ec694..3f90fb63 100644 --- a/code/boot.js +++ b/code/boot.js @@ -193,6 +193,8 @@ window.setupSidebarToggle = function() { // BOOTING /////////////////////////////////////////////////////////// function boot() { + window.debug.console.overwriteNativeIfRequired(); + console.log('loading done, booting'); window.setupStyles(); window.setupMap(); diff --git a/code/chat.js b/code/chat.js index 11b116e9..7b091552 100644 --- a/code/chat.js +++ b/code/chat.js @@ -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(); diff --git a/code/debugging.js b/code/debugging.js index 0a3ce734..b3f12ecc 100644 --- a/code/debugging.js +++ b/code/debugging.js @@ -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('debug'); + $('#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(''); +} + +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 = ''; + var s = 'style="color:'+color+'"'; + var l = '

'+t+''+errorType+''+text+'

'; + $('#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(); +} diff --git a/style.css b/style.css index 652db7a3..03492dc4 100644 --- a/style.css +++ b/style.css @@ -224,6 +224,7 @@ time { display: inline-block; width: 44px; color: #bbb; + overflow: hidden; } mark {