From bade81cd431624f7aa9bd859e1d2992ebf529a5d Mon Sep 17 00:00:00 2001 From: jwbth Date: Sun, 1 Dec 2024 10:00:43 +0400 Subject: [PATCH] Apply minor improvements Change-Id: I79a66bfffad1d1be2fe6f126835e82010436e3f8 --- ...nvenientDiscussions-generateBasicConfig.js | 2 +- src/Button.js | 1 + src/Section.js | 13 ++++----- src/Thread.js | 27 ++++++++++--------- src/navPanel.js | 2 -- 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/misc/convenientDiscussions-generateBasicConfig.js b/misc/convenientDiscussions-generateBasicConfig.js index 9ca545c8..ef820df4 100644 --- a/misc/convenientDiscussions-generateBasicConfig.js +++ b/misc/convenientDiscussions-generateBasicConfig.js @@ -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('{{')) { diff --git a/src/Button.js b/src/Button.js index 7feab6a9..c53ac258 100644 --- a/src/Button.js +++ b/src/Button.js @@ -291,6 +291,7 @@ class Button { prototype.setAttribute('role', 'button'); this.prototypes[tagName] = prototype; } + return this.prototypes[tagName].cloneNode(true); } } diff --git a/src/Section.js b/src/Section.js index d9f93163..2f5b8b67 100644 --- a/src/Section.js +++ b/src/Section.js @@ -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. @@ -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. diff --git a/src/Thread.js b/src/Thread.js index 7da2d8be..bd284f46 100644 --- a/src/Thread.js +++ b/src/Thread.js @@ -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' }); } } @@ -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 + ); } /** @@ -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', diff --git a/src/navPanel.js b/src/navPanel.js index 07516497..516705b9 100644 --- a/src/navPanel.js +++ b/src/navPanel.js @@ -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,