diff options
author | Luke "Jared" Bennett <lbennett@gitlab.com> | 2017-07-19 20:07:34 +0300 |
---|---|---|
committer | Luke "Jared" Bennett <lbennett@gitlab.com> | 2017-07-19 20:28:08 +0300 |
commit | 929c66d6207d19c39d99f09cda79de7f16e8aaae (patch) | |
tree | 6a05c72794d352b21c17fd8b318c6551a3b8dcc7 /app/assets/javascripts/helpers | |
parent | b05092ef7e247cffc1fe40daecc12ecce126349e (diff) |
Move getScrollWidth to ScrollHelper
Diffstat (limited to 'app/assets/javascripts/helpers')
-rw-r--r-- | app/assets/javascripts/helpers/scroll_helper.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/app/assets/javascripts/helpers/scroll_helper.js b/app/assets/javascripts/helpers/scroll_helper.js new file mode 100644 index 00000000000..4a3a9e161a8 --- /dev/null +++ b/app/assets/javascripts/helpers/scroll_helper.js @@ -0,0 +1,29 @@ +function getScrollWidth() { + const $rulerContainer = $('<div>').css({ + visibility: 'hidden', + width: 100, + overflow: 'scroll', + }); + + const $ruler = $('<div>').css({ + width: '100%', + }); + + $ruler.appendTo($rulerContainer); + $rulerContainer.appendTo('body'); + + const scrollWidth = $ruler.outerWidth(); + + $rulerContainer.remove(); + + return 100 - scrollWidth; +} + +function setScrollWidth() { + $('body').attr('data-scroll-width', getScrollWidth()); +} + +export { + getScrollWidth, + setScrollWidth, +}; |