adt-js-components 1.11.1 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adt-js-components",
3
- "version": "1.11.1",
3
+ "version": "1.11.3",
4
4
  "description": "JavaScript components for Nette framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -25,7 +25,9 @@
25
25
  "tinymce-i18n": "^20.12.25",
26
26
  "nette.ajax.js": "^2.3.0",
27
27
  "leaflet": "^1.9.4",
28
- "leaflet.markercluster": "^1.5.3"
28
+ "leaflet.markercluster": "^1.5.3",
29
+ "firebase": "^12.10.0",
30
+ "@firebase/messaging": "^0.12.24"
29
31
  },
30
32
  "peerDependencies": {
31
33
  "jquery": "^3.4.1"
@@ -1,21 +1,36 @@
1
1
  import { getToken, deleteToken } from "firebase/messaging";
2
2
 
3
- const run = (config) => {
4
- const $enableBtn = $('[data-adt-notifications-enable]');
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
- if (Notification.permission === 'granted') {
9
- $enableBtn.hide();
10
- $disableBtn.show();
11
- } else {
8
+ const $enableBtn = $(ENABLE_SELECTOR);
9
+ const $disableBtn = $(DISABLE_SELECTOR);
10
+
11
+ if (Notification.permission !== 'granted') {
12
12
  $enableBtn.show();
13
13
  $disableBtn.hide();
14
+ return;
14
15
  }
16
+
17
+ navigator.serviceWorker.getRegistrations().then(function (registrations) {
18
+ var hasFirebaseSw = registrations.some(function (registration) {
19
+ return registration.active && registration.active.scriptURL.includes('firebase-messaging-sw');
20
+ });
21
+
22
+ if (hasFirebaseSw) {
23
+ $enableBtn.hide();
24
+ $disableBtn.show();
25
+ } else {
26
+ $enableBtn.show();
27
+ $disableBtn.hide();
28
+ }
29
+ });
15
30
  };
16
31
 
17
32
  // Enable notifications
18
- $enableBtn.on('click', function () {
33
+ $(document).on('click', ENABLE_SELECTOR, function () {
19
34
  if (window.messaging) {
20
35
  Notification.requestPermission().then(function (permission) {
21
36
  if (permission !== 'granted') {
@@ -46,7 +61,7 @@ const run = (config) => {
46
61
  });
47
62
 
48
63
  // Disable notifications
49
- $disableBtn.on('click', function () {
64
+ $(document).on('click', DISABLE_SELECTOR, function () {
50
65
  if (window.messaging) {
51
66
  deleteToken(window.messaging)
52
67
  .then(function () {
@@ -88,6 +103,10 @@ const run = (config) => {
88
103
  } else {
89
104
  updateButtons();
90
105
  }
106
+
107
+ $(document).on('ajaxComplete', function () {
108
+ updateButtons();
109
+ });
91
110
  }
92
111
 
93
112
  export default { run };