Browse Source

Custom console-shim. Better debugging

Nathaniel van Diepen 10 years ago
parent
commit
eceb99cb5c
5 changed files with 120 additions and 16 deletions
  1. 24 3
      app/www/css/style.css
  2. 2 1
      app/www/index.html
  3. 0 12
      app/www/js/console-shim-min.js
  4. 54 0
      app/www/js/consoleshim.js
  5. 40 0
      app/www/js/omnomirc.js

+ 24 - 3
app/www/css/style.css

@@ -37,6 +37,7 @@ html,body{
 	font-size: 24px;
 	margin-top: -5px;
 	font-family: Arial,Liberation Sans,DejaVu Sans,sans-serif;
+	cursor: pointer;
 }
 .close-button:hover{
 	color: red;
@@ -62,12 +63,26 @@ html,body{
 	display: table-cell;
 	text-align: right;
 }
-#content{
+#content,#console-log{
 	width: 100%;
 	height: calc(100% - 61px);
 	top: 41px;
 	left: 0;
 }
+#console-log{
+	display: none;
+}
+#console-log-pre{
+	height: 100%;
+	margin: 0;
+	padding: 2px;
+}
+#console-log-controls{
+	position: absolute;
+	bottom: 22px;
+	width: 100%;
+	overflow: hidden;
+}
 #settings,#users{
 	bottom: 0;
 	height: 18px;
@@ -80,6 +95,12 @@ html,body{
 #settings span,#users span{
 	cursor: pointer;
 }
+#settings.open span,#users.open.span{
+	cursor: default;
+}
+#settings.open span.close-button,#users.open span.close-button{
+	cursor: pointer;
+}
 #users{
 	right: 0;
 	width: 36px;
@@ -138,13 +159,13 @@ html,body{
 #send.clicked{
 	background-color: red;
 }
-#content,#head,#users,#entry,#input,#send,#settings{
+#console-log,#content,#head,#users,#entry,#input,#send,#settings{
 	border-color: black;
 	border-width: 1px;
 	position: absolute;
 	overflow: hidden;
 }
-#content{
+#console-log,#content{
 	overflow-y: scroll;
 }
 #users,#input,#send,#settings{

+ 2 - 1
app/www/index.html

@@ -3,7 +3,7 @@
 	<head>
 		<title>OmnomIRC3</title>
 		<meta charset='utf-8'> 
-		<script type="text/javascript" src="js/console-shim-min.js"></script>
+		<script type="text/javascript" src="js/consoleshim.js"></script>
 		<script type="text/javascript" src="js/html5shiv.js"></script>
 		<script type="text/javascript" src="js/html5shiv-printshiv.js"></script>
 		<script src="http://bestiejs.github.io/json3/lib/json3.js"></script>
@@ -47,5 +47,6 @@
 				<ul id="settings-list"></ul>
 			</div>
 		</div>
+		<div id="console-log"></div>
 	</body>
 </html>

+ 0 - 12
app/www/js/console-shim-min.js

@@ -1,12 +0,0 @@
-/*
- console-shim 1.0.2
- https://github.com/kayahr/console-shim
- Copyright (C) 2011 Klaus Reimer <[email protected]>
- Licensed under the MIT license
- (See http://www.opensource.org/licenses/mit-license)
-*/
-'use strict';function f(){return function(){}}
-(function(){function c(a,l,b){var c=Array.prototype.slice.call(arguments,2);return function(){var b=c.concat(Array.prototype.slice.call(arguments,0));a.apply(l,b)}}window.console||(window.console={});var a=window.console;if(!a.log)if(window.log4javascript){var b=log4javascript.getDefaultLogger();a.log=c(b.info,b);a.debug=c(b.debug,b);a.info=c(b.info,b);a.warn=c(b.warn,b);a.error=c(b.error,b)}else a.log=f();a.debug||(a.debug=a.log);a.info||(a.info=a.log);a.warn||(a.warn=a.log);a.error||(a.error=a.log);
-if(null!=window.__consoleShimTest__||eval("/*@cc_on @_jscript_version \x3c\x3d 9@*/"))b=function(d){var b,e,c;d=Array.prototype.slice.call(arguments,0);c=d.shift();e=d.length;if(1<e&&!1!==window.__consoleShimTest__){"string"!=typeof d[0]&&(d.unshift("%o"),e+=1);for(b=(b=d[0].match(/%[a-z]/g))?b.length+1:1;b<e;b+=1)d[0]+=" %o"}Function.apply.call(c,a,d)},a.log=c(b,window,a.log),a.debug=c(b,window,a.debug),a.info=c(b,window,a.info),a.warn=c(b,window,a.warn),a.error=c(b,window,a.error);a.assert||(a.assert=
-function(){var d=Array.prototype.slice.call(arguments,0);d.shift()||(d[0]="Assertion failed: "+d[0],a.error.apply(a,d))});a.dir||(a.dir=a.log);a.dirxml||(a.dirxml=a.log);a.exception||(a.exception=a.error);if(!a.time||!a.timeEnd){var g={};a.time=function(a){g[a]=(new Date).getTime()};a.timeEnd=function(b){var c=g[b];c&&(a.log(b+": "+((new Date).getTime()-c)+"ms"),delete g[b])}}a.table||(a.table=function(b,c){var e,g,j,h,k;if(b&&b instanceof Array&&b.length){if(!c||!(c instanceof Array))for(e in c=
-[],b[0])b[0].hasOwnProperty(e)&&c.push(e);e=0;for(g=b.length;e<g;e+=1){j=[];h=0;for(k=c.length;h<k;h+=1)j.push(b[e][c[h]]);Function.apply.call(a.log,a,j)}}});a.clear||(a.clear=f());a.trace||(a.trace=f());a.group||(a.group=f());a.groupCollapsed||(a.groupCollapsed=f());a.groupEnd||(a.groupEnd=f());a.timeStamp||(a.timeStamp=f());a.profile||(a.profile=f());a.profileEnd||(a.profileEnd=f());a.count||(a.count=f())})();

+ 54 - 0
app/www/js/consoleshim.js

@@ -0,0 +1,54 @@
+(function(window,undefined){
+    "use strict";
+	var deepCopy = function(p,c) {
+			c = c||{};
+			for (var i in p) {
+				if (typeof p[i] === 'object') {
+					c[i] = (p[i].constructor === Array)?[]:{};
+					deepCopy(p[i],c[i]);
+				}else{
+					c[i] = p[i];
+				}
+			}
+			return c;
+		},
+		oC = typeof console != 'undefined' ? deepCopy(console) : {},
+		i,
+		console = window.console,
+        noop = function(){},
+		a = ['log','info','debug','error','warn'];
+	console._call = function(index,name,args){
+		console._old[index].apply(window,args);
+		var d = $('#console-log'),
+		msg = name+': '+Array.prototype.slice.call(args,0).join("\t");
+		if(d.children().length === 0){
+			d.css({
+				margin: 0,
+				padding: 0
+			}).append($('<pre>').attr('id','console-log-pre'));
+		}
+		d.children('pre').each(function(){
+			$(this).html($(this).html()+""+msg+"<br/>");
+		});
+		return msg;
+	};
+	console._old = [];
+	for(i=0;i<a.length;i++){
+		var name = a[i],
+			index = i;
+		console._old.push(oC[name] || noop);
+		if(a[i] != 'error'){
+			console[name] = function(){
+				return console._call(index,name.toUpperCase(),arguments)
+			}
+		}else{
+			console[name] = function(){
+				var args;
+				for(var i in arguments){
+					args.push(arguments[i].message);
+				}
+				return console._call(index,name.toUpperCase(),args)
+			}
+		}
+	}
+})(window);

+ 40 - 0
app/www/js/omnomirc.js

@@ -461,6 +461,41 @@
 								)
 						);
 					}
+					if(settings.debug){
+						$(frag).append(
+							$('<li>')
+								.addClass('row')
+								.attr('id','console-log-controls')
+								.append(
+									$('<span>')
+										.text('Debug Log')
+										.addClass('cell')
+								)
+								.append(
+									$('<span>')
+										.addClass('cell')
+										.append(
+											$('<button>')
+												.text('Show')
+												.click(function(){
+													$(this).text($('#console-log').is(':visible')?'Show':'Hide');
+													$('#console-log').toggle();
+													$('#console-log-clear').toggle();
+													$('#content').toggle();
+												})
+										)
+										.append(
+											$('<button>')
+												.text('Clear')
+												.attr('id','console-log-clear')
+												.hide()
+												.click(function(){
+													$('#console-log-pre').html('');
+												})
+										)
+								)
+						);
+					}
 					$('#settings-list').html(frag);
 				},
 				users: function(){
@@ -804,6 +839,11 @@
 					case 'nick':
 						$o.chat.auth();
 					break;
+					case 'debug':
+						if(typeof render != 'undefined'){
+							$o.ui.render.settings();
+						}
+					break;
 				}
 				if(typeof render == 'undefined'){
 					$o.ui.render.settings();