1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-12-22 21:40:08 +00:00

Use new notification API

This commit is contained in:
Tim Düsterhus 2013-04-11 17:58:04 +02:00
parent 70d2aa7df0
commit 4ff62179df

View File

@ -216,11 +216,12 @@ window.console ?=
@oldScrollTop = $('.timsChatMessageContainer').scrollTop() @oldScrollTop = $('.timsChatMessageContainer').scrollTop()
# Desktop Notifications # Desktop Notifications
unless typeof window.webkitNotifications is 'undefined' if window.Notification?
$('#timsChatNotify').click (event) -> $('#timsChatNotify').click (event) ->
if $(@).data('status') and window.webkitNotifications.checkPermission() isnt 0 return unless $(@).data 'status'
window.webkitNotifications.requestPermission() if window.Notification.permission isnt 'granted'
window.Notification.requestPermission (permission) ->
window.Notification.permission ?= permission
### ###
# Changes the chat-room. # Changes the chat-room.
# #
@ -480,18 +481,16 @@ window.console ?=
title: $('#timsChatRoomList .activeMenuItem a').text() title: $('#timsChatRoomList .activeMenuItem a').text()
# Desktop Notifications # Desktop Notifications
if typeof window.webkitNotifications isnt 'undefined' title = WCF.Language.get 'chat.general.notify.title'
if window.webkitNotifications.checkPermission() is 0 content = message.username + message.separator + (if message.separator is ' ' then '' else ' ') + message.message
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 if window.Notification?
setTimeout () -> if window.Notification.permission is 'granted'
notification.cancel() notification = new window.Notification title,
, 10e3 body: content
onclick: ->
notification.close()
setTimeout notification.close, 5e3
### ###
# Refreshes the room-list. # Refreshes the room-list.
### ###