Fix performance of sticky.js

Closes #39332
This commit is contained in:
Phil Hughes 2017-10-20 18:56:43 +01:00
parent 5295f23b4b
commit 016e750308
No known key found for this signature in database
GPG Key ID: 32245528C52E0F9F
2 changed files with 3 additions and 7 deletions

View File

@ -1,7 +1,7 @@
import stickyMonitor from './lib/utils/sticky';
export default () => {
stickyMonitor(document.querySelector('.js-diff-files-changed'));
stickyMonitor(document.querySelector('.js-diff-files-changed'), 76);
$('.js-diff-stats-dropdown').glDropdown({
filterable: true,

View File

@ -28,14 +28,10 @@ export const isSticky = (el, scrollY, stickyTop, insertPlaceholder) => {
}
};
export default (el, insertPlaceholder = true) => {
export default (el, stickyTop, insertPlaceholder = true) => {
if (!el) return;
const computedStyle = window.getComputedStyle(el);
if (!/sticky/.test(computedStyle.position)) return;
const stickyTop = parseInt(computedStyle.top, 10);
if (typeof CSS === 'undefined' || !(CSS.supports('(position: -webkit-sticky) or (position: sticky)'))) return;
document.addEventListener('scroll', () => isSticky(el, window.scrollY, stickyTop, insertPlaceholder), {
passive: true,