Repository navigation
Conversation
| // get the diff container for this button | ||
| const parent = b.parentElement.parentElement.parentElement | ||
|
|
||
| b.addEventListener('click', () => { |
There was a problem hiding this comment.
Can we avoid the loop and use a delegate listener instead? Big PRs are loaded via ajax. Something like this instead of approximately the first 6 lines of this file:
$('.js-diff-progressive-container').on('click', '.js-details-target', fn);| console.log('hihi') | ||
| const btns = document.querySelectorAll('.file-actions > .js-details-target') | ||
| const prToolbar = document.querySelector('.pr-toolbar') | ||
| const toolbarHeight = prToolbar.getBoundingClientRect().height |
There was a problem hiding this comment.
prToolbar might not exist on the PR's Conversation tab, you'll need a condition or just move it inside the event handler.
|
|
||
| btns.forEach((b) => { | ||
| // get the diff container for this button | ||
| const parent = b.parentElement.parentElement.parentElement |
There was a problem hiding this comment.
This is best done via b.closest('.file')
| const parentOffset = parent.getBoundingClientRect().top | ||
| const parentY = parentOffset - bodyOffset - toolbarHeight | ||
|
|
||
| if (window.scrollY > parentY) { |
There was a problem hiding this comment.
bodyOffset is the same as window.scrollY, so you're cancelling it out.
When the element is inside the viewport, parentOffset will be positive, so the condition can just be parentOffset < toolbarHeight.
|
sorry, I didn't realise there was full jQuery available. also removed the silly console log i left in. |
as per #655