Skip to content

Commit

Permalink
Apply minor improvements
Browse files Browse the repository at this point in the history
Change-Id: I79a66bfffad1d1be2fe6f126835e82010436e3f8
  • Loading branch information
jwbth committed Dec 1, 2024
1 parent 4aaa998 commit bade81c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion misc/convenientDiscussions-generateBasicConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ mw.loader.using([

const signatureMessage = (await api.getMessages('Signature', {
amlang: mw.config.get('wgContentLanguage'),
amincludelocal: 1
amincludelocal: 1,
})).Signature;
const parsedSignature = await api.parse(signatureMessage, { disablelimitreport: true });
if (!parsedSignature.includes('{{')) {
Expand Down
1 change: 1 addition & 0 deletions src/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ class Button {
prototype.setAttribute('role', 'button');
this.prototypes[tagName] = prototype;
}

return this.prototypes[tagName].cloneNode(true);
}
}
Expand Down
13 changes: 7 additions & 6 deletions src/Section.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,12 +491,9 @@ class Section extends SectionSkeleton {
/**
* Show or hide a popup with the list of users who have posted in the section.
*
* @param {Event} event
* @private
*/
toggleAuthors(event) {
event.preventDefault();

toggleAuthors() {
if (!this.authorsPopup) {
/**
* Popup with the list of users who have posted in the section.
Expand Down Expand Up @@ -647,10 +644,14 @@ class Section extends SectionSkeleton {

const span = commentCountWrapper.querySelector('.cd-section-metadata-authorcount-link');
if (span) {
// A tiny bit slower on long pages than direct element creation, but at least this can be
// triggered by Enter.
authorCountButton = new Button({
label: span.textContent,
action: this.toggleAuthors.bind(this),
})
action: () => {
this.toggleAuthors();
},
});

// `role` changes the link color, making it different from the color of neighboring links,
// and I think it doesn't really give any benefit.
Expand Down
27 changes: 14 additions & 13 deletions src/Thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,23 +316,23 @@ class Thread {
/**
* Handle the `mouseup` event on the click area.
*
* @param {Event} e
* @param {Event} event
* @private
*/
handleClickAreaMouseUp(e) {
if (this.navMode && e.button === 0) {
handleClickAreaMouseUp(event) {
if (this.navMode && event.button === 0) {
// `mouseup` event comes before `click`, so we need to block collapsing the thread is the user
// clicked the left button to navigate threads.
this.blockClickEvent = true;
}

// Middle or left button.
if (e.button === 1 || e.button === 0) {
if (event.button === 1 || event.button === 0) {
this.handleClickAreaHover(undefined, true);
}

// Middle button
if (e.button === 1 && this.navMode && !this.hasMouseMoved(e)) {
if (event.button === 1 && this.navMode && !this.hasMouseMoved(event)) {
this.rootComment.scrollTo({ alignment: 'top' });
}
}
Expand All @@ -341,11 +341,13 @@ class Thread {
* Has the mouse moved enough to consider it a navigation gesture and not a click with an
* insignificant mouse movement between pressing and releasing a button.
*
* @param {MouseEvent} e
* @param {MouseEvent} event
* @returns {boolean}
*/
hasMouseMoved(e) {
return Math.abs(e.clientX - this.navFromX) >= 5 || Math.abs(e.clientY - this.navFromY) >= 5;
hasMouseMoved(event) {
return (
Math.abs(event.clientX - this.navFromX) >= 5 || Math.abs(event.clientY - this.navFromY) >= 5
);
}

/**
Expand Down Expand Up @@ -374,22 +376,21 @@ class Thread {
/**
* Handle the `mousemove` event when the navigation mode is active.
*
* @param {Event} e
* @param {Event} event
* @private
*/
handleDocumentMouseMove(e) {
handleDocumentMouseMove(event) {
if (!this.navMode) {
// This implies `this.navFromX !== undefined`, .navFromX set in .handleClickAreaMouseDown()

if (this.hasMouseMoved(e)) {
if (this.hasMouseMoved(event)) {
$(document).off('mousemove.cd', this.documentMouseMoveHandler);
this.enterNavMode(this.navFromX, this.navFromY, true);
}
return;
}

const delta = e.clientY - this.navFromY;
const target = this.getNavTarget(delta);
const target = this.getNavTarget(event.clientY - this.navFromY);
if (target && this.navScrolledTo !== target) {
target.scrollTo({
alignment: target.logicalLevel === this.rootComment.logicalLevel ? 'top' : 'bottom',
Expand Down
2 changes: 0 additions & 2 deletions src/navPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,6 @@ export default {
* @private
*/
refreshClick(markAsRead) {
// There was reload confirmation here, but after session restore was introduced, the
// confirmation seems to be no longer needed.
controller.reload({
commentIds: controller.getRelevantAddedCommentIds(),
markAsRead,
Expand Down

0 comments on commit bade81c

Please sign in to comment.