ConsoleLogHTML demo
A demo of the ConsoleLogHTML library
by Art
HTML
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css">
<script src="https://cdn.rawgit.com/Alorel/console-log-html/1.2.7/console-log-html.min.js"></script>
<script src="https://cdn.rawgit.com/coolaj86/TextEncoderLite/master/index.js"></script>
<script src="https://cdn.rawgit.com/beatgammit/base64-js/master/base64js.min.js"></script>
<script src="https://cdn.rawgit.com/Alorel/console-log-html/a40aea9e88bfff88da77b0d4ca2b9903973425c3/console-log-html.min.js"></script>
<div class="container">
<label class="show">
<span>Text to output:</span>
<input id="text" class="form-control" value="Alorel/console-log-html" />
</label>
<label class="show">
<input type="checkbox" id="onlyConsole" />
<span>Don't log to HTML, only the console (skipHtml option)</span>
</label>
<div class="tbl margin-top">
<div>
<div>
<div class="list-group">
<button class="list-group-item list-group-item-default">Log</button>
<button class="list-group-item list-group-item-info">Debug</button>
<button class="list-group-item list-group-item-success">Info</button>
<button class="list-group-item list-group-item-warning">Warn</button>
<button class="list-group-item list-group-item-danger">Error</button>
<button class="list-group-item list-group-item-default">Clear</button>
</div>
</div>
<div>
<ul id="target"></ul>
</div>
</div>
</div>
<hr>
<footer class="text-center">
<small style="display:block">
<span>Created by</span>
<a href="https://github.com/Alorel">Alorel</a>
</small>
<small style="display:block">
<span>See the source on</span>
<a href="https://github.com/Alorel/console-log-html" target="_blank">GitHub</a>
</small>
</footer>
...
SCSS
.margin-top {
margin-top: 1em;
}
#outlink {
text-decoration: underline;
}
#target {
list-style: none;
-webkit-padding-start: 0;
-webkit-margin-after: 0;
-webkit-margin-before: 1em;
border: 1px solid #000;
overflow-y: auto;
width: 100%;
background: #333;
color: #fff;
}
.tbl {
display: table;
width:100%;
>* {
display: table-row;
>* {
display: table-cell;
&:last-child {
width:100%
}
}
}
}
.container {
padding-top: 1em;
}
JavaScript
// The text we're logging
var text = document.getElementById("text"),
// The checkbox
onlyConsole = document.getElementById("onlyConsole"),
// The target <ul>
target = document.getElementById("target"),
// The buttons on the left
buttons = document.querySelectorAll(".list-group-item"),
// Our button click listener
buttonListener = function() {
var target = onlyConsole.checked ? console.skipHtml : console;
// Since all buttons have their text set to the appropriate log level
// we can just check them for it via innerText - just need to make it
// lowercase
target[this.innerText.toLowerCase()](text.value);
},
i = 0;
// jQuery works too! The result would be the same if you did
// ConsoleLogHTML.connect($("#target"))
ConsoleLogHTML.connect(target);
// Attach our event listeners
for (; i < buttons.length; i++) {
buttons[i].addEventListener("click", buttonListener);
}
//Create interactive page link
document.getElementById("outlink").addEventListener("click", function(e) {
window.open(
"data:text/html;base64," + base64js.fromByteArray(
(new TextEncoderLite('utf-8')).encode(document.firstElementChild.outerHTML)
)
);
});
// Remove the "A thing to remember!" notice if we're on a data URL
if ("data:" === location.protocol) {
var outDiv = document.getElementById("outdiv");
outDiv.parentElement.removeChild(outDiv);
console.clear();
}
// And some basic styling
target.style.maxHeight = document.querySelector(".list-group").offsetHeight + "px";