summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/lib/utils/sticky.js
diff options
context:
space:
mode:
authorMatija Čupić <matteeyah@gmail.com>2018-06-06 21:29:12 +0200
committerMatija Čupić <matteeyah@gmail.com>2018-06-06 21:29:12 +0200
commit9efb1875b7b001f0bda8afea60be7145459eb496 (patch)
tree6b1eb349cc5ad120c55f8e5af10df7b062b0c6b4 /app/assets/javascripts/lib/utils/sticky.js
parent44be58836c826dfc0fbfa6d58641d34f84e292fb (diff)
parentdd6aade3bf54a6d72a5b98daa34d0798b158399f (diff)
downloadgitlab-ce-9efb1875b7b001f0bda8afea60be7145459eb496.tar.gz
Merge branch 'master' into 38542-application-control-panel-in-settings-page
Diffstat (limited to 'app/assets/javascripts/lib/utils/sticky.js')
-rw-r--r--app/assets/javascripts/lib/utils/sticky.js23
1 files changed, 22 insertions, 1 deletions
diff --git a/app/assets/javascripts/lib/utils/sticky.js b/app/assets/javascripts/lib/utils/sticky.js
index 098afcfa1b4..15a4dd62012 100644
--- a/app/assets/javascripts/lib/utils/sticky.js
+++ b/app/assets/javascripts/lib/utils/sticky.js
@@ -1,3 +1,5 @@
+import StickyFill from 'stickyfilljs';
+
export const createPlaceholder = () => {
const placeholder = document.createElement('div');
placeholder.classList.add('sticky-placeholder');
@@ -28,7 +30,16 @@ export const isSticky = (el, scrollY, stickyTop, insertPlaceholder) => {
}
};
-export default (el, stickyTop, insertPlaceholder = true) => {
+/**
+ * Create a listener that will toggle a 'is-stuck' class, based on the current scroll position.
+ *
+ * - If the current environment does not support `position: sticky`, do nothing.
+ *
+ * @param {HTMLElement} el The `position: sticky` element.
+ * @param {Number} stickyTop Used to determine when an element is stuck.
+ * @param {Boolean} insertPlaceholder Should a placeholder element be created when element is stuck?
+ */
+export const stickyMonitor = (el, stickyTop, insertPlaceholder = true) => {
if (!el) return;
if (typeof CSS === 'undefined' || !(CSS.supports('(position: -webkit-sticky) or (position: sticky)'))) return;
@@ -37,3 +48,13 @@ export default (el, stickyTop, insertPlaceholder = true) => {
passive: true,
});
};
+
+/**
+ * Polyfill the `position: sticky` behavior.
+ *
+ * - If the current environment supports `position: sticky`, do nothing.
+ * - Can receive an iterable element list (NodeList, jQuery collection, etc.) or single HTMLElement.
+ */
+export const polyfillSticky = (el) => {
+ StickyFill.add(el);
+};