add debugging/console capability to devices where it is not available or easily accessibile
This commit is contained in:
@ -193,6 +193,8 @@ window.setupSidebarToggle = function() {
|
|||||||
// BOOTING ///////////////////////////////////////////////////////////
|
// BOOTING ///////////////////////////////////////////////////////////
|
||||||
|
|
||||||
function boot() {
|
function boot() {
|
||||||
|
window.debug.console.overwriteNativeIfRequired();
|
||||||
|
|
||||||
console.log('loading done, booting');
|
console.log('loading done, booting');
|
||||||
window.setupStyles();
|
window.setupStyles();
|
||||||
window.setupMap();
|
window.setupMap();
|
||||||
|
16
code/chat.js
16
code/chat.js
@ -496,8 +496,12 @@ window.chat.request = function() {
|
|||||||
window.chat.needMoreMessages = function() {
|
window.chat.needMoreMessages = function() {
|
||||||
var activeChat = $('#chat > :visible');
|
var activeChat = $('#chat > :visible');
|
||||||
if(scrollBottom(activeChat) !== 0 || activeChat.scrollTop() !== 0) return;
|
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');
|
console.log('no scrollbar in active chat, requesting more msgs');
|
||||||
if($('#chatcontrols a:last.active').length)
|
|
||||||
|
if(activeTab === 'faction')
|
||||||
chat.requestOldFaction();
|
chat.requestOldFaction();
|
||||||
else
|
else
|
||||||
chat.requestOldPublic();
|
chat.requestOldPublic();
|
||||||
@ -507,6 +511,7 @@ window.chat.needMoreMessages = function() {
|
|||||||
window.chat.chooser = function(event) {
|
window.chat.chooser = function(event) {
|
||||||
var t = $(event.target);
|
var t = $(event.target);
|
||||||
var tt = t.text();
|
var tt = t.text();
|
||||||
|
|
||||||
var span = $('#chatinput span');
|
var span = $('#chatinput span');
|
||||||
|
|
||||||
$('#chatcontrols .active').removeClass('active');
|
$('#chatcontrols .active').removeClass('active');
|
||||||
@ -537,6 +542,8 @@ window.chat.chooser = function(event) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!elm) throw('chat button handled by chat.chooser, yet it is null');
|
||||||
|
|
||||||
elm.show();
|
elm.show();
|
||||||
if(elm.data('needsScrollTop')) {
|
if(elm.data('needsScrollTop')) {
|
||||||
elm.data('ignoreNextScroll', true);
|
elm.data('ignoreNextScroll', true);
|
||||||
@ -580,7 +587,10 @@ window.chat.setup = function() {
|
|||||||
$('#chatcontrols, #chat, #chatinput').show();
|
$('#chatcontrols, #chat, #chatinput').show();
|
||||||
|
|
||||||
$('#chatcontrols a:first').click(window.chat.toggle);
|
$('#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() {
|
$('#chatinput').click(function() {
|
||||||
@ -665,6 +675,8 @@ window.chat.postMsg = function() {
|
|||||||
var msg = $.trim($('#chatinput input').val());
|
var msg = $.trim($('#chatinput input').val());
|
||||||
if(!msg || msg === '') return;
|
if(!msg || msg === '') return;
|
||||||
|
|
||||||
|
if(c === 'debug') return new Function (msg)();
|
||||||
|
|
||||||
var public = c === 'public';
|
var public = c === 'public';
|
||||||
var latlng = map.getCenter();
|
var latlng = map.getCenter();
|
||||||
|
|
||||||
|
@ -42,3 +42,68 @@ window.debug.forceSync = function() {
|
|||||||
updateGameScore();
|
updateGameScore();
|
||||||
requestData();
|
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();
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user