blob: 88945bd3e1d4fcd6eb110b1b56b4e580584e447d [file] [log] [blame]
Jakub Josef52c3f122017-08-09 13:14:07 +02001function DOMReady(fn) {
Jakub Josef1aa47882017-08-09 20:21:57 +02002 if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading") {
3 fn();
4 } else {
5 document.addEventListener('DOMContentLoaded', fn);
6 }
Jakub Josef52c3f122017-08-09 13:14:07 +02007}
Jakub Josef1aa47882017-08-09 20:21:57 +02008
Jakub Josef52c3f122017-08-09 13:14:07 +02009function addScript(src, callback, async) {
Jakub Josef1aa47882017-08-09 20:21:57 +020010 var s = document.createElement('script');
11 s.setAttribute('src', src);
12 s.onload = callback;
13 if (async) s.async = true
14 document.body.appendChild(s);
Jakub Josef52c3f122017-08-09 13:14:07 +020015}
16
Jakub Josef1aa47882017-08-09 20:21:57 +020017DOMReady(function() {
18 var consoleOutputSelector = ".console-output";
19 if (document.querySelector(consoleOutputSelector)) {
20 // init ansi colors
21 addScript("/userContent/theme/js/ansi_up.js", function() {
22 var ansiUp = new AnsiUp,
23 $console = document.querySelector(consoleOutputSelector),
24 entities = {
25 'amp': '&',
26 'apos': '\'',
27 '#x27': '\'',
28 '#x2F': '/',
29 '#39': '\'',
30 '#47': '/',
31 'lt': '<',
32 'gt': '>',
33 'nbsp': ' ',
34 'quot': '"'
35 },
36 decodeHTMLEntities = function(text) {
37 return text.replace(/&([^;]+);/gm, function(match, entity) {
38 return entities[entity] || match
39 })
40 },
41 colorizeFn = function() {
42 $console.innerHTML = decodeHTMLEntities(ansiUp.ansi_to_html($console.innerHTML));
43 };
Jakub Josef52c3f122017-08-09 13:14:07 +020044
Jakub Josef1aa47882017-08-09 20:21:57 +020045 colorizeFn();
46 // create prototype.js global ajax handle responder
47 Ajax.Responders.register({
48 onComplete: function(req, res) {
49 if (req.body.indexOf("start=") != -1 && res.status==200 && res.responseText != "") {
50 colorizeFn();
51 }
52 }
53 });
54 }, true);
55 }
Jakub Josef52c3f122017-08-09 13:14:07 +020056});