Navigation Menu

Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/kandanapp/kandan
Browse files Browse the repository at this point in the history
  • Loading branch information
gabceb committed Mar 1, 2013
2 parents d526da8 + 3b39026 commit 1eadbbd
Show file tree
Hide file tree
Showing 19 changed files with 71 additions and 38 deletions.
8 changes: 8 additions & 0 deletions app/assets/javascripts/backbone/helpers/avatars.js.coffee
@@ -0,0 +1,8 @@
class Kandan.Helpers.Avatars
@urlFor: (a, options) ->
size = options.size || 30
fallback = options.fallback || Kandan.options.avatarFallback || 'mm'
avatarHash = a.gravatar_hash || a.get('user').gravatar_hash || a.get('gravatarHash')
Kandan.options.avatarUrl.replace(/%{hash}/, avatarHash).
replace(/%{size}/, size).
replace(/%{fallback}/, fallback)
12 changes: 6 additions & 6 deletions app/assets/javascripts/backbone/helpers/channels.js.coffee
Expand Up @@ -62,7 +62,7 @@ class Kandan.Helpers.Channels
@getChannelIdByTabIndex: (tabIndex)->
$("#kandan .ui-tabs-panel")
.eq(tabIndex)
.data("channel-id")
.data("channel-id")

@getTabIndexByChannelId: (channelId)->
$("#channels-#{channelId}").prevAll("div").length
Expand Down Expand Up @@ -92,11 +92,11 @@ class Kandan.Helpers.Channels
$createTab = $("#create_channel").parents("li").detach()
$("#kandan").tabs("add", channelArea, "#{channel.get("name")}", totalTabs)
$createTab.appendTo("ul.ui-tabs-nav")
$('#ui-tabs-1').remove()
view = new Kandan.Views.ChannelPane({channel: channel})
view.render $(channelArea)
$(channelArea).data("channel_id", channel.get("id"))


$newChannel = $(channelArea)
view.render $newChannel
$newChannel.addClass('ui-tabs-panel')

@newActivityView: (activityAttributes)->
activity = new Kandan.Models.Activity(activityAttributes)
Expand Down Expand Up @@ -135,7 +135,7 @@ class Kandan.Helpers.Channels

if not local and @getActiveChannelId() == activityAttributes.channel_id and activityAttributes.action == "message" and Kandan.Helpers.Utils.browserTabFocused != true
Kandan.Helpers.Utils.notifyInTitle()
Kandan.Plugins.Notifications.playAudioNotification()
Kandan.Plugins.Notifications.playAudioNotification('channel')
Kandan.Plugins.Notifications.displayNotification(activityAttributes.user.username || activityAttributes.user.email, activityAttributes.content)

@setPaginationData(activityAttributes.channel_id)
Expand Down
5 changes: 4 additions & 1 deletion app/assets/javascripts/backbone/kandan.js.coffee.erb
Expand Up @@ -21,6 +21,8 @@ window.Kandan =
perPage : <%= Kandan::Config.options[:per_page] %>
nowThreshold: 3000
timestampRefreshInterval: 2000
avatarUrl: "<%= Kandan::Config.options[:avatar_url] %>"
avatarFallback: "<%= Kandan::Config.options[:avatar_fallback] %>"


# TODO this is a helper method to register plugins
Expand Down Expand Up @@ -88,7 +90,8 @@ window.Kandan =
add: (event, ui) ->
$('.header .ui-tabs-panel:last').detach().appendTo('#channels')
$('#kandan').tabs('option', 'disabled', [])
$('.header ul a').delegate('cite.close_channel', 'click', window.tabViewGlobal.deleteChannel)
$('.header ul a').undelegate('cite.close_channel','click').
delegate('cite.close_channel', 'click', window.tabViewGlobal.deleteChannel)
})

$("#kandan").tabs 'option', 'tabTemplate', '''
Expand Down
10 changes: 7 additions & 3 deletions app/assets/javascripts/backbone/plugins/music_player.js.coffee
Expand Up @@ -7,7 +7,10 @@ class Kandan.Plugins.MusicPlayer
@stopRegex: /^&#x2F;stop/
@resumeRegex: /^&#x2F;resume/
@localSongData: false

@sounds: {
channel: 'ding.wav'
attention: 'gong.mp3'
}

@playTemplate: _.template('<strong><a class="audio-play">playing</a> <a target="_blank" href="<%- url %>"><%- url %></a></strong>')
@stopTemplate: _.template('<strong><a class="audio-play">stopping</a> the music.')
Expand Down Expand Up @@ -170,8 +173,9 @@ class Kandan.Plugins.MusicPlayer
if @audioChannel(channelId)?
@unmute(channelId)

@playAudioNotice: ->
url = @localFileUrl('ding.wav')
@playAudioNotice: (type)->
sound = @sounds[type] || 'ding.wav'
url = @localFileUrl(sound)
player = $('.audio_private')[0]
player.setAttribute('src', url)
player.play()
Expand Down
14 changes: 8 additions & 6 deletions app/assets/javascripts/backbone/plugins/notifications.js.coffee
Expand Up @@ -76,7 +76,7 @@ class Kandan.Plugins.Notifications
@onPopupNotificationsEnabled: ()->
if @webkitNotificationsEnabled()
@enablePopupNotifications()

return

# If you are wondering why the kandan icon is not displayed on OS X this is the reason:
Expand Down Expand Up @@ -108,7 +108,7 @@ class Kandan.Plugins.Notifications
@sound_notifications_enabled = true
$(".sound-notifications .enable-sound-notifications").remove()
$(".notification.sound-notifications").append(@disable_sound_notifications_template())

return

@disableSoundNotifications: ()->
Expand All @@ -118,7 +118,9 @@ class Kandan.Plugins.Notifications
$(".notification.sound-notifications").append(@enable_sound_notifications_template())
return

@playAudioNotification: ()->
if @sound_notifications_enabled
Kandan.Plugins.MusicPlayer.playAudioNotice()
return
@playAudioNotification: (type)->
if @sound_notifications_enabled and not @isPlaying
@isPlaying = true
setTimeout (=> @isPlaying = false), 1000
Kandan.Plugins.MusicPlayer.playAudioNotice(type)
return
4 changes: 2 additions & 2 deletions app/assets/javascripts/backbone/plugins/user_list.js.coffee
Expand Up @@ -6,7 +6,7 @@ class Kandan.Plugins.UserList

@template: _.template '''
<div class="user clearfix">
<img class="avatar" src="http://gravatar.com/avatar/<%= gravatarHash %>?s=25"/>
<img class="avatar" src="<%= avatarUrl %>"/>
<span class="name"><%= name %></span>
</div>
'''
Expand All @@ -22,7 +22,7 @@ class Kandan.Plugins.UserList

$users.append @template({
name: displayName,
gravatarHash: user.gravatar_hash
avatarUrl: Kandan.Helpers.Avatars.urlFor(user, {size: 25})
})
$el.html($users)

Expand Down
6 changes: 4 additions & 2 deletions app/assets/javascripts/backbone/views/show_activity.js.coffee
Expand Up @@ -6,6 +6,7 @@ class Kandan.Views.ShowActivity extends Backbone.View
render: ()->
activity = @options.activity.toJSON()
activity.content = _.escape(activity.content)
activity.avatarUrl = Kandan.Helpers.Avatars.urlFor(@options.activity, {size: 30})
if activity.action != "message"
@compiledTemplate = JST['user_notification']({activity: activity})
else
Expand All @@ -20,12 +21,13 @@ class Kandan.Views.ShowActivity extends Backbone.View

user_mention_regex = new RegExp("@#{Kandan.Helpers.Users.currentUser().username}\\b")
all_mention_regex = new RegExp("@all")

if activity.user.id == Kandan.Helpers.Users.currentUser().id
$(@el).addClass("current_user")

if user_mention_regex.test(@compiledTemplate) || all_mention_regex.test(@compiledTemplate)
$(@el).addClass("mentioned_user")
Kandan.Plugins.Notifications?.playAudioNotification('attention')

if activity.id == undefined
$(@el).attr("id", "activity-c#{activity.cid}")
Expand Down
2 changes: 1 addition & 1 deletion app/assets/templates/activity_base.jst.eco
@@ -1,7 +1,7 @@
<span class="posted_at">
<%= new Date(@activity.created_at).toRelativeTime(Kandan.options.nowThreshold) %>
</span>
<img class="avatar" src="http://gravatar.com/avatar/<%= @activity.user.gravatar_hash %>?s=30"/>
<img class="avatar" src="<%= @activity.avatarUrl %>"/>

<div class="readable">
<div class="content">
Expand Down
4 changes: 3 additions & 1 deletion app/assets/templates/channel_tabs.jst.eco
Expand Up @@ -5,7 +5,9 @@
<span class="tab_left"></span>
<span class="tab_content">
<cite><%= channel.get('name') %></cite>
<cite class="close_channel" title="close channel">x</cite>
<% unless channel.get('id') == 1: %>
<cite class="close_channel" title="close channel">x</cite>
<% end %>
</span>
</a>
</li>
Expand Down
2 changes: 0 additions & 2 deletions app/assets/templates/current_user.jst.eco

This file was deleted.

2 changes: 1 addition & 1 deletion app/assets/templates/message.jst.eco
@@ -1,7 +1,7 @@
<span class="posted_at">
<%= new Date(@activity.created_at).toRelativeTime(Kandan.options.nowThreshold) %>
</span>
<img class="avatar" src="http://gravatar.com/avatar/<%= @activity.user.gravatar_hash %>?s=30"/>
<img class="avatar" src="<%= @activity.avatarUrl %>"/>

<div class="readable">
<span class="user">
Expand Down
2 changes: 1 addition & 1 deletion app/assets/templates/user_notification.jst.eco
@@ -1,7 +1,7 @@
<span class="posted_at">
<%= new Date(@activity.created_at).toRelativeTime(Kandan.options.nowThreshold) %>
</span>
<img class="avatar" src="http://gravatar.com/avatar/<%= @activity.user.gravatar_hash %>?s=30"/>
<img class="avatar" src="<%= @activity.avatarUrl %>"/>

<div class="readable">
<span class="user">Kandan bot</span>
Expand Down
11 changes: 11 additions & 0 deletions app/helpers/application_helper.rb
@@ -1,2 +1,13 @@
module ApplicationHelper
def current_user_data
current_user_data = {
:id => current_user.id,
:first_name => current_user.first_name,
:last_name => current_user.last_name,
:email => current_user.email,
:username => current_user.username,
:auth_token => current_user.authentication_token,
:gravatar_hash => current_user.gravatar_hash
}
end
end
7 changes: 7 additions & 0 deletions app/helpers/avatar_helper.rb
@@ -0,0 +1,7 @@
module AvatarHelper
def avatar_url_for(user, options = {})
Kandan::Config.options[:avatar_url].gsub(/%{hash}/, user.gravatar_hash).
gsub(/%{size}/, (options[:size] || 30).to_s).
gsub(/%{fallback}/, options[:fallback] || Kandan::Config.options[:avatar_fallback] || 'mm')
end
end
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Expand Up @@ -22,7 +22,7 @@
<a href="#" class="user_menu_link">
<cite class="user_flag"></cite>
<div class="user">
<img src="http://gravatar.com/avatar/<%= current_user.gravatar_hash %>?s=25"/>
<img src="<%= avatar_url_for(current_user, :size => 25) %>"/>
<span><%= current_user.full_name_or_username %></span>
</div>
</a>
Expand Down
12 changes: 1 addition & 11 deletions app/views/main/index.html.erb
Expand Up @@ -10,16 +10,6 @@
<%= javascript_tag do %>
<%- if user_signed_in? %>
<%- current_user_data = {
:id => current_user.id,
:first_name => current_user.first_name,
:last_name => current_user.last_name,
:email => current_user.email,
:username => current_user.username,
:auth_token => current_user.authentication_token,
:gravatar_hash => current_user.gravatar_hash
}
%>
$.data(document, "current-user", <%= current_user_data.to_json.html_safe %>);
<%- end %>
$(document).data("active-users", [])
Expand Down Expand Up @@ -63,4 +53,4 @@

window._cloudfuji_help = <%= cloudfuji_help_vars.to_json.html_safe %>;
<%- end %>
<%- end %>
<%- end %>
2 changes: 2 additions & 0 deletions app/views/main/search.html.erb
@@ -1,4 +1,6 @@
<%= javascript_tag do %>
$.data(document, "current-user", <%= current_user_data.to_json.html_safe %>);

$(document).ready(function(){
Kandan.Plugins.initAll()
activities = <%= @activities.to_json(:include => :user).html_safe %>;
Expand Down
3 changes: 3 additions & 0 deletions config/kandan_settings.yml
Expand Up @@ -13,3 +13,6 @@
:max_rooms: 99

:public_site: true

:avatar_url: http://gravatar.com/avatar/%{hash}?s=%{size}&d=%{fallback}
:avatar_fallback: identicon
1 change: 1 addition & 0 deletions lib/tasks/git.rake
Expand Up @@ -12,6 +12,7 @@ namespace :git do
'fusion94' => 'git://github.com/fusion94/kandan.git',
'SpencerCooley' => 'git://github.com/SpencerCooley/kandan.git',
'jrgifford' => 'git://github.com/jrgifford/kandan.git',
'mjtko' => 'git://github.com/mjtko/kandan.git',
}

def get_remotes
Expand Down

0 comments on commit 1eadbbd

Please sign in to comment.