diff options
author | Bryce Johnson <bryce@gitlab.com> | 2017-06-19 05:30:58 +0300 |
---|---|---|
committer | Bryce Johnson <bryce@gitlab.com> | 2017-06-30 17:03:50 +0300 |
commit | 728be6af7c46bf57f2d4a3dd2f1d5dd9ec23bd4b (patch) | |
tree | ca056a3cbe372fac9c033862a64ffd2c31973947 /app/assets/javascripts/sidebar_height_manager.js | |
parent | 1a449b24a22283aeffa08603d2cff00db10d7fe5 (diff) |
Make setSidebarHeight more efficient with SidebarHeightManager.
Diffstat (limited to 'app/assets/javascripts/sidebar_height_manager.js')
-rw-r--r-- | app/assets/javascripts/sidebar_height_manager.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/app/assets/javascripts/sidebar_height_manager.js b/app/assets/javascripts/sidebar_height_manager.js new file mode 100644 index 00000000000..022415f22b2 --- /dev/null +++ b/app/assets/javascripts/sidebar_height_manager.js @@ -0,0 +1,33 @@ +export default { + init() { + if (!this.initialized) { + this.$window = $(window); + this.$rightSidebar = $('.js-right-sidebar'); + this.$navHeight = $('.navbar-gitlab').outerHeight() + + $('.layout-nav').outerHeight() + + $('.sub-nav-scroll').outerHeight(); + + const throttledSetSidebarHeight = _.throttle(() => this.setSidebarHeight(), 20); + const debouncedSetSidebarHeight = _.debounce(() => this.setSidebarHeight(), 200); + + this.$window.on('scroll', throttledSetSidebarHeight); + this.$window.on('resize', debouncedSetSidebarHeight); + this.initialized = true; + } + }, + + setSidebarHeight() { + const currentScrollDepth = window.pageYOffset || 0; + const diff = this.$navHeight - currentScrollDepth; + + if (diff > 0) { + const newSidebarHeight = window.innerHeight - diff; + this.$rightSidebar.outerHeight(newSidebarHeight); + this.sidebarHeightIsCustom = true; + } else if (this.sidebarHeightIsCustom) { + this.$rightSidebar.outerHeight('100%'); + this.sidebarHeightIsCustom = false; + } + }, +}; + |