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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adt-js-components",
3
- "version": "1.11.2",
3
+ "version": "1.11.3",
4
4
  "description": "JavaScript components for Nette framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,10 +1,13 @@
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
+ 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
- $enableBtn.on('click', function () {
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
- $disableBtn.on('click', function () {
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 };