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