Fixed javascript coloring of async output
Change-Id: I9b05ed3f008e97a2bc30811251486bfc7482e1ee
diff --git a/theme/mirantis.js b/theme/mirantis.js
index 3b3a34a..88945bd 100644
--- a/theme/mirantis.js
+++ b/theme/mirantis.js
@@ -1,45 +1,56 @@
function DOMReady(fn) {
- if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading"){
- fn();
- } else {
- document.addEventListener('DOMContentLoaded', 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);
+ var s = document.createElement('script');
+ s.setAttribute('src', src);
+ s.onload = callback;
+ if (async) s.async = true
+ document.body.appendChild(s);
}
-DOMReady(function(){
- // init ansi colors
- addScript("/userContent/theme/js/ansi_up.js", (function(contentSelector){
- var ansiUp = new AnsiUp
- , $console = document.querySelector(contentSelector)
- , 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));
- };
+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();
- $console.addEventListener('change', colorizeFn, false);
- }).bind(null,".console-output"), true);
+ 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);
+ }
});
\ No newline at end of file