From 43e51f2d8ad8375ef94412d6dd05b1bb1cd398e5 Mon Sep 17 00:00:00 2001 From: Hiroyuki Inoue Date: Mon, 26 Jun 2017 12:56:04 -0700 Subject: [PATCH 1/3] Use MutationObserver to oberve log for work instance_linker.js correctly --- .../javascripts/kuroko2/instance_linker.js | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/kuroko2/instance_linker.js b/app/assets/javascripts/kuroko2/instance_linker.js index 49223787..0a95f87f 100644 --- a/app/assets/javascripts/kuroko2/instance_linker.js +++ b/app/assets/javascripts/kuroko2/instance_linker.js @@ -1,10 +1,22 @@ jQuery(function ($) { - $('td.log').each(function(){ - var logText = $(this).html(); - $(this).html( - logText.replace(/instance#(\d+)\/(\d+)(?:\s+|\.)/, function(match, jobId, instanceId){ - return '' + match + ''; - }) - ); + var logParent = document.querySelector('#logs tbody'); + var observer = new MutationObserver(function(mutations) { + if (mutations.some(x => + x.addedNodes + && x.addedNodes instanceof NodeList + && x.addedNodes.length > 0 + && x.type == 'childList' + ) + ) { + $('td.log').each(function() { + var logText = $(this).html(); + $(this).html( + logText.replace(/instance#(\d+)\/(\d+)(?:\s+|\.|$)/, function(match, jobId, instanceId) { + return '' + match + ''; + }) + ); + }); + } }); + observer.observe(logParent, {childList: true, substree: true}); }); From c8f6d42f3849d508588adc737090580475ddaedf Mon Sep 17 00:00:00 2001 From: Hiroyuki Inoue Date: Mon, 26 Jun 2017 13:57:47 -0700 Subject: [PATCH 2/3] Remove arrow function --- app/assets/javascripts/kuroko2/instance_linker.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/kuroko2/instance_linker.js b/app/assets/javascripts/kuroko2/instance_linker.js index 0a95f87f..fd61c3a5 100644 --- a/app/assets/javascripts/kuroko2/instance_linker.js +++ b/app/assets/javascripts/kuroko2/instance_linker.js @@ -1,13 +1,12 @@ jQuery(function ($) { var logParent = document.querySelector('#logs tbody'); var observer = new MutationObserver(function(mutations) { - if (mutations.some(x => - x.addedNodes - && x.addedNodes instanceof NodeList - && x.addedNodes.length > 0 - && x.type == 'childList' - ) - ) { + if (mutations.some(function(m) { + return m.addedNodes + && m.addedNodes instanceof NodeList + && m.addedNodes.length > 0 + && m.type == 'childList' + })) { $('td.log').each(function() { var logText = $(this).html(); $(this).html( From 5cb4b5f93bb8854748a0317f2f38b34add528a56 Mon Sep 17 00:00:00 2001 From: Hiroyuki Inoue Date: Mon, 26 Jun 2017 15:40:21 -0700 Subject: [PATCH 3/3] Find compatibility of MutationObserver. Don't observe, if not found --- app/assets/javascripts/kuroko2/instance_linker.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/assets/javascripts/kuroko2/instance_linker.js b/app/assets/javascripts/kuroko2/instance_linker.js index fd61c3a5..a31b90eb 100644 --- a/app/assets/javascripts/kuroko2/instance_linker.js +++ b/app/assets/javascripts/kuroko2/instance_linker.js @@ -1,4 +1,8 @@ jQuery(function ($) { + var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver; + if (!MutationObserver) { + return; + } var logParent = document.querySelector('#logs tbody'); var observer = new MutationObserver(function(mutations) { if (mutations.some(function(m) {