| |
| // ------ Jenkins ANSI color pure JS plugin https://github.com/jakubjosef/jenkins-ansi-color-js ------ // |
| function DOMReady(fn) { |
| if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading") { |
| fn(); |
| } else { |
| document.addEventListener('DOMContentLoaded', fn); |
| } |
| } |
| |
| function addScript(src, callback, async) { |
| var s = document.createElement('script'); |
| s.setAttribute('src', src); |
| s.onload = callback; |
| if (async) s.async = true |
| document.body.appendChild(s); |
| } |
| |
| DOMReady(function() { |
| var consoleOutputSelector = ".console-output"; |
| if (document.querySelector(consoleOutputSelector)) { |
| // init ansi colors |
| addScript("/userContent/theme/js/ansi_up.js", function() { |
| var ansiUp = new AnsiUp, |
| $console = document.querySelector(consoleOutputSelector), |
| entities = { |
| 'amp': '&', |
| 'apos': '\'', |
| '#x27': '\'', |
| '#x2F': '/', |
| '#39': '\'', |
| '#47': '/', |
| 'lt': '<', |
| 'gt': '>', |
| 'nbsp': ' ', |
| 'quot': '"' |
| }, |
| decodeHTMLEntities = function(text) { |
| return text.replace(/&([^;]+);/gm, function(match, entity) { |
| return entities[entity] || match |
| }) |
| }, |
| colorizeFn = function() { |
| $console.innerHTML = decodeHTMLEntities(ansiUp.ansi_to_html($console.innerHTML)); |
| }; |
| |
| colorizeFn(); |
| // create prototype.js global ajax handle responder |
| Ajax.Responders.register({ |
| onComplete: function(req, res) { |
| if (req.body.indexOf("start=") != -1 && res.status==200 && res.responseText != "") { |
| colorizeFn(); |
| } |
| } |
| }); |
| }, true); |
| } |
| }); |