Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibilità di rimuovere template HTML #3

Merged
merged 3 commits into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
aggiunta possibilità di rimuovere il template HTML
  • Loading branch information
niciz committed Mar 25, 2020
commit e7e8143a5290607ca87528d5ef2e5e11d82fa287
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ So you can call the Notifications widget in your app layout to show generated no
```

You can customize the HTML template for the widget as follow.
When you customize the template remember to include a button with id 'js-web-push-subscribe-button':
Setting template to false will hide all widget HTML and the browser will prompts the user to allow notifications.
If you customize the HTML template remember to include a button with id 'js-web-push-subscribe-button':

```html
<div>
Expand Down
39 changes: 27 additions & 12 deletions assets/js/web-notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,23 @@ var WebNotifications = (function(opts) {
});

// initialize page button for subscribe notification
subscribeButton.addEventListener('click', function () {
if (isSubscribed) {
unsubscribe();
} else {
if(subscribeButton) {
subscribeButton.addEventListener('click', function () {
if (isSubscribed) {
unsubscribe();
} else {
subscribe();
}
});

// enable button
subscribeButton.disabled = false;
}
else {
if (!isSubscribed) {
subscribe();
}
});

// enable button
subscribeButton.disabled = false;
}

}

Expand All @@ -136,7 +143,9 @@ var WebNotifications = (function(opts) {
function unsubscribe() {

// Disable the button so it can't be changed while we process the permission request
subscribeButton.disabled = true;
if(subscribeButton) {
subscribeButton.disabled = true;
}

navigator.serviceWorker.ready.then(function (serviceWorkerRegistration) {
// To unsubscribe from push messaging, you need get the subscription object, which you can call unsubscribe() on.
Expand Down Expand Up @@ -167,7 +176,9 @@ var WebNotifications = (function(opts) {
isSubscribed = false;

updateButtonSubscribeStatus();
subscribeButton.disabled = false;
if(subscribeButton) {
subscribeButton.disabled = false;
}

return sendUnsubscriptionToServer(pushSubscription);

Expand All @@ -186,7 +197,9 @@ var WebNotifications = (function(opts) {
function subscribe() {

// Disable the button so it can't be changed while we process the permission request
subscribeButton.disabled = true;
if(subscribeButton) {
subscribeButton.disabled = true;
}

navigator.serviceWorker.ready.then(function (serviceWorkerRegistration) {
serviceWorkerRegistration.pushManager.subscribe({
Expand All @@ -200,7 +213,9 @@ var WebNotifications = (function(opts) {
isSubscribed = true;

updateButtonSubscribeStatus();
subscribeButton.disabled = false;
if(subscribeButton) {
subscribeButton.disabled = false;
}

return sendSubscriptionToServer(pushSubscription);

Expand Down
3 changes: 3 additions & 0 deletions widgets/WebNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ public function run()
protected function renderSubscribeButton()
{

if($this->template === false) {
return '';
}
if($this->template) {
return $this->template;
}
Expand Down