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

Update diff files toggle button placement #176

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
29 changes: 13 additions & 16 deletions github-diff-file-toggle.user.js
Original file line number Diff line number Diff line change
@@ -26,29 +26,32 @@

const setToggleStyle = state => {
const mainToggle = $(".ghdt-toggle");
mainToggle.classList.toggle("ghdt-selected", state);
mainToggle.style = state
? "background-color: var(--color-btn-selected-bg);"
: "";
if (mainToggle) {
mainToggle.classList.toggle("ghdt-selected", state);
mainToggle.style = state ? "background-color: var(--color-btn-selected-bg);" : "";
}
};

const buildButton = () => {
const init = () => {
if (!$(".ghdt-toggle")) {
const button = make({
const toggleButton = make({
el: "button",
className: "btn btn-sm ghdt-toggle tooltipped tooltipped-s float-right",
text: "Toggle viewed",
attrs: {
"aria-label": "Toggle all viewed files"
}
});
on(button, "click", event => {
on(toggleButton, "click", event => {
toggle(document, !event.target.classList.contains("ghdt-selected"));
});
$("#files.diff-view")?.prepend(button);
const diffBarItem = make({
el: "div",
className: "diffbar-item js-batched-reviewed mr-3",
}, [toggleButton]);
$("diff-layout > div.pr-toolbar > div.diffbar > div.pr-review-tools")?.prepend(diffBarItem);
Nirmal4G marked this conversation as resolved.
Show resolved Hide resolved
}
// Update toggle button state after initialized; timer for progressive
// loading
// Update toggle button state after initialized; timer for progressive loading
clearTimeout(timer);
timer = setTimeout(() => {
if ($$(".js-reviewed-checkbox").every(el => el.checked)) {
@@ -78,12 +81,6 @@
}
};

const init = () => {
if ($("#files.diff-view") || $(".pr-toolbar")) {
buildButton();
}
};

on(document, "ghmo:container ghmo:diff", init);
on(document, "click", debounce(handleChange));
on(document, "keydown", debounce(handleChange));