Skip to content

Commit

Permalink
Merge pull request #67 from iMattPro/Disabled-state
Browse files Browse the repository at this point in the history
  • Loading branch information
iMattPro authored Jul 2, 2024
2 parents 16e7012 + b19ad65 commit 329a938
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
7 changes: 4 additions & 3 deletions language/en/webpushnotifications_module_ucp.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@

$lang = array_merge($lang, [
'NOTIFICATION_METHOD_PHPBB_WPN_WEBPUSH' => 'Web Push',
'NOTIFY_WEBPUSH_NOTIFICATIONS' => 'Web Push Notifications',
'NOTIFY_WEBPUSH_DISABLE' => 'Disable Push Notifications',
'NOTIFY_WEBPUSH_ENABLE' => 'Enable Push Notifications',
'NOTIFY_WEBPUSH_NOTIFICATIONS' => 'Web push notifications',
'NOTIFY_WEBPUSH_DISABLE' => 'Disable push notifications',
'NOTIFY_WEBPUSH_ENABLE' => 'Enable push notifications',
'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.',
'NOTIFY_WEBPUSH_SUBSCRIBE' => 'Enable to subscribe',
'NOTIFY_WEBPUSH_UNSUBSCRIBE' => 'Disable to unsubscribe',
'NOTIFY_WEBPUSH_DROPDOWN_TITLE' => 'Visit notifications settings to set your preferred push notifications.',
'NOTIFY_WEBPUSH_DENIED' => 'You have denied notifications from this site. To enable push notifications, allow notifications from this site in your browser settings.',
'NOTIFY_WEBPUSH_DISABLED' => 'Push notifications not supported',
]);
21 changes: 21 additions & 0 deletions styles/all/template/webpush.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function PhpbbWebpush() {
// Service workers are only supported in secure context
if (window.isSecureContext !== true) {
subscribeButton.disabled = true;
handleDisabledState();
return;
}

Expand All @@ -71,8 +72,28 @@ function PhpbbWebpush() {
} else {
subscribeButton.disabled = true;
}
handleDisabledState();
};

/**
* If subscribing is disabled, hide dropdown toggle and update subscribe button text
*
* @return void
*/
function handleDisabledState() {
if (subscribeButton.disabled) {
const notificationList = document.getElementById('notification_list');
const footer = notificationList.querySelector('.wpn-notification-dropdown-footer');
if (footer) {
footer.style.display = 'none';
}

if (subscribeButton.type === 'submit' || subscribeButton.classList.contains('button')) {
subscribeButton.value = subscribeButton.getAttribute('data-disabled-msg');
}
}
}

/**
* Update button state depending on notifications state
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<dl>
<dt><label for="subscribe_webpush">{{ lang('NOTIFY_WEBPUSH_NOTIFICATIONS') ~ lang('COLON') }}</label></dt>
<dd>
<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') }}">
<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') }}">
<input id="unsubscribe_webpush" type="submit" name="unsubscribe_webpush" value="{{ lang('NOTIFY_WEBPUSH_DISABLE') }}" class="wpn button1 button button-form hidden">
<br><span>{{ lang('NOTIFY_WEBPUSH_ENABLE_EXPLAIN') }}</span>
</dd>
Expand Down

0 comments on commit 329a938

Please sign in to comment.