Last active
June 5, 2019 13:35
-
-
Save AndersDJohnson/5692405 to your computer and use it in GitHub Desktop.
dom logger / jsfiddle
This file contains 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 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