Skip to content

Commit 0980414

Browse files
authored
Merge pull request #118 from iMattPro/improve-prompt
Improve prompt popup
2 parents c17dba0 + 558cdc4 commit 0980414

File tree

7 files changed

+57
-28
lines changed

7 files changed

+57
-28
lines changed

language/en/webpushnotifications_module_acp.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@
5151
'WEBPUSH_DROPDOWN_SUBSCRIBE' => 'Show web push settings in the notification dropdown',
5252
'WEBPUSH_DROPDOWN_SUBSCRIBE_EXPLAIN'=> 'Show or hide the “Enable Web Push” toggle switch in the notification dropdown. This allows users to easily enable or disable push notifications from any page of the forum.',
5353
'WEBPUSH_POPUP_PROMPT' => 'Show popup prompt for unsubscribed members',
54-
'WEBPUSH_POPUP_PROMPT_EXPLAIN' => 'Display a popup message asking registered members if they want to receive push notifications. The popup will only appear to members who are not currently subscribed and have not previously declined.',
54+
'WEBPUSH_POPUP_PROMPT_EXPLAIN' => 'Display a popup message asking registered members if they want to receive push notifications. The popup will only appear to members who are not currently subscribed and have not previously denied.',
5555
'WEBPUSH_INSECURE_SERVER_ERROR' => 'This board is not using a secure SSL/HTTPS protocol, which is required for enabling web push notifications. Alternatively, the server environment might be misconfigured. Ensure that the <em>HTTPS</em> and <em>HEADER_CLIENT_PROTO</em> server environment variables are correctly configured.',
5656
]);

language/en/webpushnotifications_module_ucp.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,5 @@
5252
'NOTIFY_WEBPUSH_POPUP_TITLE' => 'Allow browser notifications?',
5353
'NOTIFY_WEBPUSH_POPUP_MESSAGE' => 'We would like to send you browser notifications for replies, private messages, and relevant forum activity. Optional — you can manage these settings at any time.',
5454
'NOTIFY_WEBPUSH_POPUP_ALLOW' => 'Allow',
55-
'NOTIFY_WEBPUSH_POPUP_DECLINE' => 'Decline',
55+
'NOTIFY_WEBPUSH_POPUP_DENY' => 'Deny',
5656
]);

language/ru/webpushnotifications_module_ucp.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,5 @@
5252
'NOTIFY_WEBPUSH_POPUP_TITLE' => 'Включить браузерные уведомления?',
5353
'NOTIFY_WEBPUSH_POPUP_MESSAGE' => 'Браузерные уведомления позволяют быстро получать информацию о новых ответах, личных сообщениях и других активностях на данной конференции. Функцию можно отключить или включить в любое время в настройках уведомлений в Личном разделе.',
5454
'NOTIFY_WEBPUSH_POPUP_ALLOW' => 'Включить',
55-
'NOTIFY_WEBPUSH_POPUP_DECLINE' => 'Отклонить',
55+
'NOTIFY_WEBPUSH_POPUP_DENY' => 'Отклонить',
5656
]);

styles/all/template/webpush.js

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* global phpbb */
22

3-
'use strict';
4-
53
function PhpbbWebpush() {
4+
'use strict';
5+
66
/** @type {string} URL to service worker */
77
let serviceWorkerUrl = '';
88

@@ -126,8 +126,8 @@ function PhpbbWebpush() {
126126
return;
127127
}
128128

129-
// Check if user declined on this browser
130-
if (getDeclined() === 'true') {
129+
// Check if user denied prompt on this browser
130+
if (promptDenied.get() === 'true') {
131131
return;
132132
}
133133

@@ -157,30 +157,32 @@ function PhpbbWebpush() {
157157
}, 1000);
158158

159159
const allowBtn = document.getElementById('wpn_popup_allow');
160-
const declineBtn = document.getElementById('wpn_popup_decline');
160+
const denyBtn = document.getElementById('wpn_popup_deny');
161161
const overlay = document.getElementById('wpn_popup_prompt');
162162

163163
if (allowBtn) {
164164
allowBtn.addEventListener('click', (event) => {
165165
event.stopPropagation();
166166
popup.style.display = 'none';
167-
subscribeButtonHandler({ preventDefault: () => {} });
167+
subscribeButtonHandler({
168+
preventDefault: () => {}
169+
});
168170
});
169171
}
170172

171-
if (declineBtn) {
172-
declineBtn.addEventListener('click', (event) => {
173+
if (denyBtn) {
174+
denyBtn.addEventListener('click', (event) => {
173175
event.stopPropagation();
174176
popup.style.display = 'none';
175-
setDeclined();
177+
promptDenied.set();
176178
});
177179
}
178180

179181
if (overlay) {
180182
overlay.addEventListener('click', (event) => {
181183
if (event.target === overlay) {
182184
popup.style.display = 'none';
183-
setDeclined();
185+
promptDenied.set();
184186
}
185187
});
186188
}
@@ -328,7 +330,7 @@ function PhpbbWebpush() {
328330
if ('form_tokens' in response) {
329331
updateFormTokens(response.form_tokens);
330332
}
331-
resetDeclined();
333+
promptDenied.remove();
332334
const popup = document.getElementById('wpn_popup_prompt');
333335
if (popup) {
334336
popup.style.display = 'none';
@@ -379,18 +381,26 @@ function PhpbbWebpush() {
379381
return outputArray;
380382
}
381383

382-
function setDeclined() {
383-
localStorage.setItem('wpn_popup_declined', 'true');
384-
}
385-
function getDeclined() {
386-
return localStorage.getItem('wpn_popup_declined');
387-
}
388-
function resetDeclined() {
389-
localStorage.removeItem('wpn_popup_declined');
390-
}
384+
const promptDenied = {
385+
key: 'wpn_popup_denied',
386+
387+
set() {
388+
localStorage.setItem(this.key, 'true');
389+
},
390+
391+
get() {
392+
return localStorage.getItem(this.key);
393+
},
394+
395+
remove() {
396+
localStorage.removeItem(this.key);
397+
}
398+
};
391399
}
392400

393401
function domReady(callBack) {
402+
'use strict';
403+
394404
if (document.readyState === 'loading') {
395405
document.addEventListener('DOMContentLoaded', callBack);
396406
} else {
@@ -401,6 +411,8 @@ function domReady(callBack) {
401411
phpbb.webpush = new PhpbbWebpush();
402412

403413
domReady(() => {
414+
'use strict';
415+
404416
/* global phpbbWebpushOptions */
405417
phpbb.webpush.init(phpbbWebpushOptions);
406418
});

styles/all/template/webpush_popup.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22
<div id="wpn_popup_prompt" class="wpn-popup-overlay" style="display:none;">
33
<div class="wpn-popup-container">
44
<div class="wpn-popup-content">
5-
<h3 class="wpn-popup-title">{{ lang('NOTIFY_WEBPUSH_POPUP_TITLE') }}</h3>
5+
<h3 class="wpn-popup-title">
6+
<span>{{ lang('NOTIFY_WEBPUSH_POPUP_TITLE') }}</span>
7+
<span class="fa-stack fa-lg">
8+
<i class="fa fa-circle fa-stack-2x"></i>
9+
<i class="fa fa-bell fa-stack-1x fa-inverse"></i>
10+
</span>
11+
</h3>
612
<p class="wpn-popup-message">{{ lang('NOTIFY_WEBPUSH_POPUP_MESSAGE') }}</p>
713
<div class="wpn-popup-buttons">
814
<button id="wpn_popup_allow" class="wpn-popup-btn wpn-popup-btn-allow">{{ lang('NOTIFY_WEBPUSH_POPUP_ALLOW') }}</button>
9-
<button id="wpn_popup_decline" class="wpn-popup-btn wpn-popup-btn-decline">{{ lang('NOTIFY_WEBPUSH_POPUP_DECLINE') }}</button>
15+
<button id="wpn_popup_deny" class="wpn-popup-btn wpn-popup-btn-deny">{{ lang('NOTIFY_WEBPUSH_POPUP_DENY') }}</button>
1016
</div>
1117
</div>
1218
</div>

styles/all/theme/phpbb_wpn.css

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,20 @@
9595
font-size: 18px;
9696
font-weight: 600;
9797
color: #333333;
98+
display: flex;
99+
justify-content: space-between;
100+
align-items: center;
98101
margin: 0 0 12px;
99102
}
100103

104+
.wpn-popup-title .fa-stack-2x {
105+
color: #0066cc;
106+
}
107+
108+
.wpn-popup-title .fa-stack-1x {
109+
top: -1px;
110+
}
111+
101112
.wpn-popup-message {
102113
font-size: 14px;
103114
line-height: 1.5;
@@ -130,12 +141,12 @@
130141
background: #0052a3;
131142
}
132143

133-
.wpn-popup-btn-decline {
144+
.wpn-popup-btn-deny {
134145
background: #f0f0f0;
135146
color: #666666;
136147
}
137148

138-
.wpn-popup-btn-decline:hover {
149+
.wpn-popup-btn-deny:hover {
139150
background: #e0e0e0;
140151
}
141152

tests/functional/functional_test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function test_popup_prompt()
159159
$this->assertContainsLang('NOTIFY_WEBPUSH_POPUP_TITLE', $crawler->filter('.wpn-popup-title')->text());
160160
$this->assertContainsLang('NOTIFY_WEBPUSH_POPUP_MESSAGE', $crawler->filter('.wpn-popup-message')->text());
161161
$this->assertContainsLang('NOTIFY_WEBPUSH_POPUP_ALLOW', $crawler->filter('#wpn_popup_allow')->text());
162-
$this->assertContainsLang('NOTIFY_WEBPUSH_POPUP_DECLINE', $crawler->filter('#wpn_popup_decline')->text());
162+
$this->assertContainsLang('NOTIFY_WEBPUSH_POPUP_DENY', $crawler->filter('#wpn_popup_deny')->text());
163163
}
164164

165165
protected function set_acp_option($option, $value)

0 commit comments

Comments
 (0)