Player script indentation fix
This commit is contained in:
parent
e94fae6099
commit
52df1f69c4
|
@ -1,234 +1,233 @@
|
||||||
class window.Player
|
class window.Player
|
||||||
|
|
||||||
bar_width: 263
|
bar_width: 263
|
||||||
jp: null
|
jp: null
|
||||||
scrobbled: false
|
scrobbled: false
|
||||||
albums: []
|
albums: []
|
||||||
playlist: []
|
playlist: []
|
||||||
|
|
||||||
initJplayer: ->
|
initJplayer: ->
|
||||||
self = this
|
self = this
|
||||||
|
|
||||||
@jp = $("#jplayer")
|
@jp = $("#jplayer")
|
||||||
@jp.jPlayer
|
@jp.jPlayer
|
||||||
swfPath: "/js"
|
swfPath: "/js"
|
||||||
supplied: "mp3"
|
supplied: "mp3"
|
||||||
cssSelectorAncestor: ""
|
cssSelectorAncestor: ""
|
||||||
cssSelector:
|
cssSelector:
|
||||||
play: ".player .play"
|
play: ".player .play"
|
||||||
pause: ".player .pause"
|
pause: ".player .pause"
|
||||||
stop: ""
|
stop: ""
|
||||||
videoPlay: ""
|
videoPlay: ""
|
||||||
seekBar: ""
|
seekBar: ""
|
||||||
playBar: ""
|
playBar: ""
|
||||||
mute: ""
|
mute: ""
|
||||||
unmute: ""
|
unmute: ""
|
||||||
volumeBar: ""
|
volumeBar: ""
|
||||||
volumeBarValue: ""
|
volumeBarValue: ""
|
||||||
currentTime: ""
|
currentTime: ""
|
||||||
duration: ""
|
duration: ""
|
||||||
|
|
||||||
@jp.bind $.jPlayer.event.timeupdate, (e) ->
|
@jp.bind $.jPlayer.event.timeupdate, (e) ->
|
||||||
data = e.jPlayer.status
|
data = e.jPlayer.status
|
||||||
if not _player.scrobbled and data.currentPercentAbsolute > 50
|
if not _player.scrobbled and data.currentPercentAbsolute > 50
|
||||||
$obj = $('.playlist li.now')
|
$obj = $('.playlist li.now')
|
||||||
self.scrobble $obj.attr('data-artist'), $obj.attr('data-album'), $obj.attr('data-track')
|
self.scrobble $obj.attr('data-artist'), $obj.attr('data-album'), $obj.attr('data-track')
|
||||||
_player.scrobbled = true
|
_player.scrobbled = true
|
||||||
$('.player .progress .loaded').width(data.seekPercent * self.bar_width / 100)
|
$('.player .progress .loaded').width(data.seekPercent * self.bar_width / 100)
|
||||||
$('.player .progress .played').width(data.currentPercentAbsolute * self.bar_width / 100)
|
$('.player .progress .played').width(data.currentPercentAbsolute * self.bar_width / 100)
|
||||||
|
|
||||||
@jp.bind $.jPlayer.event.ended, (e) ->
|
@jp.bind $.jPlayer.event.ended, (e) ->
|
||||||
next = self.nextTrack()
|
next = self.nextTrack()
|
||||||
if not next
|
if not next
|
||||||
$('#jplayer').jPlayer 'clearMedia'
|
$('#jplayer').jPlayer 'clearMedia'
|
||||||
$('.player .now-playing').html 'Nothing left to <strike>lose</strike> play'
|
$('.player .now-playing').html 'Nothing left to <strike>lose</strike> play'
|
||||||
$('.player .loaded, .player .played').width 0
|
$('.player .loaded, .player .played').width 0
|
||||||
$('.playlist li').removeClass 'now'
|
$('.playlist li').removeClass 'now'
|
||||||
else
|
else
|
||||||
self.setTrack next
|
self.setTrack next
|
||||||
false
|
false
|
||||||
|
|
||||||
addTracks: (tracks, autoplay) ->
|
addTracks: (tracks, autoplay) ->
|
||||||
if not autoplay?
|
if not autoplay?
|
||||||
autoplay = false
|
autoplay = false
|
||||||
initial_count = $('.playlist li').length
|
initial_count = $('.playlist li').length
|
||||||
for item in tracks
|
for item in tracks
|
||||||
$('.playlist').append '
|
$('.playlist').append '
|
||||||
<li id="i' +Math.round(Math.random() * 999999)+ '" data-id="'+item.id+'">
|
<li id="i' +Math.round(Math.random() * 999999)+ '" data-id="'+item.id+'">
|
||||||
<div class="song-duration">' +item.duration+ '</div>
|
<div class="song-duration">' +item.duration+ '</div>
|
||||||
<div class="remove">remove</div>
|
<div class="remove">remove</div>
|
||||||
<div class="drag"></div>
|
<div class="drag"></div>
|
||||||
<div class="artist-name">' +item.artist+ '</div>
|
<div class="artist-name">' +item.artist+ '</div>
|
||||||
<div class="song-title">' +item.name+ '</div>
|
<div class="song-title">' +item.name+ '</div>
|
||||||
</li>'
|
</li>'
|
||||||
_player.playlist.push item
|
_player.playlist.push item
|
||||||
$('.playlist').sortable axis: 'y', handle: '.drag'
|
$('.playlist').sortable axis: 'y', handle: '.drag'
|
||||||
if initial_count == 0 and not _player.hasTrack()
|
if initial_count == 0 and not _player.hasTrack()
|
||||||
_player.setTrack($('.playlist li').first().attr('id').split('i')[1])
|
_player.setTrack($('.playlist li').first().attr('id').split('i')[1])
|
||||||
false
|
false
|
||||||
|
|
||||||
getDataFromLi: (obj) ->
|
getDataFromLi: (obj) ->
|
||||||
id = $(obj).attr 'data-id'
|
id = $(obj).attr 'data-id'
|
||||||
track_name = $(obj).find('.trackname').html()
|
track_name = $(obj).find('.trackname').html()
|
||||||
length = $(obj).find('.length').html()
|
length = $(obj).find('.length').html()
|
||||||
id: id, name: track_name, length: length
|
id: id, name: track_name, length: length
|
||||||
|
|
||||||
setTrack: (id) ->
|
setTrack: (id) ->
|
||||||
$obj = $('#i' +id)
|
$obj = $('#i' +id)
|
||||||
track = _player.getTrackInfo $obj.attr('data-id')
|
track = _player.getTrackInfo $obj.attr('data-id')
|
||||||
query = track.artist+ ' — ' +track.name
|
query = track.artist+ ' — ' +track.name
|
||||||
|
|
||||||
$('.player .loaded, .player .played').width 0
|
$('.player .loaded, .player .played').width 0
|
||||||
$('.player .now-playing').html query
|
$('.player .now-playing').html query
|
||||||
$('.playlist li').removeClass 'now'
|
$('.playlist li').removeClass 'now'
|
||||||
$obj.addClass 'now'
|
$obj.addClass 'now'
|
||||||
console.log(track)
|
console.log(track)
|
||||||
_vkontakte.loadTracksData track.artist, track.name, track.duration, (url) ->
|
_vkontakte.loadTracksData track.artist, track.name, track.duration, (url) ->
|
||||||
_player.playSource url
|
_player.playSource url
|
||||||
this.updateNowListening track.artist, track.album, track.name
|
this.updateNowListening track.artist, track.album, track.name
|
||||||
false
|
false
|
||||||
|
|
||||||
getTrackInfo: (id) ->
|
getTrackInfo: (id) ->
|
||||||
for track in _player.playlist
|
for track in _player.playlist
|
||||||
if track.id == parseInt(id, 10)
|
if track.id == parseInt(id, 10)
|
||||||
return track
|
return track
|
||||||
false
|
false
|
||||||
|
|
||||||
hasTrack: ->
|
hasTrack: ->
|
||||||
if $('#jplayer audio').length > 0
|
if $('#jplayer audio').length > 0
|
||||||
return $('#jplayer audio').attr('src')? and $('#jplayer audio').attr('src') != ''
|
return $('#jplayer audio').attr('src')? and $('#jplayer audio').attr('src') != ''
|
||||||
else if $('#jplayer object').length > 0
|
else if $('#jplayer object').length > 0
|
||||||
$('#jplayer').jPlayer 'play'
|
$('#jplayer').jPlayer 'play'
|
||||||
true
|
true
|
||||||
false
|
false
|
||||||
|
|
||||||
playSource: (url) ->
|
playSource: (url) ->
|
||||||
@scrobbled = false
|
@scrobbled = false
|
||||||
$('#jplayer').jPlayer 'setMedia', mp3: url
|
$('#jplayer').jPlayer 'setMedia', mp3: url
|
||||||
$('#jplayer').jPlayer 'play'
|
$('#jplayer').jPlayer 'play'
|
||||||
false
|
false
|
||||||
|
|
||||||
nextTrack: (manual) ->
|
nextTrack: (manual) ->
|
||||||
manual = manual?
|
manual = manual?
|
||||||
cnt = $('.playlist li').length
|
cnt = $('.playlist li').length
|
||||||
if not this.onShuffle() # Shuffle off
|
if not this.onShuffle() # Shuffle off
|
||||||
if $('.playlist .now').next().length == 0 # Last track and repeat is on
|
if $('.playlist .now').next().length == 0 # Last track and repeat is on
|
||||||
if _player.onRepeat() or manual # Repeat or manual click
|
if _player.onRepeat() or manual # Repeat or manual click
|
||||||
return $('.playlist li').first().attr('id').split('i')[1]
|
return $('.playlist li').first().attr('id').split('i')[1]
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
else
|
else
|
||||||
return $('.playlist .now').next().attr('id').split('i')[1]
|
return $('.playlist .now').next().attr('id').split('i')[1]
|
||||||
else if cnt == 1 # Single track in the playlist
|
else if cnt == 1 # Single track in the playlist
|
||||||
return $('.playlist li').first().attr('id').split('i')[1]
|
return $('.playlist li').first().attr('id').split('i')[1]
|
||||||
else # Shuffle on
|
else # Shuffle on
|
||||||
while true
|
while true
|
||||||
rnd = Math.floor(Math.random() * (cnt + .999))
|
rnd = Math.floor(Math.random() * (cnt + .999))
|
||||||
$li = $('.playlist li').eq rnd
|
$li = $('.playlist li').eq rnd
|
||||||
if $li.length > 0 and not $li.hasClass 'now'
|
if $li.length > 0 and not $li.hasClass 'now'
|
||||||
return $li.attr('id').split('i')[1]
|
return $li.attr('id').split('i')[1]
|
||||||
false
|
false
|
||||||
|
|
||||||
prevTrack: ->
|
prevTrack: ->
|
||||||
cnt = $('.playlist li').length
|
cnt = $('.playlist li').length
|
||||||
if not _player.onShuffle() # Shuffle off
|
if not _player.onShuffle() # Shuffle off
|
||||||
if $('.playlist .now').prev().length == 0 # First track in the playlist
|
if $('.playlist .now').prev().length == 0 # First track in the playlist
|
||||||
return $('.playlist li').last().attr('id').split('i')[1]
|
return $('.playlist li').last().attr('id').split('i')[1]
|
||||||
else
|
else
|
||||||
return $('.playlist .now').prev().attr('id').split('i')[1]
|
return $('.playlist .now').prev().attr('id').split('i')[1]
|
||||||
else if cnt == 1 # Single track in the playlist
|
else if cnt == 1 # Single track in the playlist
|
||||||
return $('.playlist li').first().attr('id').split('i')[1]
|
return $('.playlist li').first().attr('id').split('i')[1]
|
||||||
else # Shuffle on
|
else # Shuffle on
|
||||||
while true
|
while true
|
||||||
rnd = Math.floor(Math.random() * (cnt + .999))
|
rnd = Math.floor(Math.random() * (cnt + .999))
|
||||||
$li = $('.playlist li').eq rnd
|
$li = $('.playlist li').eq rnd
|
||||||
if $li.length > 0 and not $li.hasClass 'now'
|
if $li.length > 0 and not $li.hasClass 'now'
|
||||||
return $li.attr('id').split('i')[1]
|
return $li.attr('id').split('i')[1]
|
||||||
false
|
false
|
||||||
|
|
||||||
onShuffle: ->
|
onShuffle: ->
|
||||||
#return $('#shuffle').hasClass 'active'
|
#return $('#shuffle').hasClass 'active'
|
||||||
|
|
||||||
onRepeat: ->
|
onRepeat: ->
|
||||||
#return $('#repeat').hasClass 'active'
|
#return $('#repeat').hasClass 'active'
|
||||||
|
|
||||||
updateNowListening: (artist, album, track) ->
|
updateNowListening: (artist, album, track) ->
|
||||||
if _session.getUser().lastfm_username
|
if _session.getUser().lastfm_username
|
||||||
_session.query '/lastfm/listening?r=' +Math.random(), artist: artist, album: album, track: track
|
_session.query '/lastfm/listening?r=' +Math.random(), artist: artist, album: album, track: track
|
||||||
false
|
false
|
||||||
|
|
||||||
scrobble: (artist, album, track) ->
|
scrobble: (artist, album, track) ->
|
||||||
if _session.getUser().lastfm_username
|
if _session.getUser().lastfm_username
|
||||||
_session.query '/lastfm/scrobble?r=' +Math.random(), artist: artist, album: album, track: track
|
_session.query '/lastfm/scrobble?r=' +Math.random(), artist: artist, album: album, track: track
|
||||||
false
|
false
|
||||||
|
|
||||||
|
|
||||||
# Player Controls
|
# Player Controls
|
||||||
|
|
||||||
$('.player .prev').live 'click', ->
|
$('.player .prev').live 'click', ->
|
||||||
_player.setTrack _player.prevTrack()
|
_player.setTrack _player.prevTrack()
|
||||||
false
|
false
|
||||||
|
|
||||||
$('.player .next').live 'click', ->
|
$('.player .next').live 'click', ->
|
||||||
_player.setTrack _player.nextTrack(true)
|
_player.setTrack _player.nextTrack(true)
|
||||||
false
|
false
|
||||||
|
|
||||||
$('.player .play').live 'click', ->
|
$('.player .play').live 'click', ->
|
||||||
if $('.playlist li').length > 0 and not _player.hasTrack()
|
if $('.playlist li').length > 0 and not _player.hasTrack()
|
||||||
_player.setTrack $('.playlist li').first().attr('id').split('i')[1]
|
_player.setTrack $('.playlist li').first().attr('id').split('i')[1]
|
||||||
false
|
false
|
||||||
|
|
||||||
$('.player .progress').live 'click', (e) ->
|
$('.player .progress').live 'click', (e) ->
|
||||||
$('#jplayer').jPlayer 'playHead', Math.round((e.offsetX / _player.bar_width) * 100)
|
$('#jplayer').jPlayer 'playHead', Math.round((e.offsetX / _player.bar_width) * 100)
|
||||||
false
|
false
|
||||||
|
|
||||||
# Player Additional Controls
|
# Player Additional Controls
|
||||||
|
|
||||||
$('#repeat, #shuffle').live 'click', ->
|
$('#repeat, #shuffle').live 'click', ->
|
||||||
$(this).toggleClass 'active'
|
$(this).toggleClass 'active'
|
||||||
false
|
false
|
||||||
|
|
||||||
$('#empty-playlist').live 'click', ->
|
$('#empty-playlist').live 'click', ->
|
||||||
if confirm('Are you sure?')
|
if confirm('Are you sure?')
|
||||||
$('.playlist li').remove()
|
$('.playlist li').remove()
|
||||||
$('#jplayer').jPlayer 'clearMedia'
|
$('#jplayer').jPlayer 'clearMedia'
|
||||||
$('.player .now-playing').text 'Add some music to playlist'
|
$('.player .now-playing').text 'Add some music to playlist'
|
||||||
$('.player .loaded, .player .played').width 0
|
$('.player .loaded, .player .played').width 0
|
||||||
false
|
false
|
||||||
|
|
||||||
# Playlist Actions
|
# Playlist Actions
|
||||||
|
|
||||||
$('.playlist li .artist-name, .playlist li .song-title, .playlist li .song-duration, .playlist li .remove').live 'mousemove mouseover mouseout', (e) ->
|
$('.playlist li .artist-name, .playlist li .song-title, .playlist li .song-duration, .playlist li .remove').live 'mousemove mouseover mouseout', (e) ->
|
||||||
if e.type in ['mouseover', 'mousemove'] and ($(window).width() - e.clientX) < 60 +
|
if e.type in ['mouseover', 'mousemove'] and $('.playlist').offset().left + $('.playlist').outerWidth() - e.clientX < 60
|
||||||
$(window).width() - $('.playlist').offset().left - $('.playlist').outerWidth()
|
$(this).parent().find('.song-duration').hide()
|
||||||
$(this).parent().find('.song-duration').hide()
|
$(this).parent().find('.remove').show()
|
||||||
$(this).parent().find('.remove').show()
|
else
|
||||||
else
|
$(this).parent().find('.remove').hide()
|
||||||
$(this).parent().find('.remove').hide()
|
$(this).parent().find('.song-duration').show()
|
||||||
$(this).parent().find('.song-duration').show()
|
false
|
||||||
false
|
|
||||||
|
|
||||||
$('.playlist li .remove').live 'click', (e) ->
|
$('.playlist li .remove').live 'click', (e) ->
|
||||||
$li = $(this).parent()
|
$li = $(this).parent()
|
||||||
if $li.hasClass 'now'
|
if $li.hasClass 'now'
|
||||||
$('#jplayer').jPlayer 'clearMedia'
|
$('#jplayer').jPlayer 'clearMedia'
|
||||||
$('.player .now-playing').text '...'
|
$('.player .now-playing').text '...'
|
||||||
$('.player .loaded, .player .played').width 0
|
$('.player .loaded, .player .played').width 0
|
||||||
$li.remove()
|
$li.remove()
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
false
|
false
|
||||||
|
|
||||||
$('.playlist li').live 'click', ->
|
$('.playlist li').live 'click', ->
|
||||||
_player.setTrack $(this).attr('id').split('i')[1]
|
_player.setTrack $(this).attr('id').split('i')[1]
|
||||||
false
|
false
|
||||||
|
|
||||||
# Adding To Playlist actions
|
# Adding To Playlist actions
|
||||||
|
|
||||||
$('.add-album').live 'click', ->
|
$('.add-album').live 'click', ->
|
||||||
artist = $('.artist-info h2').text()
|
artist = $('.artist-info h2').text()
|
||||||
album = _player.albums[$(this).attr('data-album-id')]
|
album = _player.albums[$(this).attr('data-album-id')]
|
||||||
for item in album.tracks.album
|
for item in album.tracks.album
|
||||||
item['artist'] = artist
|
item['artist'] = artist
|
||||||
item['album'] = album.name
|
item['album'] = album.name
|
||||||
_player.addTracks album.tracks.album
|
_player.addTracks album.tracks.album
|
||||||
false
|
false
|
||||||
|
|
|
@ -21,14 +21,14 @@
|
||||||
width: 94%;
|
width: 94%;
|
||||||
margin: 0 0 18px 3%;
|
margin: 0 0 18px 3%;
|
||||||
height: 5px;
|
height: 5px;
|
||||||
background-color: #e0e0e0;
|
background-color: #f0f0f0;
|
||||||
.loaded {
|
.loaded {
|
||||||
width: 66%;
|
width: 0;
|
||||||
height: 5px;
|
height: 5px;
|
||||||
background-color: #d0e0e0;
|
background-color: #d0e0e0;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
.played {
|
.played {
|
||||||
width: 66%;
|
width: 0;
|
||||||
height: 5px;
|
height: 5px;
|
||||||
background-color: #0090AA;
|
background-color: #0090AA;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue