Commit 85b5cecf authored by Ricco Førgaard's avatar Ricco Førgaard
Browse files

Added a Firebug like console.

This is nice to have on clients that don't have a JavaScript console.
Turn it on in the config (see config example).
parent 33d920a1
window.config = {
baseUrl: 'http://129.177.92.208/api/'
baseUrl: 'http://129.177.92.208/api/',
useAlternativeConsole: false
}
......@@ -83,6 +83,11 @@
'nesstartouch/VariableMetadata',
'dojo/domReady!'],
function(parser) {
if (window.config.useAlternativeConsole) {
require(['nesstartouch/_Console'], function(Console) {
new Console();
});
}
parser.parse();
}
);
......
define(['dojo/_base/declare'],
function(declare) {
return declare('nesstartouch.Console', null, {
numberOfAttributesToShow: 9,
constructor: function() {
this._createOutputConsoleStyling();
this._createOutputConsole();
var that = this;
window.console.log = function() {
for (var x = 0; x < arguments.length; x++) {
var arg = arguments[x];
var line;
if (typeof arg == 'object') {
line = that.objectTraverser(arg);
} else {
line = document.createElement('p');
line.innerHTML = arg;
}
that.output.appendChild(line);
line.scrollIntoView(false);
}
}
window.onerror = function(msg, url, line) {
window.console.log('Error: ' + msg + ' (' + url + ':' + line + ')');
}
},
objectTraverser: function(object) {
var ul = document.createElement('ul');
var limit = 0;
for (att in object) {
var type = typeof object[att];
var value = object[att];
var item = att + '(' + type + '): ' + value;
var li = document.createElement('li');
li.innerHTML = item;
ul.appendChild(li);
limit++;
if (limit > this.numberOfAttributesToShow) {
break;
}
}
return ul;
},
_createOutputConsoleStyling: function() {
var style = document.createElement('style');
style.innerHTML = "\
#console { \
background-color: #fff; \
border: 1px solid #333; \
height: 250px; \
width: 100%; \
z-index: 9000; \
position: fixed; \
bottom: 5px; \
} \
#console p { \
border-bottom: 1px solid #bbb;\
line-height: 16px; \
}";
var head = document.getElementsByTagName('head')[0];
head.appendChild(style);
},
_createOutputConsole: function() {
this.output = document.createElement('div');
this.output.setAttribute('id', 'console');
this.output.setAttribute('class', 'scrollable-view');
document.body.appendChild(this.output);
},
});
}
);
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment