Skip to content

Commit 52b233c

Browse files
author
Tony Guntharp
committed
Merge pull request #90 from gabceb/kanda-24
Added notifications pane.
2 parents f52250d + a986430 commit 52b233c

14 files changed

+1422
-10
lines changed

app/assets/fonts/FontAwesome.otf

47.6 KB
Binary file not shown.
24.8 KB
Binary file not shown.

app/assets/fonts/fontawesome-webfont.svg

Lines changed: 284 additions & 0 deletions
Loading
53.8 KB
Binary file not shown.
28.7 KB
Binary file not shown.

app/assets/javascripts/backbone/helpers/channels.js.coffee

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,12 @@ class Kandan.Helpers.Channels
132132
.append(@newActivityView(activityAttributes).render().el)
133133

134134
@flushActivities(activityAttributes.channel_id)
135-
if not local
136-
Kandan.Helpers.Utils.notifyInTitleIfRequired(activityAttributes)
135+
136+
if not local and @getActiveChannelId() == activityAttributes.channel_id and activityAttributes.action == "message" and Kandan.Helpers.Utils.browserTabFocused != true
137+
Kandan.Helpers.Utils.notifyInTitle()
138+
Kandan.Plugins.Notifications.playAudioNotification()
139+
Kandan.Plugins.Notifications.displayNotification(activityAttributes.user.username || activityAttributes.user.email, activityAttributes.content)
140+
137141
@setPaginationData(activityAttributes.channel_id)
138142

139143

app/assets/javascripts/backbone/helpers/utils.js.coffee

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,9 @@ class Kandan.Helpers.Utils
33

44
@browserTabFocused: true
55

6-
@notifyInTitleIfRequired: (activityAttributes) ->
7-
console.log(activityAttributes)
8-
9-
if Kandan.Data.Channels.activeChannelId() == activityAttributes.channel_id and activityAttributes.action == "message" and @browserTabFocused != true
10-
Kandan.Plugins.MusicPlayer.playAudioNotice()
11-
@unreadActivities += 1
12-
$(document).attr('title', "(#{@unreadActivities}) Kandan")
13-
6+
@notifyInTitle: ()->
7+
@unreadActivities += 1
8+
$(document).attr('title', "(#{@unreadActivities}) Kandan")
149

1510
@months: [
1611
"January"

app/assets/javascripts/backbone/kandan.js.coffee.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ window.Kandan =
2828
registerPlugins: ->
2929
plugins = [
3030
"UserList"
31+
,"Notifications"
3132
,"MusicPlayer"
3233
,"YouTubeEmbed"
3334
,"VimeoEmbed"
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
class Kandan.Plugins.Notifications
2+
3+
@widget_title: "Notifications"
4+
@widget_icon_url: "/assets/people_icon.png"
5+
@pluginNamespace: "Kandan.Plugins.Notifications"
6+
7+
@popup_notifications_template: _.template '<div class="notification popup-notifications"></div>'
8+
@enable_popup_notifications_template = _.template '<a class="btn enable-popup-notifications" href="#"><i class="icon-check-empty"></i> Notifications</a>'
9+
@disable_popup_notifications_template = _.template '<a class="btn disable-popup-notifications" href="#"><i class="icon-check"></i> Notifications</a>'
10+
11+
@sound_notifications_template: _.template '<div class="notification sound-notifications"></div>'
12+
@enable_sound_notifications_template = _.template '<a class="btn enable-sound-notifications" href="#"><i class="icon-check-empty"></i> Sounds</a>'
13+
@disable_sound_notifications_template = _.template '<a class="btn disable-sound-notifications" href="#"><i class="icon-check"></i> Sounds</a>'
14+
15+
@render: ($el)->
16+
$notifications = $("<div class='notifications_list'></div>")
17+
$el.next().hide();
18+
19+
@initPopupsNotificationsButtons()
20+
21+
$el.html($notifications)
22+
23+
@initWebkitNotifications($notifications)
24+
@initSoundNotifications($notifications)
25+
26+
return
27+
28+
29+
@init: ()->
30+
Kandan.Widgets.register @pluginNamespace
31+
32+
# HTML 5 Popups
33+
@initPopupsNotificationsButtons: ()->
34+
$(document).on 'click', '.enable-popup-notifications', => @enablePopupNotifications()
35+
$(document).on 'click', '.disable-popup-notifications', => @disablePopupNotifications()
36+
return
37+
38+
@initWebkitNotifications: (container)->
39+
if Modernizr.notification
40+
container.append(@popup_notifications_template())
41+
42+
if @webkitNotificationsEnabled()
43+
@enablePopupNotifications()
44+
else
45+
@disablePopupNotifications()
46+
47+
@enablePopupNotifications: ()->
48+
if @webkitNotificationsEnabled()
49+
@popups_notifications_enabled = true
50+
$(".popup-notifications .enable-popup-notifications").remove()
51+
$(".notification.popup-notifications").append(@disable_popup_notifications_template())
52+
else
53+
if @webkitNotificationsDenied()
54+
# If the notifications have been denied we need to let the user know because there is nothing else we can do
55+
alert("It looks like notifications are denied for this page.\n\nUse your browser settings to allow notifications for this page.")
56+
else
57+
window.webkitNotifications.requestPermission(=> @onPopupNotificationsEnabled())
58+
59+
return
60+
61+
@disablePopupNotifications: ()->
62+
@popups_notifications_enabled = false
63+
64+
$(".popup-notifications .disable-popup-notifications").remove()
65+
$(".notification.popup-notifications").append(@enable_popup_notifications_template())
66+
return
67+
68+
# Returns true if notifications are enabled for this page.
69+
@webkitNotificationsEnabled: ()->
70+
window.webkitNotifications.checkPermission() == 0
71+
72+
@webkitNotificationsDenied: ()->
73+
window.webkitNotifications.checkPermission() == 2
74+
75+
# Callback when notifiactions are enabled for the first time
76+
@onPopupNotificationsEnabled: ()->
77+
if @webkitNotificationsEnabled()
78+
@enablePopupNotifications()
79+
80+
return
81+
82+
# If you are wondering why the kandan icon is not displayed on OS X this is the reason:
83+
# If you try notifying users on MacOS Mountain Lion, using a custom notification icon, don't be surprised that the Web browser icon overrides the icon you defined.
84+
# Apple locked notification icons to the app icons (for instance Chrome icon).
85+
@displayNotification: (sender, message)->
86+
if @popups_notifications_enabled && @webkitNotificationsEnabled()
87+
notification = window.webkitNotifications.createNotification('/assets/kandanlogo.png', "#{sender} says:", message);
88+
notification.onclick = ->
89+
window.focus()
90+
@cancel()
91+
return
92+
93+
notification.show();
94+
95+
# HTML 5 sounds
96+
@initSoundNotifications: ($container)->
97+
if Modernizr.audio
98+
$container.append(@sound_notifications_template())
99+
@enableSoundNotifications()
100+
@initSoundNotificationsButtons()
101+
102+
@initSoundNotificationsButtons: ()->
103+
$(document).on 'click', '.enable-sound-notifications', => @enableSoundNotifications()
104+
$(document).on 'click', '.disable-sound-notifications', => @disableSoundNotifications()
105+
return
106+
107+
@enableSoundNotifications: ()->
108+
@sound_notifications_enabled = true
109+
$(".sound-notifications .enable-sound-notifications").remove()
110+
$(".notification.sound-notifications").append(@disable_sound_notifications_template())
111+
112+
return
113+
114+
@disableSoundNotifications: ()->
115+
@sound_notifications_enabled = false
116+
117+
$(".sound-notifications .disable-sound-notifications").remove()
118+
$(".notification.sound-notifications").append(@enable_sound_notifications_template())
119+
return
120+
121+
@playAudioNotification: ()->
122+
if @sound_notifications_enabled
123+
Kandan.Plugins.MusicPlayer.playAudioNotice()
124+
return

0 commit comments

Comments
 (0)