Skip to content

Commit 746ad03

Browse files
committed
Extract hide prompt logic to a function
1 parent db06ede commit 746ad03

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

styles/all/template/webpush.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ function PhpbbWebpush() {
163163
if (allowBtn) {
164164
allowBtn.addEventListener('click', (event) => {
165165
event.stopPropagation();
166-
popup.style.display = 'none';
166+
hidePopup(popup);
167167
subscribeButtonHandler(event).catch(error => {
168168
console.error('Subscription handler error:', error);
169169
});
@@ -173,21 +173,31 @@ function PhpbbWebpush() {
173173
if (denyBtn) {
174174
denyBtn.addEventListener('click', (event) => {
175175
event.stopPropagation();
176-
popup.style.display = 'none';
176+
hidePopup(popup);
177177
promptDenied.set();
178178
});
179179
}
180180

181181
if (overlay) {
182182
overlay.addEventListener('click', (event) => {
183183
if (event.target === overlay) {
184-
popup.style.display = 'none';
184+
hidePopup(popup);
185185
promptDenied.set();
186186
}
187187
});
188188
}
189189
}
190190

191+
/**
192+
* Hide popup
193+
* @param popup
194+
*/
195+
function hidePopup(popup) {
196+
if (popup) {
197+
popup.style.display = 'none';
198+
}
199+
}
200+
191201
/**
192202
* Check whether subscription is valid
193203
*
@@ -282,10 +292,7 @@ function PhpbbWebpush() {
282292
});
283293
} catch (error) {
284294
promptDenied.set(); // deny the prompt on error to prevent repeated prompting
285-
const popup = document.getElementById('wpn_popup_prompt');
286-
if (popup) {
287-
popup.style.display = 'none';
288-
}
295+
hidePopup(document.getElementById('wpn_popup_prompt'));
289296
console.error('Push subscription error:', error);
290297
phpbb.alert(subscribeButton.getAttribute('data-l-err'), error.message || subscribeButton.getAttribute('data-l-unsupported'));
291298
} finally {
@@ -343,10 +350,7 @@ function PhpbbWebpush() {
343350
updateFormTokens(response.form_tokens);
344351
}
345352
promptDenied.remove();
346-
const popup = document.getElementById('wpn_popup_prompt');
347-
if (popup) {
348-
popup.style.display = 'none';
349-
}
353+
hidePopup(document.getElementById('wpn_popup_prompt'));
350354
}
351355
}
352356

0 commit comments

Comments
 (0)