Abstract desktop notifications to a class
[KiwiIRC.git] / client / src / applets / settings.js
index f041ab196506c6ba4efe2fcbed8ceb52707540e2..504fe60fe984be2c20e026c3b7f5457fc56f9a13 100644 (file)
@@ -4,7 +4,7 @@
             'change [data-setting]': 'saveSettings',\r
             'click [data-setting="theme"]': 'selectTheme',\r
             'click .register_protocol': 'registerProtocol',\r
-            'click .enable_notifications': 'enableNoticiations'\r
+            'click .enable_notifications': 'enableNotifications'\r
         },\r
 \r
         initialize: function (options) {\r
@@ -36,8 +36,9 @@
                 this.$el.find('.protocol_handler').remove();\r
             }\r
 \r
-            if (!window.webkitNotifications) {\r
-                this.$el.find('notification_enabler').remove();\r
+\r
+            if (_kiwi.global.utils.notifications.allowed() !== null) {\r
+                this.$el.find('.notification_enabler').remove();\r
             }\r
 \r
             // Incase any settings change while we have this open, update them\r
         },\r
 \r
         selectTheme: function(event) {\r
+            event.preventDefault();\r
+\r
             $('[data-setting="theme"].active', this.$el).removeClass('active');\r
             $(event.currentTarget).addClass('active').trigger('change');\r
-            event.preventDefault();\r
         },\r
 \r
         registerProtocol: function (event) {\r
+            event.preventDefault();\r
+\r
             navigator.registerProtocolHandler('irc', document.location.origin + _kiwi.app.get('base_path') + '/%s', 'Kiwi IRC');\r
             navigator.registerProtocolHandler('ircs', document.location.origin + _kiwi.app.get('base_path') + '/%s', 'Kiwi IRC');\r
         },\r
 \r
-        enableNoticiations: function(event){\r
-            window.webkitNotifications.requestPermission();\r
+        enableNotifications: function(event){\r
+            event.preventDefault();\r
+            var notifications = _kiwi.global.utils.notifications;\r
+            notifications.requestPermission().always(_.bind(function () {\r
+                if (notifications.allowed() !== null) {\r
+                    this.$('.notification_enabler').remove();\r
+                }\r
+            }, this));\r
         }\r
 \r
     });\r