From 016e750308b6e927b53d8c050b3f3bb60e9ca4aa Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Fri, 20 Oct 2017 18:56:43 +0100 Subject: Fix performance of sticky.js Closes #39332 --- app/assets/javascripts/init_changes_dropdown.js | 2 +- app/assets/javascripts/lib/utils/sticky.js | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) (limited to 'app') diff --git a/app/assets/javascripts/init_changes_dropdown.js b/app/assets/javascripts/init_changes_dropdown.js index f785ed29e6c..e41f374b2e5 100644 --- a/app/assets/javascripts/init_changes_dropdown.js +++ b/app/assets/javascripts/init_changes_dropdown.js @@ -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, diff --git a/app/assets/javascripts/lib/utils/sticky.js b/app/assets/javascripts/lib/utils/sticky.js index 64db42701ce..098afcfa1b4 100644 --- a/app/assets/javascripts/lib/utils/sticky.js +++ b/app/assets/javascripts/lib/utils/sticky.js @@ -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, -- cgit v1.2.1