Skip to content

Commit

Permalink
Merge pull request #68 from inohiro/link_to_parent_from_child_process
Browse files Browse the repository at this point in the history
Use MutationObserver to observe log for work instance_linker.js correctly
  • Loading branch information
riseshia authored Apr 27, 2018
2 parents ee7871c + 5cb4b5f commit 68fdb7d
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions app/assets/javascripts/kuroko2/instance_linker.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
jQuery(function ($) {
$('td.log').each(function(){
var logText = $(this).html();
$(this).html(
logText.replace(/instance#(\d+)\/(\d+)(?:\s+|\.)/, function(match, jobId, instanceId){
return '<a href="/definitions/' + jobId + '/instances/' + instanceId+ '">' + match + '</a>';
})
);
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) {
return m.addedNodes
&& m.addedNodes instanceof NodeList
&& m.addedNodes.length > 0
&& m.type == 'childList'
})) {
$('td.log').each(function() {
var logText = $(this).html();
$(this).html(
logText.replace(/instance#(\d+)\/(\d+)(?:\s+|\.|$)/, function(match, jobId, instanceId) {
return '<a href="/definitions/' + jobId + '/instances/' + instanceId+ '">' + match + '</a>';
})
);
});
}
});
observer.observe(logParent, {childList: true, substree: true});
});

0 comments on commit 68fdb7d

Please sign in to comment.