-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from inohiro/link_to_parent_from_child_process
Use MutationObserver to observe log for work instance_linker.js correctly
- Loading branch information
Showing
1 changed file
with
22 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}); | ||
}); |