Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add "Hide all child comments" functionality to keyboard navigation #4678

Merged
merged 3 commits into from
Feb 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/modules/hideChildComments.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.include = [
'comments',
];

let initialHide;
let initialHide, toggleAllButton;

module.beforeLoad = () => {
initialHide = module.options.automatic.value &&
Expand Down Expand Up @@ -77,6 +77,7 @@ const addToggleAllButton = _.once(thing => {
e.preventDefault();
toggle(a.getAttribute('action'));
});
toggleAllButton = a;

toggle(initialHide ? 'hide' : 'show');

Expand Down Expand Up @@ -123,6 +124,12 @@ function addToggleChildrenButton(comment) {
menu.appendChild(li);
}

export function toggleAll() {
const button = toggleAllButton;
if (!button) throw new Error('Toggle all button not found');
button.click();
}

export function toggle(thing: *) {
const button = thing.entry.querySelector('a.toggleChildren');
if (!button) throw new Error('Toggle button not found');
Expand Down
10 changes: 10 additions & 0 deletions lib/modules/keyboardNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,16 @@ module.options = {
HideChildComments.toggle(selected);
},
},
showAllChildComments: {
type: 'keycode',
requiresModule: HideChildComments,
value: [67, false, false, true, false], // shift-c
description: 'keyboardNavShowAllChildCommentsDesc',
title: 'keyboardNavShowAllChildCommentsTitle',
callback() {
HideChildComments.toggleAll();
},
},
followPermalink: {
type: 'keycode',
include: ['comments', 'commentsLinklist', 'inbox'],
Expand Down
6 changes: 6 additions & 0 deletions locales/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,12 @@
"keyboardNavShowChildCommentsDesc": {
"message": "Show/hide the child comments tree (comment pages only)."
},
"keyboardNavShowAllChildCommentsTitle": {
"message": "Show all child comments"
},
"keyboardNavShowAllChildCommentsDesc": {
"message": "Show/hide all child comments on the page (comment pages only)."
},
"keyboardNavFollowPermalinkTitle": {
"message": "Follow Permalink"
},
Expand Down