blob: d838b8533d5f674ea384c457f4abc2a259049a16 [file] [log] [blame]
Jakub Josef95765192017-08-09 20:29:16 +02001
2// ------ Jenkins ANSI color pure JS plugin https://github.com/jakubjosef/jenkins-ansi-color-js ------ //
Jakub Josef52c3f122017-08-09 13:14:07 +02003function DOMReady(fn) {
Jakub Josef1aa47882017-08-09 20:21:57 +02004 if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading") {
5 fn();
6 } else {
7 document.addEventListener('DOMContentLoaded', fn);
8 }
Jakub Josef52c3f122017-08-09 13:14:07 +02009}
Jakub Josef1aa47882017-08-09 20:21:57 +020010
Jakub Josef52c3f122017-08-09 13:14:07 +020011function addScript(src, callback, async) {
Jakub Josef1aa47882017-08-09 20:21:57 +020012 var s = document.createElement('script');
13 s.setAttribute('src', src);
14 s.onload = callback;
15 if (async) s.async = true
16 document.body.appendChild(s);
Jakub Josef52c3f122017-08-09 13:14:07 +020017}
18
Jakub Josef1aa47882017-08-09 20:21:57 +020019DOMReady(function() {
20 var consoleOutputSelector = ".console-output";
21 if (document.querySelector(consoleOutputSelector)) {
22 // init ansi colors
23 addScript("/userContent/theme/js/ansi_up.js", function() {
24 var ansiUp = new AnsiUp,
25 $console = document.querySelector(consoleOutputSelector),
26 entities = {
27 'amp': '&',
28 'apos': '\'',
29 '#x27': '\'',
30 '#x2F': '/',
31 '#39': '\'',
32 '#47': '/',
33 'lt': '<',
34 'gt': '>',
35 'nbsp': ' ',
36 'quot': '"'
37 },
38 decodeHTMLEntities = function(text) {
39 return text.replace(/&([^;]+);/gm, function(match, entity) {
40 return entities[entity] || match
41 })
42 },
43 colorizeFn = function() {
44 $console.innerHTML = decodeHTMLEntities(ansiUp.ansi_to_html($console.innerHTML));
45 };
Jakub Josef52c3f122017-08-09 13:14:07 +020046
Jakub Josef1aa47882017-08-09 20:21:57 +020047 colorizeFn();
48 // create prototype.js global ajax handle responder
49 Ajax.Responders.register({
50 onComplete: function(req, res) {
51 if (req.body.indexOf("start=") != -1 && res.status==200 && res.responseText != "") {
52 colorizeFn();
53 }
54 }
55 });
56 }, true);
57 }
Jakub Josef52c3f122017-08-09 13:14:07 +020058});