diff options
author | Paul Slaughter <pslaughter@gitlab.com> | 2018-06-05 02:50:38 -0500 |
---|---|---|
committer | Paul Slaughter <pslaughter@gitlab.com> | 2018-06-05 02:50:38 -0500 |
commit | 67315ca9df71b251484b9ea72978371a949c193c (patch) | |
tree | a862dd9bc1eaa7ca36367fab4782f2245f3c8c2f | |
parent | 0059a0e5fc9e33461b333e718cb35f582f45684a (diff) | |
download | gitlab-ce-46833-sticky-polyfill.tar.gz |
Add comments for utils/sticky46833-sticky-polyfill
-rw-r--r-- | app/assets/javascripts/lib/utils/sticky.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/app/assets/javascripts/lib/utils/sticky.js b/app/assets/javascripts/lib/utils/sticky.js index e7dafbe70e0..d34d722b572 100644 --- a/app/assets/javascripts/lib/utils/sticky.js +++ b/app/assets/javascripts/lib/utils/sticky.js @@ -30,11 +30,30 @@ export const isSticky = (el, scrollY, stickyTop, insertPlaceholder) => { } }; +/** + * This function attaches listeners to support `position: sticky` behavior. + * + * Description: + * - For the given element, polyfill `position: sticky` in unsupported browsers. + * - For the given element, add a scroll listener for toggling 'is-stuck' class. + * + * @param {Element} el Element with `position: sticky`. + * + * @param {Number} stickyTop Used to determine when `el` is stuck or not. + * + * @param {Boolean} [options.insertPlaceholder=true] When `el` is stuck, should a placeholder + * element be inserted (to preserve height)? + * + * @param {Boolean} [options.hasOnStickListener=true] Should the scroll listener for toggling + * 'is-stuck' class be created? + */ export default (el, stickyTop, { insertPlaceholder = true, hasOnStickListener = true } = {}) => { if (!el) return; + // Add polyfill StickyFill.add(el); + // Add scroll listener for 'is-stuck' class if (hasOnStickListener) { document.addEventListener('scroll', () => isSticky(el, window.scrollY, stickyTop, insertPlaceholder), { passive: true, |