Skip to content

Commit 99eb3e5

Browse files
committed
Comments: Fixed JS error when lacking commenting permissions
The page comments component would throw an error due to references to form elements/content, when form elements may not exist due to permisisons. For #4531
1 parent 15da4b9 commit 99eb3e5

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

resources/js/components/page-comments.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,12 @@ export class PageComments extends Component {
2727

2828
// Internal State
2929
this.parentId = null;
30-
this.formReplyText = this.formReplyLink.textContent;
30+
this.formReplyText = this.formReplyLink?.textContent || '';
3131

3232
this.setupListeners();
3333
}
3434

3535
setupListeners() {
36-
this.removeReplyToButton.addEventListener('click', this.removeReplyTo.bind(this));
37-
this.hideFormButton.addEventListener('click', this.hideForm.bind(this));
38-
this.addCommentButton.addEventListener('click', this.showForm.bind(this));
39-
4036
this.elem.addEventListener('page-comment-delete', () => {
4137
this.updateCount();
4238
this.hideForm();
@@ -47,6 +43,9 @@ export class PageComments extends Component {
4743
});
4844

4945
if (this.form) {
46+
this.removeReplyToButton.addEventListener('click', this.removeReplyTo.bind(this));
47+
this.hideFormButton.addEventListener('click', this.hideForm.bind(this));
48+
this.addCommentButton.addEventListener('click', this.showForm.bind(this));
5049
this.form.addEventListener('submit', this.saveComment.bind(this));
5150
}
5251
}
@@ -123,9 +122,8 @@ export class PageComments extends Component {
123122
this.showForm();
124123
this.parentId = commentLocalId;
125124
this.replyToRow.toggleAttribute('hidden', false);
126-
const replyLink = this.replyToRow.querySelector('a');
127-
replyLink.textContent = this.formReplyText.replace('1234', this.parentId);
128-
replyLink.href = `#comment${this.parentId}`;
125+
this.formReplyLink.textContent = this.formReplyText.replace('1234', this.parentId);
126+
this.formReplyLink.href = `#comment${this.parentId}`;
129127
}
130128

131129
removeReplyTo() {

0 commit comments

Comments
 (0)