From 4ff62179df98c4258d174e875ac604bbd85087a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Thu, 11 Apr 2013 17:58:04 +0200 Subject: [PATCH] Use new notification API --- file/js/be.bastelstu.Chat.coffee | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/file/js/be.bastelstu.Chat.coffee b/file/js/be.bastelstu.Chat.coffee index 06a64a5..80cb6db 100644 --- a/file/js/be.bastelstu.Chat.coffee +++ b/file/js/be.bastelstu.Chat.coffee @@ -216,11 +216,12 @@ window.console ?= @oldScrollTop = $('.timsChatMessageContainer').scrollTop() # Desktop Notifications - unless typeof window.webkitNotifications is 'undefined' + if window.Notification? $('#timsChatNotify').click (event) -> - if $(@).data('status') and window.webkitNotifications.checkPermission() isnt 0 - window.webkitNotifications.requestPermission() - + return unless $(@).data 'status' + if window.Notification.permission isnt 'granted' + window.Notification.requestPermission (permission) -> + window.Notification.permission ?= permission ### # Changes the chat-room. # @@ -480,18 +481,16 @@ window.console ?= title: $('#timsChatRoomList .activeMenuItem a').text() # Desktop Notifications - if typeof window.webkitNotifications isnt 'undefined' - if window.webkitNotifications.checkPermission() is 0 - title = WCF.Language.get 'chat.general.notify.title' - icon = "data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D" # empty gif - content = message.username + message.separator + (if message.separator is ' ' then '' else ' ') + message.message - notification = window.webkitNotifications.createNotification icon, title, content - notification.show() - - # Hide notification after 10 seconds - setTimeout () -> - notification.cancel() - , 10e3 + title = WCF.Language.get 'chat.general.notify.title' + content = message.username + message.separator + (if message.separator is ' ' then '' else ' ') + message.message + + if window.Notification? + if window.Notification.permission is 'granted' + notification = new window.Notification title, + body: content + onclick: -> + notification.close() + setTimeout notification.close, 5e3 ### # Refreshes the room-list. ###