adt-js-components 1.11.2 → 1.11.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/Notifications/index.js +12 -5
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { getToken, deleteToken } from "firebase/messaging";
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const $disableBtn = $('[data-adt-notifications-disable]');
|
|
3
|
+
const ENABLE_SELECTOR = '[data-adt-notifications-enable]';
|
|
4
|
+
const DISABLE_SELECTOR = '[data-adt-notifications-disable]';
|
|
6
5
|
|
|
6
|
+
const run = (config) => {
|
|
7
7
|
const updateButtons = () => {
|
|
8
|
+
const $enableBtn = $(ENABLE_SELECTOR);
|
|
9
|
+
const $disableBtn = $(DISABLE_SELECTOR);
|
|
10
|
+
|
|
8
11
|
if (Notification.permission !== 'granted') {
|
|
9
12
|
$enableBtn.show();
|
|
10
13
|
$disableBtn.hide();
|
|
@@ -27,7 +30,7 @@ const run = (config) => {
|
|
|
27
30
|
};
|
|
28
31
|
|
|
29
32
|
// Enable notifications
|
|
30
|
-
$
|
|
33
|
+
$(document).on('click', ENABLE_SELECTOR, function () {
|
|
31
34
|
if (window.messaging) {
|
|
32
35
|
Notification.requestPermission().then(function (permission) {
|
|
33
36
|
if (permission !== 'granted') {
|
|
@@ -58,7 +61,7 @@ const run = (config) => {
|
|
|
58
61
|
});
|
|
59
62
|
|
|
60
63
|
// Disable notifications
|
|
61
|
-
$
|
|
64
|
+
$(document).on('click', DISABLE_SELECTOR, function () {
|
|
62
65
|
if (window.messaging) {
|
|
63
66
|
deleteToken(window.messaging)
|
|
64
67
|
.then(function () {
|
|
@@ -100,6 +103,10 @@ const run = (config) => {
|
|
|
100
103
|
} else {
|
|
101
104
|
updateButtons();
|
|
102
105
|
}
|
|
106
|
+
|
|
107
|
+
$(document).on('ajaxComplete', function () {
|
|
108
|
+
updateButtons();
|
|
109
|
+
});
|
|
103
110
|
}
|
|
104
111
|
|
|
105
112
|
export default { run };
|