Skip to content

Commit

Permalink
Merge pull request #351 from alfajango/fixed-play-sound
Browse files Browse the repository at this point in the history
Fixed play sound
  • Loading branch information
scouttyg committed May 8, 2014
2 parents 9ad9635 + fa91652 commit a32900d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions app/assets/javascripts/backbone/kandan.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ window.Kandan =
Kandan.Helpers.Channels.scrollToLatestMessage()
Kandan.Plugins.Mentions.initUsersMentions(Kandan.Helpers.ActiveUsers.all())
Kandan.Plugins.Emojis.attachToChatbox()
Kandan.Plugins.MusicPlayer.attachClicks()

# Call the asynchronous initializers, passing the synchronous
# initializer in as the callback to execute after all asynchrnous
Expand Down
28 changes: 18 additions & 10 deletions app/assets/javascripts/backbone/plugins/music_player.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,19 @@ class Kandan.Plugins.MusicPlayer
attention: 'threetone-alert.wav'
}

@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.')
@resumeTemplate: _.template('<strong><a class="audio-play">resuming</a> the music.')
@playTemplate: _.template('<a class="audio-play" target="_blank" href="<%- soundUrl %>"><i>:sound: play <%- url %></i></a>')
@stopTemplate: _.template('<i>:mute: stop the music.</i>')
@resumeTemplate: _.template('<i>:sound: resume the music.</i>')
@songTemplate: _.template('<li><%= song.split("/").pop() %></li>')

@attachClicks: =>
_this = this
$(document).delegate('.audio-play', 'click', (e) ->
e.preventDefault()
soundUrl = $(this).attr('href')
channelId = _this.currentChannel()
_this.playUrl(channelId, soundUrl)
)

@setError: (errorMessage)->
console.log "music player error", errorMessage
Expand Down Expand Up @@ -65,18 +73,18 @@ class Kandan.Plugins.MusicPlayer
@registerPlayModifier: ()->
Kandan.Modifiers.register @playRegex, (message, activity) =>
url = $.trim(message.substr(message.indexOf(" ") + 1));
if true and Kandan.Data.Channels.activeChannelId()?
rawInput = Kandan.Helpers.Utils.unescape(url)
soundUrl = null
soundUrl = @localSounds(rawInput)
soundUrl ?= rawInput
rawInput = Kandan.Helpers.Utils.unescape(url)
soundUrl = null
soundUrl = @localSounds(rawInput)
soundUrl ?= rawInput

if true and Kandan.Data.Channels.activeChannelId()?
@playUrl(activity.channel_id, soundUrl)
else
console.log "Not playing stale song"

message.content = @playTemplate({url: url})
return Kandan.Helpers.Activities.buildFromBaseTemplate message
message = @playTemplate({url: url, soundUrl: soundUrl})
return message #Kandan.Helpers.Activities.buildFromBaseTemplate message

@registerStopModifier: ()->
Kandan.Modifiers.register @stopRegex, (message, activity) =>
Expand Down

0 comments on commit a32900d

Please sign in to comment.