]> git.mxchange.org Git - friendica.git/commitdiff
Update desktop notifications logic without yesno field
authorHypolite Petovan <hypolite@mrpetovan.com>
Thu, 6 Feb 2020 02:38:22 +0000 (21:38 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Thu, 6 Feb 2020 15:25:33 +0000 (10:25 -0500)
view/templates/settings/settings.tpl
view/theme/frio/templates/settings/settings.tpl

index 3811e4f25c4169e1c25f2f3cb45568b9db63256a..511dfdcb3d53399a46434fb5c1d662cfbe1883a4 100644 (file)
 {{include file="field_checkbox.tpl" field=$desktop_notifications}}
 <script>
 (function(){
-    var elm = $("#id_{{$desktop_notifications.0}}_onoff");
-    var ckbox = $("#id_{{$desktop_notifications.0}}");
-
-    if (getNotificationPermission() === 'granted') {
-        ckbox.val(1);
-        elm.find(".off").addClass("hidden");
-        elm.find(".on").removeClass("hidden");
-    }
+       let $notificationField = $("#div_id_{{$desktop_notifications.0}}");
+       let $notificationCheckbox = $("#id_{{$desktop_notifications.0}}");
+
+       if (getNotificationPermission() === 'granted') {
+               $notificationCheckbox.prop('checked', true);
+       }
        if (getNotificationPermission() === null) {
-               elm.parent(".field.yesno").hide();
+               $notificationField.hide();
        }
 
-    $("#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);
+                               }
+                       });
+               }
+       })
 })();
 </script>
 
index 3cf750a68b29f01df1a6e1e39c7d5c37469593b3..1b8481155736ad1f00ce6bd6d004eb7aa827d5ac 100644 (file)
                                                        {{include file="field_checkbox.tpl" field=$desktop_notifications}}
                                                        <script type="text/javascript">
                                                                (function(){
-                                                                       var elm = $("#id_{{$desktop_notifications.0}}_onoff");
-                                                                       var ckbox = $("#id_{{$desktop_notifications.0}}");
+                                                                       let $notificationField = $("#div_id_{{$desktop_notifications.0}}");
+                                                                       let $notificationCheckbox = $("#id_{{$desktop_notifications.0}}");
 
                                                                        if (getNotificationPermission() === 'granted') {
-                                                                               ckbox.val(1);
-                                                                               elm.find(".off").addClass("hidden");
-                                                                               elm.find(".on").removeClass("hidden");
+                                                                               $notificationCheckbox.prop('checked', true);
                                                                        }
                                                                        if (getNotificationPermission() === null) {
-                                                                               elm.parent(".field.yesno").hide();
+                                                                               $notificationField.hide();
                                                                        }
 
-                                                                       $("#id_{{$desktop_notifications.0}}_onoff").on("click", function(e){
-
+                                                                       $notificationCheckbox.on('change', function(e){
                                                                                if (Notification.permission === 'granted') {
-                                                                                       localStorage.setItem('notification-permissions', ckbox.val()==1 ? 'granted' : 'denied');
+                                                                                       localStorage.setItem('notification-permissions', $notificationCheckbox.prop('checked') ? '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");
-
+                                                                                       $notificationCheckbox.prop('checked', false);
                                                                                } else if (Notification.permission === 'default') {
                                                                                        Notification.requestPermission(function(choice) {
                                                                                                if (choice === 'granted') {
-                                                                                                       localStorage.setItem('notification-permissions', ckbox.val()==1 ? 'granted' : 'denied');
-
+                                                                                                       localStorage.setItem('notification-permissions', $notificationCheckbox.prop('checked') ? 'granted' : 'denied');
                                                                                                } else {
                                                                                                        localStorage.setItem('notification-permissions', 'denied');
-                                                                                                       ckbox.val(0);
-                                                                                                       elm.find(".on").addClass("hidden");
-                                                                                                       elm.find(".off").removeClass("hidden");
+                                                                                                       $notificationCheckbox.prop('checked', false);
                                                                                                }
                                                                                        });
                                                                                }
-
-                                                                               //console.log(getNotificationPermission());
                                                                        })
                                                                })();
                                                        </script>