Skip to content

Commit

Permalink
Make discussion sidebar sticky (refined-github#964)
Browse files Browse the repository at this point in the history
  • Loading branch information
niklashigi authored and fregante committed Jan 8, 2018
1 parent 7579916 commit de678f7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions source/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import addJumpToBottomLink from './features/add-jump-to-bottom-link';
import addQuickReviewButtons from './features/add-quick-review-buttons';
import extendDiffExpander from './features/extend-diff-expander';
import sortIssuesByUpdateTime from './features/sort-issues-by-update-time';
import makeDiscussionSidebarSticky from './features/make-discussion-sidebar-sticky';
import shortenLinks from './features/shorten-links';

import * as pageDetect from './libs/page-detect';
Expand Down Expand Up @@ -115,6 +116,7 @@ function onDomReady() {
enableFeature(markUnread);
enableFeature(enableCopyOnY);
enableFeature(addProfileHotkey);
enableFeature(makeDiscussionSidebarSticky);

if (!pageDetect.isGist()) {
enableFeature(moveMarketplaceLinkToProfileDropdown);
Expand Down
23 changes: 23 additions & 0 deletions source/features/make-discussion-sidebar-sticky.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import select from 'select-dom';
import debounce from 'debounce-fn';
import onAjaxedPages from 'github-injection';
import * as pageDetect from '../libs/page-detect';

function updateStickiness() {
const sidebar = select('.discussion-sidebar');
const sidebarHeight = sidebar.offsetHeight + 25;
sidebar.style.position = sidebarHeight < window.innerHeight ? 'sticky' : null;
}

const handler = debounce(updateStickiness, {wait: 100});

export default function () {
onAjaxedPages(() => {
if (pageDetect.isIssue() || pageDetect.isPRConversation()) {
updateStickiness();
window.addEventListener('resize', handler);
} else {
window.removeEventListener('resize', handler);
}
});
}

0 comments on commit de678f7

Please sign in to comment.