Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use MutationObserver to observe log for work instance_linker.js correctly #68

Merged
merged 3 commits into from
Apr 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PhantomJS supports MutationObserver from 2.0. But It seems that TravisCI uses PhantomJS 1.x currently (as default). So if browser does not support MutationObserver, this function (instance linker) should be disabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But recent modern browsers support MutationObserver like that https://caniuse.com/#feat=mutationobserver

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your information.
To support PhantomJS 2.0 in #70 .
Could you add a test after merged #70 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you about #70. I'll add a test about this.

}
var logParent = document.querySelector('#logs tbody');
var observer = new MutationObserver(function(mutations) {
if (mutations.some(function(m) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about separate as a named function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should do that 👍

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) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI I added |$

return '<a href="/definitions/' + jobId + '/instances/' + instanceId+ '">' + match + '</a>';
})
);
});
}
});
observer.observe(logParent, {childList: true, substree: true});
});