blob: 3b3a34a2031d3d5339c80d2646ee20f07ecaa3bf [file] [log] [blame]
Jakub Josef52c3f122017-08-09 13:14:07 +02001function DOMReady(fn) {
2 if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading"){
3 fn();
4 } else {
5 document.addEventListener('DOMContentLoaded', fn);
6 }
7}
8function addScript(src, callback, async) {
9 var s = document.createElement('script');
10 s.setAttribute('src', src);
11 s.onload=callback;
12 if(async) s.async = true
13 document.body.appendChild(s);
14}
15
16DOMReady(function(){
17 // init ansi colors
18 addScript("/userContent/theme/js/ansi_up.js", (function(contentSelector){
19 var ansiUp = new AnsiUp
20 , $console = document.querySelector(contentSelector)
21 , entities = {
22 'amp': '&',
23 'apos': '\'',
24 '#x27': '\'',
25 '#x2F': '/',
26 '#39': '\'',
27 '#47': '/',
28 'lt': '<',
29 'gt': '>',
30 'nbsp': ' ',
31 'quot': '"'
32 }
33 , decodeHTMLEntities = function (text) {
34 return text.replace(/&([^;]+);/gm, function (match, entity) {
35 return entities[entity] || match
36 })
37 }
38 , colorizeFn = function(){
39 $console.innerHTML = decodeHTMLEntities(ansiUp.ansi_to_html($console.innerHTML));
40 };
41
42 colorizeFn();
43 $console.addEventListener('change', colorizeFn, false);
44 }).bind(null,".console-output"), true);
45});