Skip to content

Commit a156afb

Browse files
committed
Improve disabled state JS
Signed-off-by: Matt Friedman <maf675@gmail.com>
1 parent c55aef6 commit a156afb

1 file changed

Lines changed: 14 additions & 15 deletions

File tree

styles/all/template/webpush.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ function PhpbbWebpush() {
5151

5252
// Service workers are only supported in secure context
5353
if (window.isSecureContext !== true) {
54-
subscribeButton.disabled = true;
55-
handleDisabledState();
54+
setDisabledState();
5655
return;
5756
}
5857

@@ -67,30 +66,30 @@ function PhpbbWebpush() {
6766
.catch(error => {
6867
console.info(error);
6968
// Service worker could not be registered
70-
subscribeButton.disabled = true;
69+
setDisabledState();
7170
});
7271
} else {
73-
subscribeButton.disabled = true;
72+
setDisabledState();
7473
}
75-
handleDisabledState();
7674
};
7775

7876
/**
7977
* If subscribing is disabled, hide dropdown toggle and update subscribe button text
8078
*
8179
* @return void
8280
*/
83-
function handleDisabledState() {
84-
if (subscribeButton.disabled) {
85-
const notificationList = document.getElementById('notification_list');
86-
const footer = notificationList.querySelector('.wpn-notification-dropdown-footer');
87-
if (footer) {
88-
footer.style.display = 'none';
89-
}
81+
function setDisabledState() {
82+
subscribeButton.disabled = true;
9083

91-
if (subscribeButton.type === 'submit' || subscribeButton.classList.contains('button')) {
92-
subscribeButton.value = subscribeButton.getAttribute('data-disabled-msg');
93-
}
84+
const notificationList = document.getElementById('notification_list');
85+
const subscribeToggle = notificationList.querySelector('.wpn-notification-dropdown-footer');
86+
87+
if (subscribeToggle) {
88+
subscribeToggle.style.display = 'none';
89+
}
90+
91+
if (subscribeButton.type === 'submit' || subscribeButton.classList.contains('button')) {
92+
subscribeButton.value = subscribeButton.getAttribute('data-disabled-msg');
9493
}
9594
}
9695

0 commit comments

Comments
 (0)