Created
November 4, 2012 15:49
-
-
Save pauliusuza/4012355 to your computer and use it in GitHub Desktop.
Javascript Output Console for Microsoft Visual Studio 2012 projects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Javascript Output Console for Microsoft Visual Studio 2012 projects | |
* @author Paulius Uza, [email protected] | |
* @license MIT | |
* | |
* Dependencies: | |
* JQuery 1.8.2 | |
* | |
* Usage: | |
* console.log(var1, var2, var3, var4); | |
* | |
* Include the console after JQuery 1.8.2. | |
* To open the console, hit the tilde (~) key inside your application. | |
* | |
* If you like this, also check out Snipppet app for Windows 8: | |
* http://bit.ly/VGPN6x | |
* | |
*/ | |
(function (window) { | |
"use strict"; | |
(function ($) { | |
$.CMstyle = { | |
insertRule: function (selector, rules, contxt) { | |
var context = contxt || document, stylesheet; | |
if (typeof context.styleSheets == 'object') { | |
if (context.styleSheets.length) { | |
stylesheet = context.styleSheets[context.styleSheets.length - 1]; | |
} | |
if (context.styleSheets.length) { | |
if (context.createStyleSheet) { | |
stylesheet = context.createStyleSheet(); | |
} | |
else { | |
context.getElementsByTagName('head')[0].appendChild(context.createElement('style')); | |
stylesheet = context.styleSheets[context.styleSheets.length - 1]; | |
} | |
} | |
if (stylesheet.addRule) { | |
for (var i = 0; i < selector.length; ++i) { | |
stylesheet.addRule(selector[i], rules); | |
} | |
} | |
else { | |
stylesheet.insertRule(selector.join(',') + '{' + rules + '}', stylesheet.cssRules.length); | |
} | |
} | |
} | |
}; | |
})(jQuery); | |
var _singleton = null; | |
var _name = "RTBug"; | |
var _newline = "\n<span class='nl'>></span> "; | |
WinJS.Namespace.define(_name, { | |
dom: null, | |
wrap: null, | |
cache: '', | |
getInstance: function () { | |
if (_singleton == null) { | |
var obj = Object.create(this); | |
obj.init(); | |
_singleton = obj; | |
} | |
return _singleton; | |
}, | |
init: function () { | |
var self = this; | |
$(document).ready(function () { | |
$('body').append('<div id="console_wrap" style="display:none;"><div id="console"></div></div>'); | |
self.dom = $('#console'); | |
self.wrap = $('#console_wrap'); | |
self.dom.append(self.cache); | |
$(document).keypress(function (e) { | |
if (e.which == 96) { | |
self.wrap.toggle(); | |
return false; | |
} | |
}); | |
}); | |
$.CMstyle.insertRule(['#console_wrap'], 'display: block; width: 100%; height: 100%; position: absolute; overflow-y: scroll; background: rgba(0,0,0,0.8); -ms-scroll-rails: railed; overflow-x: hidden;'); | |
$.CMstyle.insertRule(['#console'], ' display: block; width: 100%; height: 100%; padding: 10px; top: 0px; left: 0px; color: #fff; white-space: pre-wrap;'); | |
$.CMstyle.insertRule(['#console .nl'], 'background: green; color: white; font-weight: bold; margin-right: 5px;'); | |
RTBug.log('Console initialized. Howdy!'); | |
}, | |
log: function (what, p1, p2, p3, p4) { | |
if (typeof (what) == 'object') { | |
what = JSON.stringify(what); | |
} | |
if (p1) if (typeof (p1) == 'object') { what += _newline + JSON.stringify(p1); } else { what += _newline + p1; }; | |
if (p2) if (typeof (p2) == 'object') { what += _newline + JSON.stringify(p2); } else { what += _newline + p2; }; | |
if (p3) if (typeof (p3) == 'object') { what += _newline + JSON.stringify(p3); } else { what += _newline + p3; }; | |
if (p4) if (typeof (p4) == 'object') { what += _newline + JSON.stringify(p4); } else { what += _newline + p4; }; | |
if (this.dom) { | |
this.dom.append(_newline + what); | |
} else { | |
this.cache += _newline + what; | |
} | |
} | |
}); | |
var i = RTBug.getInstance(); | |
window.console = i; | |
}(window)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment