- $("#id_{{$desktop_notifications.0}}_onoff").on("click", function(e){
-
- if (Notification.permission === 'granted') {
- localStorage.setItem('notification-permissions', ckbox.val()==1 ? 'granted' : 'denied');
- } else if (Notification.permission === 'denied') {
- localStorage.setItem('notification-permissions', 'denied');
-
- ckbox.val(0);
- elm.find(".on").addClass("hidden");
- elm.find(".off").removeClass("hidden");
-
- } else if (Notification.permission === 'default') {
- Notification.requestPermission(function(choice) {
- if (choice === 'granted') {
- localStorage.setItem('notification-permissions', ckbox.val()==1 ? 'granted' : 'denied');
-
- } else {
- localStorage.setItem('notification-permissions', 'denied');
- ckbox.val(0);
- elm.find(".on").addClass("hidden");
- elm.find(".off").removeClass("hidden");
- }
- });
- }
-
- //console.log(getNotificationPermission());
-
-
- })
+ $notificationCheckbox.on('change', function(e) {
+ if (Notification.permission === 'granted') {
+ localStorage.setItem('notification-permissions', $notificationCheckbox.prop('checked') ? 'granted' : 'denied');
+ } else if (Notification.permission === 'denied') {
+ localStorage.setItem('notification-permissions', 'denied');
+
+ $notificationCheckbox.prop('checked', false);
+ } else if (Notification.permission === 'default') {
+ Notification.requestPermission(function(choice) {
+ if (choice === 'granted') {
+ localStorage.setItem('notification-permissions', $notificationCheckbox.prop('checked') ? 'granted' : 'denied');
+ } else {
+ localStorage.setItem('notification-permissions', 'denied');
+ $notificationCheckbox.prop('checked', false);
+ }
+ });
+ }
+ })