Skip to content

Commit

Permalink
Merge d4a857f into 82cfd2c
Browse files Browse the repository at this point in the history
  • Loading branch information
mjtko committed Mar 14, 2013
2 parents 82cfd2c + d4a857f commit 6eb0312
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class Kandan.Broadcasters.FayeBroadcaster

constructor: ()->
@fayeClient = new Faye.Client("<%= ENV['KANDAN_FAYE_URL'] %>/remote/faye")
endpoint = $('body').data('kandan-config').broadcaster.config.endpoint
@fayeClient = new Faye.Client(endpoint)

@fayeClient.disable('websocket')
authExtension = {
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/backbone/helpers/avatars.js.coffee
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
class Kandan.Helpers.Avatars
@urlFor: (a, options) ->
size = options.size || 30
fallback = options.fallback || Kandan.options.avatarFallback || 'mm'
fallback = options.fallback || Kandan.options().avatar_fallback || 'mm'
avatarHash = a.gravatar_hash || a.get('user').gravatar_hash || a.get('gravatarHash')
Kandan.options.avatarUrl.replace(/%{hash}/, avatarHash).
Kandan.options().avatar_url.replace(/%{hash}/, avatarHash).
replace(/%{size}/, size).
replace(/%{fallback}/, fallback)
3 changes: 1 addition & 2 deletions app/assets/javascripts/backbone/helpers/channels.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ class Kandan.Helpers.Channels

@options:
autoScrollThreshold: 0.90
maxActivities: Kandan.options.perPage

@pastAutoScrollThreshold: (channelId)->
currentPosition = @currentScrollPosition channelId
Expand Down Expand Up @@ -45,7 +44,7 @@ class Kandan.Helpers.Channels

@flushActivities: (channelId)->
$channelActivities = $("#channel-activities-#{channelId}")
if $channelActivities.children().length == @options.maxActivities + 1
if $channelActivities.children().length == Kandan.options().per_page + 1
$channelActivities.children().first().remove()
oldest = $channelActivities.children().first().data("activity-id")
$channelActivities.prev().data("oldest", oldest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,8 @@ window.Kandan =
Data: {}
Plugins: {}

options:
broadcaster: "<%= Kandan::Config.options[:broadcaster][:name] %>"
perPage : <%= Kandan::Config.options[:per_page] %>
nowThreshold: 3000
timestampRefreshInterval: 2000
avatarUrl: "<%= Kandan::Config.options[:avatar_url] %>"
avatarFallback: "<%= Kandan::Config.options[:avatar_fallback] %>"

options: ->
@_options ?= $('body').data('kandan-config')

# TODO this is a helper method to register plugins
# in the order required until we come up with plugin management
Expand Down Expand Up @@ -69,7 +63,7 @@ window.Kandan =


initBroadcasterAndSubscribe: ()->
Kandan.broadcaster = eval "new Kandan.Broadcasters.#{@options.broadcaster}Broadcaster()"
Kandan.broadcaster = eval "new Kandan.Broadcasters.#{@options().broadcaster.name}Broadcaster()"
Kandan.broadcaster.subscribe "/channels/*"
@registerAppEvents()

Expand All @@ -80,10 +74,10 @@ window.Kandan =

$(document).data('active-channel-id',
Kandan.Helpers.Channels.getChannelIdByTabIndex(ui.index))
#the need for the delay feels hacky to me.

#the need for the delay feels hacky to me.
#It is there because the chat area has to render before scrollHeight can be determined.
theId = Kandan.Helpers.Channels.getActiveChannelId()
theId = Kandan.Helpers.Channels.getActiveChannelId()
delay = (ms, func) -> setTimeout func, ms
delay 1, -> Kandan.Helpers.Channels.scrollToLatestMessage(theId)
Kandan.Data.Channels.runCallbacks('change')
Expand Down Expand Up @@ -134,8 +128,8 @@ window.Kandan =
registerUtilityEvents: ()->
window.setInterval(=>
for el in $(".posted_at")
$(el).text (new Date($(el).data("timestamp"))).toRelativeTime(@options.nowThreshold)
, @options.timestampRefreshInterval)
$(el).text (new Date($(el).data("timestamp"))).toRelativeTime(@options().now_threshold)
, @options().timestamp_refresh_interval)

init: ->
channels = new Kandan.Collections.Channels()
Expand Down
2 changes: 1 addition & 1 deletion app/assets/templates/activity_base.jst.eco
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<span class="posted_at">
<%= new Date(@activity.created_at).toRelativeTime(Kandan.options.nowThreshold) %>
<%= new Date(@activity.created_at).toRelativeTime(Kandan.options().now_threshold) %>
</span>
<img class="avatar" src="<%= @activity.avatarUrl %>"/>

Expand Down
2 changes: 1 addition & 1 deletion app/assets/templates/message.jst.eco
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<span class="posted_at">
<%= new Date(@activity.created_at).toRelativeTime(Kandan.options.nowThreshold) %>
<%= new Date(@activity.created_at).toRelativeTime(Kandan.options().now_threshold) %>
</span>
<img class="avatar" src="<%= @activity.avatarUrl %>"/>

Expand Down
2 changes: 1 addition & 1 deletion app/assets/templates/user_notification.jst.eco
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<span class="posted_at">
<%= new Date(@activity.created_at).toRelativeTime(Kandan.options.nowThreshold) %>
<%= new Date(@activity.created_at).toRelativeTime(Kandan.options().now_threshold) %>
</span>
<img class="avatar" src="<%= @activity.avatarUrl %>"/>

Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<% end %>
<%- end %>
</head>
<body>
<body data-kandan-config="<%= Kandan::Config.to_json %>">
<div id="kandan">
<div class="header">
<a href="/">
Expand Down
3 changes: 3 additions & 0 deletions config/kandan_settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@

:avatar_url: http://gravatar.com/avatar/%{hash}?s=%{size}&d=%{fallback}
:avatar_fallback: identicon

:now_threshold: 3000
:timestamp_refresh_interval: 2000
9 changes: 8 additions & 1 deletion lib/kandan_config.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Kandan
class Config

class << self
def options
@config ||= YAML.load_file "#{Rails.root}/config/kandan_settings.yml"
Expand All @@ -9,6 +8,14 @@ def options
def broadcaster
Broadcasters.const_get(Kandan::Config.options[:broadcaster][:name])
end

def to_json
@json_representation ||= options.dup.tap do |h|
h[:broadcaster][:config] = {
endpoint: "#{ENV['KANDAN_FAYE_URL']}/remote/faye"
}
end.to_json
end
end

end
Expand Down

0 comments on commit 6eb0312

Please sign in to comment.