-
-
Save jasondavis/75c7ca1a7b37ed01f7bcfd7849cde40b to your computer and use it in GitHub Desktop.
dom logger / jsfiddle
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
| /** | |
| * Originally based on http://www.kobashicomputing.com/send-your-console-output-to-the-result-pane-in-jsfiddle | |
| */ | |
| window.jsFiddleConsole = function() { | |
| var consoleDiv; | |
| consoleDiv = document.createElement('div'); | |
| document.body.appendChild(consoleDiv); | |
| return { | |
| log: function(msg) { | |
| var para, text; | |
| para = document.createElement('p'); | |
| text = document.createTextNode(msg); | |
| para.appendChild(text); | |
| consoleDiv.appendChild(para); | |
| } | |
| }; | |
| }; |
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
| (function(context){ | |
| // don't call until domready | |
| var getDefaultElement = (function () { | |
| var defaultElement; | |
| return function () { | |
| if (typeof defaultElement == 'undefined') { | |
| defaultElement = document.createElement('div'); | |
| document.body.appendChild(defaultElement); | |
| } | |
| return defaultElement; | |
| }; | |
| })(); | |
| var Logger = function(name, element) { | |
| this.name = name; | |
| this.element = element || getDefaultElement(); | |
| }; | |
| Logger.prototype.log = function(msg) { | |
| var para, text; | |
| msg = this.name + ': ' + msg; | |
| para = document.createElement('p'); | |
| text = document.createTextNode(msg); | |
| para.appendChild(text); | |
| this.element.appendChild(para); | |
| }; | |
| context.Logger = Logger; | |
| })(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment