Skip to content

Commit 329a938

Browse files
authored
Merge pull request #67 from iMattPro/Disabled-state
2 parents 16e7012 + b19ad65 commit 329a938

3 files changed

Lines changed: 26 additions & 4 deletions

File tree

language/en/webpushnotifications_module_ucp.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@
3939

4040
$lang = array_merge($lang, [
4141
'NOTIFICATION_METHOD_PHPBB_WPN_WEBPUSH' => 'Web Push',
42-
'NOTIFY_WEBPUSH_NOTIFICATIONS' => 'Web Push Notifications',
43-
'NOTIFY_WEBPUSH_DISABLE' => 'Disable Push Notifications',
44-
'NOTIFY_WEBPUSH_ENABLE' => 'Enable Push Notifications',
42+
'NOTIFY_WEBPUSH_NOTIFICATIONS' => 'Web push notifications',
43+
'NOTIFY_WEBPUSH_DISABLE' => 'Disable push notifications',
44+
'NOTIFY_WEBPUSH_ENABLE' => 'Enable push notifications',
4545
'NOTIFY_WEBPUSH_ENABLE_EXPLAIN' => 'Enabling push notifications will activate them on this device only. You can turn off notifications at any time through your browser settings or by clicking the button above. Additionally, if no web push notification types are selected below, you will not receive any web push notifications.',
4646
'NOTIFY_WEBPUSH_SUBSCRIBE' => 'Enable to subscribe',
4747
'NOTIFY_WEBPUSH_UNSUBSCRIBE' => 'Disable to unsubscribe',
4848
'NOTIFY_WEBPUSH_DROPDOWN_TITLE' => 'Visit notifications settings to set your preferred push notifications.',
4949
'NOTIFY_WEBPUSH_DENIED' => 'You have denied notifications from this site. To enable push notifications, allow notifications from this site in your browser settings.',
50+
'NOTIFY_WEBPUSH_DISABLED' => 'Push notifications not supported',
5051
]);

styles/all/template/webpush.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ function PhpbbWebpush() {
5252
// Service workers are only supported in secure context
5353
if (window.isSecureContext !== true) {
5454
subscribeButton.disabled = true;
55+
handleDisabledState();
5556
return;
5657
}
5758

@@ -71,8 +72,28 @@ function PhpbbWebpush() {
7172
} else {
7273
subscribeButton.disabled = true;
7374
}
75+
handleDisabledState();
7476
};
7577

78+
/**
79+
* If subscribing is disabled, hide dropdown toggle and update subscribe button text
80+
*
81+
* @return void
82+
*/
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+
}
90+
91+
if (subscribeButton.type === 'submit' || subscribeButton.classList.contains('button')) {
92+
subscribeButton.value = subscribeButton.getAttribute('data-disabled-msg');
93+
}
94+
}
95+
}
96+
7697
/**
7798
* Update button state depending on notifications state
7899
*

styles/prosilver/template/event/ucp_notifications_content_before.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<dl>
66
<dt><label for="subscribe_webpush">{{ lang('NOTIFY_WEBPUSH_NOTIFICATIONS') ~ lang('COLON') }}</label></dt>
77
<dd>
8-
<input id="subscribe_webpush" type="submit" name="subscribe_webpush" value="{{ lang('NOTIFY_WEBPUSH_ENABLE') }}" class="wpn button1 button button-form" data-l-err="{{ lang('INFORMATION') }}" data-l-msg="{{ lang('NOTIFY_WEBPUSH_DENIED') }}">
8+
<input id="subscribe_webpush" type="submit" name="subscribe_webpush" value="{{ lang('NOTIFY_WEBPUSH_ENABLE') }}" class="wpn button1 button button-form" data-l-err="{{ lang('INFORMATION') }}" data-l-msg="{{ lang('NOTIFY_WEBPUSH_DENIED') }}" data-disabled-msg="{{ lang('NOTIFY_WEBPUSH_DISABLED') }}">
99
<input id="unsubscribe_webpush" type="submit" name="unsubscribe_webpush" value="{{ lang('NOTIFY_WEBPUSH_DISABLE') }}" class="wpn button1 button button-form hidden">
1010
<br><span>{{ lang('NOTIFY_WEBPUSH_ENABLE_EXPLAIN') }}</span>
1111
</dd>

0 commit comments

Comments
 (0)