Holy fuck. It works!
This commit is contained in:
parent
b9ac20f575
commit
18b2b910ae
|
@ -3,42 +3,46 @@ class Ajax
|
|||
referer: false
|
||||
|
||||
loadArtistData: (name) ->
|
||||
search.showSpinner()
|
||||
_search.showSpinner()
|
||||
name = name.split(' ').join('+')
|
||||
$.get '/artist/' +name+ '/', (data) ->
|
||||
if data.status?
|
||||
if data.status is 'loading'
|
||||
search.showArtistPics data.pics
|
||||
_search.showArtistPics data.pics
|
||||
setTimeout () ->
|
||||
this.loadArtistData name
|
||||
_ajax.loadArtistData name
|
||||
, 3000
|
||||
else if data.status is 'corrected'
|
||||
ajax.loadArtistData data.page
|
||||
_ajax.loadArtistData data.page
|
||||
else if data.status is 'suggestions'
|
||||
search.hideSpinner()
|
||||
search.showSuggestions data.values
|
||||
_search.hideSpinner()
|
||||
_search.showSuggestions data.values
|
||||
else if data.status == 'loading_failed'
|
||||
search.hideSpinner()
|
||||
search.showError()
|
||||
_search.hideSpinner()
|
||||
_search.showError()
|
||||
else
|
||||
this.setArchor '/artist/' +name+ '/'
|
||||
pages.renderArtist data
|
||||
beathaven.redrawScrollbar()
|
||||
_ajax.setArchor '/artist/' +name+ '/'
|
||||
_pages.renderArtist data
|
||||
_beathaven.redrawScrollbar()
|
||||
false
|
||||
|
||||
loadSearchPage: ->
|
||||
$.get '/templates/search.html', (data) ->
|
||||
this.setArchor '/search/'
|
||||
pages.renderSearch data
|
||||
_ajax.setArchor '/search/'
|
||||
_pages.renderSearch data
|
||||
false
|
||||
|
||||
loadSettingsPage: ->
|
||||
$.get '/templates/settings.html', (data) ->
|
||||
this.setArchor '/settings/'
|
||||
pages.renderSettings data
|
||||
_ajax.setArchor '/settings/'
|
||||
_pages.renderSettings data
|
||||
false
|
||||
|
||||
load404Page: ->
|
||||
$.get '/404.html', (data) ->
|
||||
$('.data-container .inner').html data
|
||||
beathaven.redrawScrollbar()
|
||||
_beathaven.redrawScrollbar()
|
||||
false
|
||||
|
||||
setArchor: (anchor) ->
|
||||
@referer = this.getAnchor()
|
||||
|
@ -49,22 +53,26 @@ class Ajax
|
|||
|
||||
setTitle: (title) ->
|
||||
document.title = title+ ' @ BeatHaven'
|
||||
|
||||
go: (url) ->
|
||||
this.setArchor url
|
||||
false
|
||||
|
||||
detectPage: () ->
|
||||
if m = this.getAnchor().match /\/artist\/(.+)\//
|
||||
this.loadArtistData m[1]
|
||||
else if this.getAnchor() == '' or Ajax.getAnchor().match /\/search\//
|
||||
this.loadSearchPage();
|
||||
else if this.getAnchor().match /\/settings\//
|
||||
this.loadSearchPage()
|
||||
if m = _ajax.getAnchor().match /\/artist\/(.+)\//
|
||||
_ajax.loadArtistData m[1]
|
||||
else if _ajax.getAnchor() == '' or _ajax.getAnchor().match /\/search\//
|
||||
_ajax.loadSearchPage();
|
||||
else if _ajax.getAnchor().match /\/settings\//
|
||||
_ajax.loadSettingsPage()
|
||||
else
|
||||
this.load404Page()
|
||||
|
||||
|
||||
$ ->
|
||||
window.ajax = new Ajax()
|
||||
$('a.data.artist').live 'click', ->
|
||||
ajax.loadArtistData $(this).html()
|
||||
_ajax.loadSearchPage()
|
||||
false
|
||||
$(window).bind 'hashchange', ->
|
||||
ajax.detectPage()
|
||||
|
||||
|
||||
$('a.data.artist').live 'click', ->
|
||||
_ajax.loadArtistData $(this).html()
|
||||
false
|
||||
$(window).bind 'hashchange', ->
|
||||
_ajax.detectPage()
|
||||
false
|
||||
|
|
|
@ -1,18 +1,25 @@
|
|||
# Registering global objects
|
||||
_beathaven = null
|
||||
_session = 1
|
||||
_vkontakte = null
|
||||
_ajax = null
|
||||
_player = null
|
||||
_search = null
|
||||
_pages = null
|
||||
_settings = null
|
||||
|
||||
$ ->
|
||||
l = document.location
|
||||
if l.host not in ['beathaven.org', 'localhost']
|
||||
l.href = 'http://beathaven.org/'+ l.hash
|
||||
|
||||
window.beathaven = new BeatHaven()
|
||||
window.vkontakte = new Vkontakte(if l.host == 'beathaven.org' then 2335068 else 2383163)
|
||||
|
||||
beathaven.init()
|
||||
vkontakte.init()
|
||||
_beathaven = new BeatHaven()
|
||||
_beathaven.init()
|
||||
|
||||
$(window).resize ->
|
||||
beathaven.adjustSizes()
|
||||
_beathaven.adjustSizes()
|
||||
window.setTimeout ->
|
||||
beathaven.checkRedrawScrollbar()
|
||||
_beathaven.checkRedrawScrollbar()
|
||||
, 500
|
||||
|
||||
class BeatHaven
|
||||
|
@ -20,9 +27,24 @@ class BeatHaven
|
|||
last_height: false
|
||||
|
||||
init: ->
|
||||
this.drawInterface()
|
||||
this.adjustSizes()
|
||||
ajax.detectPage()
|
||||
this.checkRedrawScrollbar()
|
||||
|
||||
_vkontakte = new Vkontakte(if document.location.host == 'beathaven.org' then 2335068 else 2383163)
|
||||
_vkontakte.init()
|
||||
|
||||
_ajax = new Ajax()
|
||||
|
||||
_player = new Player()
|
||||
_player.initJplayer()
|
||||
|
||||
_search = new Search()
|
||||
|
||||
_pages = new Pages()
|
||||
|
||||
_settings = new Settings()
|
||||
|
||||
_ajax.detectPage()
|
||||
|
||||
adjustSizes: ->
|
||||
$('.data-container').height $(window).height() - $('.header-container').height()
|
||||
|
@ -45,7 +67,7 @@ class BeatHaven
|
|||
document.getElementById(focused_id).focus()
|
||||
focused_id = false
|
||||
window.setTimeout ->
|
||||
beathaven.checkRedrawScrollbar()
|
||||
_beathaven.checkRedrawScrollbar()
|
||||
, 500
|
||||
|
||||
redrawScrollbar: ->
|
||||
|
|
|
@ -47,8 +47,9 @@ class Pages
|
|||
$('.data-container').css backgroundImage: 'none'
|
||||
$('.data-container .inner').html('').append(artist_info).append(albums_info)
|
||||
|
||||
yaCounter7596904.hit ajax.getAnchor(), data.artist.name, ajax.referer
|
||||
ajax.setTitle data.artist.name
|
||||
yaCounter7596904.hit _ajax.getAnchor(), data.artist.name, _ajax.referer
|
||||
_ajax.setTitle data.artist.name
|
||||
false
|
||||
|
||||
renderSearch: (data) ->
|
||||
$('.data-container').css background: 'url(/images/concrete_wall_2.png) 0 -30px repeat'
|
||||
|
@ -69,20 +70,18 @@ class Pages
|
|||
zIndex: 9999 # z-index списка
|
||||
deferRequestBy: 500 # Задержка запроса (мсек)
|
||||
onSelect: ->
|
||||
ajax.loadArtistData()
|
||||
_ajax.loadArtistData $('#search_field').val()
|
||||
$('#search_field').focus()
|
||||
, 501
|
||||
|
||||
yaCounter7596904.hit ajax.getAnchor(), 'Artist Search', ajax.referer
|
||||
ajax.setTitle 'Artist Search'
|
||||
yaCounter7596904.hit _ajax.getAnchor(), 'Artist Search', _ajax.referer
|
||||
_ajax.setTitle 'Artist Search'
|
||||
false
|
||||
|
||||
renderSettings: (data) ->
|
||||
$('.data-container').css background: 'none'
|
||||
$('.data-container .inner').html data
|
||||
yaCounter7596904.hit ajax.getAnchor(), 'Settings', ajax.referer
|
||||
ajax.setTitle 'Settings'
|
||||
yaCounter7596904.hit _ajax.getAnchor(), 'Settings', _ajax.referer
|
||||
_ajax.setTitle 'Settings'
|
||||
$('.settings-container .tabs .tab').first().trigger 'click'
|
||||
|
||||
$ ->
|
||||
window.pages = new Pages()
|
||||
false
|
||||
false
|
||||
|
|
|
@ -13,8 +13,8 @@ class Player
|
|||
supplied: "mp3"
|
||||
cssSelectorAncestor: ""
|
||||
cssSelector:
|
||||
play: "#player .play"
|
||||
pause: "#player .pause"
|
||||
play: ".player .play"
|
||||
pause: ".player .pause"
|
||||
stop: ""
|
||||
videoPlay: ""
|
||||
seekBar: ""
|
||||
|
@ -28,19 +28,19 @@ class Player
|
|||
|
||||
@jp.bind $.jPlayer.event.timeupdate, (e) ->
|
||||
data = e.jPlayer.status
|
||||
if not Player.scrobbled and data.currentPercentAbsolute > 50
|
||||
if not _player.scrobbled and data.currentPercentAbsolute > 50
|
||||
$obj = $('.playlist-tracks li.now')
|
||||
self.scrobble $obj.attr('data-artist'), $obj.attr('data-album'), $obj.attr('data-track')
|
||||
Player.scrobbled = true
|
||||
$('#player .progress .loaded').width(data.seekPercent * self.bar_width / 100)
|
||||
$('#player .progress .played').width(data.currentPercentAbsolute * self.bar_width / 100)
|
||||
_player.scrobbled = true
|
||||
$('.player .progress .loaded').width(data.seekPercent * self.bar_width / 100)
|
||||
$('.player .progress .played').width(data.currentPercentAbsolute * self.bar_width / 100)
|
||||
|
||||
@jp.bind $.jPlayer.event.ended, (e) ->
|
||||
next = self.nextTrack()
|
||||
if not next
|
||||
$('#jplayer').jPlayer 'clearMedia'
|
||||
$('#player .now-playing').html 'Nothing left to <strike>lose</strike> play'
|
||||
$('#player .loaded, #player .played').width 0
|
||||
$('.player .now-playing').html 'Nothing left to <strike>lose</strike> play'
|
||||
$('.player .loaded, .player .played').width 0
|
||||
$('.playlist-tracks li').removeClass 'now'
|
||||
else
|
||||
self.setTrack next
|
||||
|
@ -54,31 +54,31 @@ class Player
|
|||
<li id="i' +Math.round(Math.random() * 999999)+ '" data-artist="' +artist.trim()+ '" data-album="' +album.trim()+ '" data-track="' +track.trim()+ '" data-length="' +length+ '">
|
||||
<div class="item">
|
||||
<div class="fade"></div>
|
||||
<span class="title" title="' +artist.htmlsafe()+ ' &mdash ' +track.htmlsafe()+ '">' +artist+ ' &mdash ' +track+ '</span>
|
||||
<span class="title" title="' +artist.htmlsafe()+ " — " +track.htmlsafe()+ '">' +artist+ ' — ' +track+ '</span>
|
||||
<span class="duration">' +length+ '</span>
|
||||
<div class="remove">remove</div>
|
||||
</div>
|
||||
</li>'
|
||||
|
||||
$('#playlist').html($('.playlist-tracks')).scrollbar()
|
||||
$('.playlist').html($('.playlist-tracks')).scrollbar()
|
||||
$('.playlist-tracks').sortable()
|
||||
|
||||
if autoplay
|
||||
Player.setTrack($('.playlist-tracks li').last().attr('id').split('i')[1])
|
||||
else if initial_count == 0 and not Player.hasTrack()
|
||||
Player.setTrack($('.playlist-tracks li').first().attr('id').split('i')[1])
|
||||
_player.setTrack($('.playlist-tracks li').last().attr('id').split('i')[1])
|
||||
else if initial_count == 0 and not _player.hasTrack()
|
||||
_player.setTrack($('.playlist-tracks li').first().attr('id').split('i')[1])
|
||||
|
||||
setTrack: (id) ->
|
||||
$obj = $('#i' +id)
|
||||
query = $obj.attr('data-artist')+ ' &mdash ' +$obj.attr('data-track')
|
||||
query = $obj.attr('data-artist')+ ' — ' +$obj.attr('data-track')
|
||||
|
||||
$('#player .now-playing').html query+ '<div class="fade"></div>'
|
||||
$('.player .now-playing').html query+ '<div class="fade"></div>'
|
||||
$('.playlist-tracks li').removeClass 'now'
|
||||
$obj.addClass 'now'
|
||||
$('#player .loaded, #player .played').width 0
|
||||
$('.player .loaded, .player .played').width 0
|
||||
|
||||
vkontakte.loadTracksData $obj.attr('data-artist'), $obj.attr('data-track'), $obj.attr('data-length'), ->
|
||||
player.playSource()
|
||||
_vkontakte.loadTracksData $obj.attr('data-artist'), $obj.attr('data-track'), $obj.attr('data-length'), (url)->
|
||||
_player.playSource url
|
||||
this.updateNowListening $obj.attr('data-artist'), $obj.attr('data-album'), $obj.attr('data-track')
|
||||
|
||||
hasTrack: ->
|
||||
|
@ -99,7 +99,7 @@ class Player
|
|||
cnt = $('.playlist-tracks li').length
|
||||
if not this.onShuffle() # Shuffle off
|
||||
if $('.playlist-tracks .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-tracks li').first().attr('id').split('i')[1]
|
||||
else
|
||||
false
|
||||
|
@ -117,7 +117,7 @@ class Player
|
|||
|
||||
prevTrack: ->
|
||||
cnt = $('.playlist-tracks li').length
|
||||
if not Player.onShuffle() # Shuffle off
|
||||
if not _player.onShuffle() # Shuffle off
|
||||
if $('.playlist-tracks .now').prev().length == 0 # First track in the playlist
|
||||
return $('.playlist-tracks li').last().attr('id').split('i')[1]
|
||||
else
|
||||
|
@ -139,37 +139,31 @@ class Player
|
|||
return $('#repeat').hasClass 'active'
|
||||
|
||||
updateNowListening: (artist, album, track) ->
|
||||
if session.user.lastfm_username
|
||||
session.query '/lastfm/listening?r=' +Math.random(), artist: artist, album: album, track: track
|
||||
if _session.getUser().lastfm_username
|
||||
_session.query '/lastfm/listening?r=' +Math.random(), artist: artist, album: album, track: track
|
||||
|
||||
scrobble: (artist, album, track) ->
|
||||
if session.user.lastfm_username
|
||||
session.query '/lastfm/scrobble?r=' +Math.random(), artist: artist, album: album, track: track
|
||||
|
||||
|
||||
$ ->
|
||||
window.player = new Player()
|
||||
window.player.initJplayer()
|
||||
false
|
||||
if _session.getUser().lastfm_username
|
||||
_session.query '/lastfm/scrobble?r=' +Math.random(), artist: artist, album: album, track: track
|
||||
|
||||
|
||||
# Player Controls
|
||||
|
||||
$('#player .controls .prev').live 'click', ->
|
||||
Player.setTrack Player.prevTrack()
|
||||
$('.player .controls .prev').live 'click', ->
|
||||
_player.setTrack _player.prevTrack()
|
||||
false
|
||||
|
||||
$('#player .controls .next').live 'click', ->
|
||||
Player.setTrack Player.nextTrack(true)
|
||||
$('.player .controls .next').live 'click', ->
|
||||
_player.setTrack _player.nextTrack(true)
|
||||
false
|
||||
|
||||
$('#player .play').live 'click', ->
|
||||
if $('.playlist-tracks li').length > 0 and not Player.hasTrack()
|
||||
player.setTrack $('.playlist-tracks li').first().attr('id').split('i')[1]
|
||||
$('.player .play').live 'click', ->
|
||||
if $('.playlist-tracks li').length > 0 and not _player.hasTrack()
|
||||
_player.setTrack $('.playlist-tracks li').first().attr('id').split('i')[1]
|
||||
false
|
||||
|
||||
$('#player .progress').live 'click', (e) ->
|
||||
$('#jplayer').jPlayer 'playHead', Math.round((e.offsetX / Player.bar_width) * 100)
|
||||
$('.player .progress').live 'click', (e) ->
|
||||
$('#jplayer').jPlayer 'playHead', Math.round((e.offsetX / _player.bar_width) * 100)
|
||||
false
|
||||
|
||||
# Player Additional Controls
|
||||
|
@ -182,8 +176,8 @@ $('#empty-playlist').live 'click', ->
|
|||
if confirm('Are you sure?')
|
||||
$('.playlist-tracks li').remove()
|
||||
$('#jplayer').jPlayer 'clearMedia'
|
||||
$('#player .now-playing').text 'Add some music to playlist'
|
||||
$('#player .loaded, #player .played').width 0
|
||||
$('.player .now-playing').text 'Add some music to playlist'
|
||||
$('.player .loaded, .player .played').width 0
|
||||
false
|
||||
|
||||
# Playlist Actions
|
||||
|
@ -201,13 +195,13 @@ $('.playlist-tracks li .remove').live 'click', ->
|
|||
$li = $(this).parent().parent()
|
||||
if $li.hasClass 'now'
|
||||
$('#jplayer').jPlayer 'clearMedia'
|
||||
$('#player .now-playing').text '...'
|
||||
$('#player .loaded, #player .played').width 0
|
||||
$('.player .now-playing').text '...'
|
||||
$('.player .loaded, .player .played').width 0
|
||||
$li.remove()
|
||||
false
|
||||
|
||||
$('.playlist-tracks li').live 'dblclick', ->
|
||||
player.setTrack $(this).attr('id').split('i')[1]
|
||||
_player.setTrack $(this).attr('id').split('i')[1]
|
||||
false
|
||||
|
||||
# Adding To Playlist actions
|
||||
|
@ -218,7 +212,7 @@ $('.add-album').live 'click', ->
|
|||
for item in $(this).parent().parent().parent().find('.tracklist li')
|
||||
track_name = $(item).find('.trackname').html()
|
||||
length = $(item).find('.length').html()
|
||||
Player.addTrack artist, album, track_name, length
|
||||
_player.addTrack artist, album, track_name, length
|
||||
false
|
||||
|
||||
$('.add-track').live 'click', ->
|
||||
|
@ -226,7 +220,7 @@ $('.add-track').live 'click', ->
|
|||
album = $(this).parent().parent().parent().parent().find('h2.name').text().replace /\s\([\d]{4}\)$/, ''
|
||||
track_name = $(this).parent().find('.trackname').html()
|
||||
length = $(this).parent().find('.length').html()
|
||||
Player.addTrack artist, album, track_name, length
|
||||
_player.addTrack artist, album, track_name, length
|
||||
false
|
||||
|
||||
$('.tracklist li').live 'mouseover mouseout', (e) ->
|
||||
|
@ -241,5 +235,5 @@ $('.tracklist li').live 'dblclick', (e) ->
|
|||
album = $(this).parent().parent().parent().find('h2.name').text().replace /\s\([\d]{4}\)$/, ''
|
||||
track_name = $(this).find('.trackname').html()
|
||||
length = $(this).find('.length').html()
|
||||
Player.addTrack artist, album, track_name, length, true
|
||||
_player.addTrack artist, album, track_name, length, true
|
||||
false
|
||||
|
|
|
@ -21,7 +21,7 @@ class Search
|
|||
$('.suggestions ul').append '
|
||||
<li>
|
||||
<a class="data artist">' +item.name+ '</a>
|
||||
' +(if item.desc then '<br/><span>'+ item.desc +'</span>' else '')+ '
|
||||
' +(if item.desc? then '<br/><span>'+item.desc+'</span>' else '')+ '
|
||||
</li>'
|
||||
$('.suggestions').show()
|
||||
false
|
||||
|
@ -48,16 +48,12 @@ class Search
|
|||
@pics = []
|
||||
|
||||
|
||||
$ ->
|
||||
window.search = new Search()
|
||||
false
|
||||
|
||||
$('.search').live 'click', ->
|
||||
ajax.loadSearchPage()
|
||||
_ajax.go '/search/'
|
||||
false
|
||||
$('#search_form').live 'submit', ->
|
||||
$('.autocomplete-container').remove()
|
||||
ajax.loadArtistData $('#search_field').val()
|
||||
_ajax.loadArtistData $('#search_field').val()
|
||||
false
|
||||
$('.suggestions a').live 'click', ->
|
||||
$('#search_field').val $(this).text()
|
||||
|
|
|
@ -3,7 +3,21 @@ class Session
|
|||
vk_params: null
|
||||
user: null
|
||||
|
||||
constructor: (@vk_params) ->
|
||||
constructor: (params) ->
|
||||
attrs = ['expire', 'mid', 'secret', 'sid', 'sig']
|
||||
_params = {}
|
||||
for key in attrs
|
||||
if params[key]?
|
||||
_params[key] = params[key]
|
||||
@vk_params = _params
|
||||
false
|
||||
|
||||
setUser: (user) ->
|
||||
@user = user
|
||||
false
|
||||
|
||||
getUser: ->
|
||||
@user
|
||||
|
||||
query: (url, params, callback) ->
|
||||
q_params = @vk_params
|
||||
|
@ -11,13 +25,3 @@ class Session
|
|||
q_params[attr] = params[attr]
|
||||
$.post url, q_params, callback
|
||||
false
|
||||
|
||||
setVkParams: (params) ->
|
||||
attrs = ['expire', 'mid', 'secret', 'sid', 'sig']
|
||||
for key in attrs
|
||||
@vk_params[key] = params[key]
|
||||
false
|
||||
|
||||
$ ->
|
||||
window.session = new Session()
|
||||
false
|
|
@ -1,35 +1,32 @@
|
|||
class Settings
|
||||
|
||||
getAccountInfo: (callback) ->
|
||||
session.query '/user/update/', {}, callback
|
||||
_session.query '/user/update/', {}, callback
|
||||
|
||||
saveAccountInfo: (params, callback) ->
|
||||
session.query '/user/update', params, callback
|
||||
_session.query '/user/update', params, callback
|
||||
|
||||
loadFormData: (form) ->
|
||||
if form == 'account'
|
||||
$('.settings-container .form input[name$="username"]').val session.user.name
|
||||
$('.settings-container .form input[name$="email"]').val session.email
|
||||
$('.settings-container .form input[name$="username"]').val _session.getUser().name
|
||||
$('.settings-container .form input[name$="email"]').val _session.getUser().email
|
||||
else if form == 'lastfm'
|
||||
if @user.lastfm_username
|
||||
$('.form-container input[name$="username"]').first().val session.lastfm_username
|
||||
if _session.getUser().lastfm_username
|
||||
$('.form-container input[name$="username"]').first().val _session.getUser().lastfm_username
|
||||
|
||||
$ ->
|
||||
window.settings = new Settings()
|
||||
false
|
||||
|
||||
$('.settings') .live 'click', ->
|
||||
ajax.loadSettingsPage();
|
||||
_ajax.go('/settings/');
|
||||
|
||||
$('.settings-container .tabs .tab').live 'click', ->
|
||||
if $(this).hasClass 'active'
|
||||
if not $(this).hasClass 'active'
|
||||
$('.settings-container .tabs .tab').removeClass 'active'
|
||||
$(this).addClass 'active'
|
||||
$('.form-container').html $('.forms .'+ $(this).attr 'data-fieldset').html()
|
||||
settings.loadFormData $(this).attr 'data-fieldset'
|
||||
_settings.loadFormData $(this).attr 'data-fieldset'
|
||||
|
||||
$('.lastfm-connect') .live 'click', ->
|
||||
window.open session.user.lastfm_login_url
|
||||
window.open _session.getUser().lastfm_login_url
|
||||
|
||||
$('.settings-container .form input').live 'blur', ->
|
||||
active_tab = $('.settings-container .tabs .tab.active').attr 'data-fieldset'
|
||||
|
@ -37,5 +34,5 @@ $('.settings-container .form input').live 'blur', ->
|
|||
params =
|
||||
username: $('.settings-container .form input[name$="username"]').first().val()
|
||||
email: $('.settings-container .form input[name$="email"]').first().val()
|
||||
settings.saveAccountInfo params, ->
|
||||
_settings.saveAccountInfo params, ->
|
||||
$('#header-container .hello .greating').text 'Hi there, ' +(if params.username.length > 0 then params.username else '%username%')+ '!'
|
|
@ -1,50 +1,53 @@
|
|||
class Vkontakte
|
||||
|
||||
qr: []
|
||||
qr: null
|
||||
|
||||
constructor: (@api_id) ->
|
||||
|
||||
init: ->
|
||||
@qr = []
|
||||
VK.init
|
||||
apiId: @api_id
|
||||
nameTransportPath: '/xd_receiver.html'
|
||||
|
||||
VK.Auth.getLoginStatus this.authInfo
|
||||
|
||||
authInfo: (response) ->
|
||||
if typeof response isnt 'undefined' and response.session
|
||||
session.setVkParams response.session
|
||||
|
||||
if typeof response isnt 'undefined' and response.session
|
||||
_session = new Session(response.session)
|
||||
|
||||
$('#vk_login, .auth_notice').hide()
|
||||
$('#vk_logout').css display: 'block'
|
||||
|
||||
$('#search_field').focus() if $('#search_field').length > 0
|
||||
|
||||
session.query '/user/auth', {}, (ar) ->
|
||||
_session.query '/user/auth', {}, (ar) ->
|
||||
if ar.newbie
|
||||
VK.Api.call 'getVariable', key: 1281, (r) ->
|
||||
Session.query '/user/update', name: r.response, (ar2) ->
|
||||
session.user = ar2.user
|
||||
$('#header-container .hello .greating')
|
||||
.text 'Hi there, ' +(if session.user.name then session.user.name else '%username%')+ '!'
|
||||
_session.query '/user/update', name: r.response, (ar2) ->
|
||||
_session.setUser ar2.user
|
||||
$('.header-container .hello .greating')
|
||||
.text 'Hi there, ' +(if _session.getUser().name then _session.getUser().name else '%username%')+ '!'
|
||||
else
|
||||
session.user = ar.user
|
||||
_session.setUser ar.user
|
||||
|
||||
$('#header-container .hello .greating')
|
||||
.text 'Hi there, ' +( if session.user.name then session.user.name else '%username%')+ '!'
|
||||
$('.header-container .hello .greating')
|
||||
.text 'Hi there, ' +(if _session.getUser().name then _session.getUser().name else '%username%')+ '!'
|
||||
else
|
||||
_session = new Session({})
|
||||
$('#vk_login, .auth_notice').css display: 'block'
|
||||
$('#vk_logout').hide()
|
||||
window._session = _session
|
||||
|
||||
loadTracksData: (artist, track, duration, callback) ->
|
||||
track_prepared = track.replace(/\(.*\)/i, '').split('/')[0];
|
||||
query = artist +' '+ track_prepared;
|
||||
if @qr[query]?
|
||||
callback @qr[query]
|
||||
query = artist+' '+track_prepared;
|
||||
if url = _vkontakte.getQR query
|
||||
callback url
|
||||
else
|
||||
VK.Api.call 'audio.search', q: query, (r) ->
|
||||
url = this.matchPerfectResult r.response, artist, track, duration
|
||||
@qr[query] = url;
|
||||
r.response.splice 0, 1
|
||||
url = _vkontakte.matchPerfectResult r.response, artist, track, duration
|
||||
_vkontakte.addQR query, url
|
||||
callback url
|
||||
|
||||
matchPerfectResult: (data, artist, track, duration) ->
|
||||
|
@ -84,9 +87,17 @@ class Vkontakte
|
|||
return best_result.url
|
||||
|
||||
return best_result.url
|
||||
|
||||
addQR: (query, url) ->
|
||||
@qr[query] = url;
|
||||
|
||||
getQR: (query) ->
|
||||
if @qr[query]?
|
||||
@qr[query]
|
||||
false
|
||||
|
||||
$ ->
|
||||
$('#vk_login').click ->
|
||||
VK.Auth.login vkontakte.authInfo, 8
|
||||
VK.Auth.login _vkontakte.authInfo(), 8
|
||||
$('#vk_logout').click ->
|
||||
VK.Auth.logout vkontakte.authInfo
|
||||
VK.Auth.logout _vkontakte.authInfo()
|
||||
|
|
|
@ -38,7 +38,7 @@ class ArtistController < ApplicationController
|
|||
render :json => {status: 'corrected', page: results[0][:name]}
|
||||
return
|
||||
else
|
||||
render :json => {status: 'suggestions', values: results}
|
||||
render :json => {status: 'suggestions', values: results.take(5)}
|
||||
return
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,7 +12,10 @@
|
|||
<%= javascript_include_tag "jquery/jquery.contentchange.js" %>
|
||||
<%= javascript_include_tag "jquery/jquery.jplayer.js" %>
|
||||
<%= javascript_include_tag "jquery/jquery.scroll.js" %>
|
||||
|
||||
<%= javascript_include_tag "coffee/beathaven.js", :type => "text/javascript", :charset => "utf-8" %>
|
||||
<%= javascript_include_tag "coffee/vkontakte.js", :type => "text/javascript", :charset => "utf-8" %>
|
||||
<%= javascript_include_tag "coffee/session.js", :type => "text/javascript", :charset => "utf-8" %>
|
||||
<%= javascript_include_tag "coffee/ajax.js", :type => "text/javascript", :charset => "utf-8" %>
|
||||
<%= javascript_include_tag "coffee/player.js", :type => "text/javascript", :charset => "utf-8" %>
|
||||
<%= javascript_include_tag "coffee/search.js", :type => "text/javascript", :charset => "utf-8" %>
|
||||
<%= javascript_include_tag "coffee/pages.js", :type => "text/javascript", :charset => "utf-8" %>
|
||||
|
@ -63,7 +66,6 @@
|
|||
<li class="search">Search</li>
|
||||
<li><a href="https://twitter.com/#!/beat_haven" target="_blank">News</a></li>
|
||||
<li class="vk_auth" id="vk_login">Login</li>
|
||||
<li class="vk_auth" id="vk_logout">Logout</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="data-container" class="css-scrollbar">
|
||||
|
|
|
@ -15,7 +15,7 @@ Barista.configure do |c|
|
|||
# c.register :tests, :root => Rails.root.join('test', 'coffeescript'), :output_prefix => 'test'
|
||||
|
||||
# Disable wrapping in a closure:
|
||||
# c.bare = true
|
||||
c.bare = true
|
||||
# ... or ...
|
||||
# c.bare!
|
||||
|
||||
|
|
|
@ -1,87 +1,89 @@
|
|||
/* DO NOT MODIFY. This file was compiled Mon, 27 Jun 2011 17:43:40 GMT from
|
||||
* /Users/chez/Sites/beathaven/app/coffeescripts/ajax.coffee
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var Ajax;
|
||||
Ajax = (function() {
|
||||
function Ajax() {}
|
||||
Ajax.prototype.referer = false;
|
||||
Ajax.prototype.loadArtistData = function(name) {
|
||||
search.showSpinner();
|
||||
name = name.split(' ').join('+');
|
||||
return $.get('/artist/' + name + '/', function(data) {
|
||||
if (data.status != null) {
|
||||
if (data.status === 'loading') {
|
||||
search.showArtistPics(data.pics);
|
||||
return setTimeout(function() {
|
||||
return this.loadArtistData(name);
|
||||
}, 3000);
|
||||
} else if (data.status === 'corrected') {
|
||||
return ajax.loadArtistData(data.page);
|
||||
} else if (data.status === 'suggestions') {
|
||||
search.hideSpinner();
|
||||
return search.showSuggestions(data.values);
|
||||
} else if (data.status === 'loading_failed') {
|
||||
search.hideSpinner();
|
||||
return search.showError();
|
||||
}
|
||||
} else {
|
||||
this.setArchor('/artist/' + name + '/');
|
||||
pages.renderArtist(data);
|
||||
return beathaven.redrawScrollbar();
|
||||
var Ajax;
|
||||
Ajax = (function() {
|
||||
function Ajax() {}
|
||||
Ajax.prototype.referer = false;
|
||||
Ajax.prototype.loadArtistData = function(name) {
|
||||
_search.showSpinner();
|
||||
name = name.split(' ').join('+');
|
||||
$.get('/artist/' + name + '/', function(data) {
|
||||
if (data.status != null) {
|
||||
if (data.status === 'loading') {
|
||||
_search.showArtistPics(data.pics);
|
||||
return setTimeout(function() {
|
||||
return _ajax.loadArtistData(name);
|
||||
}, 3000);
|
||||
} else if (data.status === 'corrected') {
|
||||
return _ajax.loadArtistData(data.page);
|
||||
} else if (data.status === 'suggestions') {
|
||||
_search.hideSpinner();
|
||||
return _search.showSuggestions(data.values);
|
||||
} else if (data.status === 'loading_failed') {
|
||||
_search.hideSpinner();
|
||||
return _search.showError();
|
||||
}
|
||||
});
|
||||
};
|
||||
Ajax.prototype.loadSearchPage = function() {
|
||||
return $.get('/templates/search.html', function(data) {
|
||||
this.setArchor('/search/');
|
||||
return pages.renderSearch(data);
|
||||
});
|
||||
};
|
||||
Ajax.prototype.loadSettingsPage = function() {
|
||||
return $.get('/templates/settings.html', function(data) {
|
||||
this.setArchor('/settings/');
|
||||
return pages.renderSettings(data);
|
||||
});
|
||||
};
|
||||
Ajax.prototype.load404Page = function() {
|
||||
return $.get('/404.html', function(data) {
|
||||
$('.data-container .inner').html(data);
|
||||
return beathaven.redrawScrollbar();
|
||||
});
|
||||
};
|
||||
Ajax.prototype.setArchor = function(anchor) {
|
||||
this.referer = this.getAnchor();
|
||||
return window.location.hash = '#' + anchor;
|
||||
};
|
||||
Ajax.prototype.getAnchor = function() {
|
||||
return window.location.hash.substring(1);
|
||||
};
|
||||
Ajax.prototype.setTitle = function(title) {
|
||||
return document.title = title + ' @ BeatHaven';
|
||||
};
|
||||
Ajax.prototype.detectPage = function() {
|
||||
var m;
|
||||
if (m = this.getAnchor().match(/\/artist\/(.+)\//)) {
|
||||
return this.loadArtistData(m[1]);
|
||||
} else if (this.getAnchor() === '' || Ajax.getAnchor().match(/\/search\//)) {
|
||||
return this.loadSearchPage();
|
||||
} else if (this.getAnchor().match(/\/settings\//)) {
|
||||
return this.loadSearchPage();
|
||||
} else {
|
||||
return this.load404Page();
|
||||
_ajax.setArchor('/artist/' + name + '/');
|
||||
_pages.renderArtist(data);
|
||||
return _beathaven.redrawScrollbar();
|
||||
}
|
||||
};
|
||||
return Ajax;
|
||||
})();
|
||||
$(function() {
|
||||
$('a.data.artist').live('click', function() {
|
||||
ajax.loadArtistData($(this).html());
|
||||
return false;
|
||||
});
|
||||
return $(window).bind('hashchange', function() {
|
||||
return ajax.detectPage();
|
||||
return false;
|
||||
};
|
||||
Ajax.prototype.loadSearchPage = function() {
|
||||
$.get('/templates/search.html', function(data) {
|
||||
_ajax.setArchor('/search/');
|
||||
return _pages.renderSearch(data);
|
||||
});
|
||||
});
|
||||
}).call(this);
|
||||
return false;
|
||||
};
|
||||
Ajax.prototype.loadSettingsPage = function() {
|
||||
$.get('/templates/settings.html', function(data) {
|
||||
_ajax.setArchor('/settings/');
|
||||
return _pages.renderSettings(data);
|
||||
});
|
||||
return false;
|
||||
};
|
||||
Ajax.prototype.load404Page = function() {
|
||||
$.get('/404.html', function(data) {
|
||||
$('.data-container .inner').html(data);
|
||||
return _beathaven.redrawScrollbar();
|
||||
});
|
||||
return false;
|
||||
};
|
||||
Ajax.prototype.setArchor = function(anchor) {
|
||||
this.referer = this.getAnchor();
|
||||
return window.location.hash = '#' + anchor;
|
||||
};
|
||||
Ajax.prototype.getAnchor = function() {
|
||||
return window.location.hash.substring(1);
|
||||
};
|
||||
Ajax.prototype.setTitle = function(title) {
|
||||
return document.title = title + ' @ BeatHaven';
|
||||
};
|
||||
Ajax.prototype.go = function(url) {
|
||||
this.setArchor(url);
|
||||
return false;
|
||||
};
|
||||
Ajax.prototype.detectPage = function() {
|
||||
var m;
|
||||
if (m = _ajax.getAnchor().match(/\/artist\/(.+)\//)) {
|
||||
_ajax.loadArtistData(m[1]);
|
||||
} else if (_ajax.getAnchor() === '' || _ajax.getAnchor().match(/\/search\//)) {
|
||||
_ajax.loadSearchPage();
|
||||
} else if (_ajax.getAnchor().match(/\/settings\//)) {
|
||||
_ajax.loadSettingsPage();
|
||||
} else {
|
||||
_ajax.loadSearchPage();
|
||||
}
|
||||
return false;
|
||||
};
|
||||
return Ajax;
|
||||
})();
|
||||
$('a.data.artist').live('click', function() {
|
||||
_ajax.loadArtistData($(this).html());
|
||||
return false;
|
||||
});
|
||||
$(window).bind('hashchange', function() {
|
||||
_ajax.detectPage();
|
||||
return false;
|
||||
});
|
|
@ -1,95 +1,97 @@
|
|||
/* DO NOT MODIFY. This file was compiled Mon, 27 Jun 2011 17:49:39 GMT from
|
||||
* /Users/chez/Sites/beathaven/app/coffeescripts/beathaven.coffee
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var BeatHaven;
|
||||
$(function() {
|
||||
var ajax, beathaven, l, pages, player, search, session, settings, vkontakte, _ref;
|
||||
l = document.location;
|
||||
if ((_ref = l.host) !== 'beathaven.org' && _ref !== 'localhost') {
|
||||
l.href = 'http://beathaven.org/' + l.hash;
|
||||
}
|
||||
beathaven = new BeatHaven();
|
||||
vkontakte = new Vkontakte(l.host === 'beathaven.org' ? 2335068 : 2383163);
|
||||
session = new Session();
|
||||
ajax = new Ajax();
|
||||
player = new Player();
|
||||
search = new Search();
|
||||
pages = new Pages();
|
||||
settings = new Settings();
|
||||
beathaven.init();
|
||||
vkontakte.init();
|
||||
$(window).resize(function() {
|
||||
return beathaven.adjustSizes();
|
||||
});
|
||||
return window.setTimeout(function() {
|
||||
return beathaven.checkRedrawScrollbar();
|
||||
}, 500);
|
||||
var BeatHaven, _ajax, _beathaven, _pages, _player, _search, _session, _settings, _vkontakte;
|
||||
_beathaven = null;
|
||||
_session = 1;
|
||||
_vkontakte = null;
|
||||
_ajax = null;
|
||||
_player = null;
|
||||
_search = null;
|
||||
_pages = null;
|
||||
_settings = null;
|
||||
$(function() {
|
||||
var l, _ref;
|
||||
l = document.location;
|
||||
if ((_ref = l.host) !== 'beathaven.org' && _ref !== 'localhost') {
|
||||
l.href = 'http://beathaven.org/' + l.hash;
|
||||
}
|
||||
_beathaven = new BeatHaven();
|
||||
_beathaven.init();
|
||||
$(window).resize(function() {
|
||||
return _beathaven.adjustSizes();
|
||||
});
|
||||
BeatHaven = (function() {
|
||||
function BeatHaven() {}
|
||||
BeatHaven.prototype.last_height = false;
|
||||
BeatHaven.prototype.init = function() {
|
||||
this.drawInterface();
|
||||
this.adjustSizes();
|
||||
return ajax.detectPage();
|
||||
};
|
||||
BeatHaven.prototype.adjustSizes = function() {
|
||||
$('.data-container').height($(window).height() - $('.header-container').height());
|
||||
$('.data-container').width($(window).width() - $('.player').width());
|
||||
$('.player-container').height($(window).height());
|
||||
$('.playlist').height($(window).height() - $('.player').height() - $('.player-container .additional-controls').height());
|
||||
$('.data-container').scrollbar();
|
||||
return $('.playlist').scrollbar();
|
||||
};
|
||||
BeatHaven.prototype.checkRedrawScrollbar = function() {
|
||||
var focused_id, outer_height;
|
||||
return window.setTimeout(function() {
|
||||
return _beathaven.checkRedrawScrollbar();
|
||||
}, 500);
|
||||
});
|
||||
BeatHaven = (function() {
|
||||
function BeatHaven() {}
|
||||
BeatHaven.prototype.last_height = false;
|
||||
BeatHaven.prototype.init = function() {
|
||||
this.adjustSizes();
|
||||
this.checkRedrawScrollbar();
|
||||
_vkontakte = new Vkontakte(document.location.host === 'beathaven.org' ? 2335068 : 2383163);
|
||||
_vkontakte.init();
|
||||
_ajax = new Ajax();
|
||||
_player = new Player();
|
||||
_player.initJplayer();
|
||||
_search = new Search();
|
||||
_pages = new Pages();
|
||||
_settings = new Settings();
|
||||
return _ajax.detectPage();
|
||||
};
|
||||
BeatHaven.prototype.adjustSizes = function() {
|
||||
$('.data-container').height($(window).height() - $('.header-container').height());
|
||||
$('.data-container').width($(window).width() - $('.player').width());
|
||||
$('.player-container').height($(window).height());
|
||||
$('.playlist').height($(window).height() - $('.player').height() - $('.player-container .additional-controls').height());
|
||||
$('.data-container').scrollbar();
|
||||
return $('.playlist').scrollbar();
|
||||
};
|
||||
BeatHaven.prototype.checkRedrawScrollbar = function() {
|
||||
var focused_id, outer_height;
|
||||
focused_id = false;
|
||||
if (document.activeElement.id != null) {
|
||||
focused_id = document.activeElement.id;
|
||||
}
|
||||
outer_height = $('.data-container > div').outerHeight();
|
||||
if (outer_height > 300 && outer_height !== this.last_height) {
|
||||
this.last_height = outer_height;
|
||||
this.redrawScrollbar();
|
||||
}
|
||||
if (focused_id) {
|
||||
document.getElementById(focused_id).focus();
|
||||
focused_id = false;
|
||||
if (document.activeElement.id != null) {
|
||||
focused_id = document.activeElement.id;
|
||||
}
|
||||
outer_height = $('.data-container > div').outerHeight();
|
||||
if (outer_height > 300 && outer_height !== this.last_height) {
|
||||
this.last_height = outer_height;
|
||||
this.redrawScrollbar();
|
||||
}
|
||||
if (focused_id) {
|
||||
document.getElementById(focused_id).focus();
|
||||
focused_id = false;
|
||||
}
|
||||
return window.setTimeout(function() {
|
||||
return beathaven.checkRedrawScrollbar();
|
||||
}, 500);
|
||||
};
|
||||
BeatHaven.prototype.redrawScrollbar = function() {
|
||||
$('.data-container').html($('.data-container').find('.inner').first());
|
||||
return $('.data-container').scrollbar();
|
||||
};
|
||||
return BeatHaven;
|
||||
})();
|
||||
String.prototype.htmlsafe = function() {
|
||||
var item, replaces, str, _i, _len;
|
||||
replaces = [["\\", "\\\\"], ["\"", """], ["<", "<"], [">", ">"]];
|
||||
str = this;
|
||||
for (_i = 0, _len = replaces.length; _i < _len; _i++) {
|
||||
item = replaces[_i];
|
||||
str = str.replace(item[0], item[1]);
|
||||
}
|
||||
return str;
|
||||
return window.setTimeout(function() {
|
||||
return _beathaven.checkRedrawScrollbar();
|
||||
}, 500);
|
||||
};
|
||||
String.prototype.trim = function() {
|
||||
var str;
|
||||
str = this;
|
||||
while (str.indexOf(' ') !== -1) {
|
||||
str = str.replace(' ', ' ');
|
||||
}
|
||||
if (str.charAt(0) === ' ') {
|
||||
str = str.substring(1);
|
||||
}
|
||||
if (str.charAt(str.length - 1) === ' ') {
|
||||
str = str.substring(0, str.length - 1);
|
||||
}
|
||||
return str;
|
||||
BeatHaven.prototype.redrawScrollbar = function() {
|
||||
$('.data-container').html($('.data-container').find('.inner').first());
|
||||
return $('.data-container').scrollbar();
|
||||
};
|
||||
}).call(this);
|
||||
return BeatHaven;
|
||||
})();
|
||||
String.prototype.htmlsafe = function() {
|
||||
var item, replaces, str, _i, _len;
|
||||
replaces = [["\\", "\\\\"], ["\"", """], ["<", "<"], [">", ">"]];
|
||||
str = this;
|
||||
for (_i = 0, _len = replaces.length; _i < _len; _i++) {
|
||||
item = replaces[_i];
|
||||
str = str.replace(item[0], item[1]);
|
||||
}
|
||||
return str;
|
||||
};
|
||||
String.prototype.trim = function() {
|
||||
var str;
|
||||
str = this;
|
||||
while (str.indexOf(' ') !== -1) {
|
||||
str = str.replace(' ', ' ');
|
||||
}
|
||||
if (str.charAt(0) === ' ') {
|
||||
str = str.substring(1);
|
||||
}
|
||||
if (str.charAt(str.length - 1) === ' ') {
|
||||
str = str.substring(0, str.length - 1);
|
||||
}
|
||||
return str;
|
||||
};
|
|
@ -1,14 +1,9 @@
|
|||
/* DO NOT MODIFY. This file was compiled Mon, 27 Jun 2011 17:49:39 GMT from
|
||||
* /Users/chez/Sites/beathaven/app/coffeescripts/pages.coffee
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var Pages;
|
||||
Pages = (function() {
|
||||
function Pages() {}
|
||||
Pages.prototype.renderArtist = function(data) {
|
||||
var albums_info, artist_info;
|
||||
artist_info = $('\
|
||||
var Pages;
|
||||
Pages = (function() {
|
||||
function Pages() {}
|
||||
Pages.prototype.renderArtist = function(data) {
|
||||
var albums_info, artist_info;
|
||||
artist_info = $('\
|
||||
<div class="artist-info">\
|
||||
<div class="pic">\
|
||||
<img src="' + data.artist.pic + '" alt="' + data.artist.name + '" width="250" />\
|
||||
|
@ -18,11 +13,11 @@
|
|||
' + data.artist.desc + '\
|
||||
</div>\
|
||||
</div>');
|
||||
albums_info = $('<div class="albums"></div>');
|
||||
$.each(data.albums, function(i, album) {
|
||||
var album_info;
|
||||
if (album.year != null) {
|
||||
album_info = $('\
|
||||
albums_info = $('<div class="albums"></div>');
|
||||
$.each(data.albums, function(i, album) {
|
||||
var album_info;
|
||||
if (album.year != null) {
|
||||
album_info = $('\
|
||||
<div class="album">\
|
||||
<h2 class="name">' + album.name + ' (' + album.year + ')</h2>\
|
||||
<div class="pic">\
|
||||
|
@ -34,9 +29,9 @@
|
|||
<div class="tracklist"><ul></ul></div>\
|
||||
</div>\
|
||||
<div class="kaboom"></div>');
|
||||
$.each(album.tracks.album, function(i, track) {
|
||||
var track_info;
|
||||
track_info = $('\
|
||||
$.each(album.tracks.album, function(i, track) {
|
||||
var track_info;
|
||||
track_info = $('\
|
||||
<li>\
|
||||
<div class="add-track button gray">+</div>\
|
||||
<div class="track-container">\
|
||||
|
@ -46,51 +41,53 @@
|
|||
<div class="length">' + track.duration + '</div>\
|
||||
</div>\
|
||||
</li>');
|
||||
return $(album_info).find('.tracklist ul').append(track_info);
|
||||
});
|
||||
return $(albums_info).append(album_info);
|
||||
return $(album_info).find('.tracklist ul').append(track_info);
|
||||
});
|
||||
return $(albums_info).append(album_info);
|
||||
}
|
||||
});
|
||||
$('.data-container').css({
|
||||
backgroundImage: 'none'
|
||||
});
|
||||
$('.data-container .inner').html('').append(artist_info).append(albums_info);
|
||||
yaCounter7596904.hit(_ajax.getAnchor(), data.artist.name, _ajax.referer);
|
||||
_ajax.setTitle(data.artist.name);
|
||||
return false;
|
||||
};
|
||||
Pages.prototype.renderSearch = function(data) {
|
||||
$('.data-container').css({
|
||||
background: 'url(/images/concrete_wall_2.png) 0 -30px repeat'
|
||||
});
|
||||
$('.data-container .inner').html(data);
|
||||
$('.search-container').css('marginLeft', ($('.data-container').width() - 425) / 2 + 'px').css('marginTop', ($('.data-container').height() / 2 - 230) + 'px').height(($('.data-container').height() - $('#search_form').height()) / 2);
|
||||
setTimeout(function() {
|
||||
$('#search_field').bh_autocomplete({
|
||||
serviceUrl: '/artist/autocomplete',
|
||||
minChars: 2,
|
||||
delimiter: /(,|;)\s*/,
|
||||
maxHeight: 400,
|
||||
width: 415,
|
||||
zIndex: 9999,
|
||||
deferRequestBy: 500,
|
||||
onSelect: function() {
|
||||
return _ajax.loadArtistData($('#search_field').val());
|
||||
}
|
||||
});
|
||||
$('.data-container').css({
|
||||
backgroundImage: 'none'
|
||||
});
|
||||
$('.data-container .inner').html('').append(artist_info).append(albums_info);
|
||||
yaCounter7596904.hit(ajax.getAnchor(), data.artist.name, ajax.referer);
|
||||
return ajax.setTitle(data.artist.name);
|
||||
};
|
||||
Pages.prototype.renderSearch = function(data) {
|
||||
$('.data-container').css({
|
||||
background: 'url(/images/concrete_wall_2.png) 0 -30px repeat'
|
||||
});
|
||||
$('.data-container .inner').html(data);
|
||||
$('.search-container').css('marginLeft', ($('.data-container').width() - 425) / 2 + 'px').css('marginTop', ($('.data-container').height() / 2 - 230) + 'px').height(($('.data-container').height() - $('#search_form').height()) / 2);
|
||||
setTimeout(function() {
|
||||
$('#search_field').bh_autocomplete({
|
||||
serviceUrl: '/artist/autocomplete',
|
||||
minChars: 2,
|
||||
delimiter: /(,|;)\s*/,
|
||||
maxHeight: 400,
|
||||
width: 415,
|
||||
zIndex: 9999,
|
||||
deferRequestBy: 500,
|
||||
onSelect: function() {
|
||||
return ajax.loadArtistData();
|
||||
}
|
||||
});
|
||||
return $('#search_field').focus();
|
||||
}, 501);
|
||||
yaCounter7596904.hit(ajax.getAnchor(), 'Artist Search', ajax.referer);
|
||||
return ajax.setTitle('Artist Search');
|
||||
};
|
||||
Pages.prototype.renderSettings = function(data) {
|
||||
$('.data-container').css({
|
||||
background: 'none'
|
||||
});
|
||||
$('.data-container .inner').html(data);
|
||||
yaCounter7596904.hit(ajax.getAnchor(), 'Settings', ajax.referer);
|
||||
ajax.setTitle('Settings');
|
||||
return $('.settings-container .tabs .tab').first().trigger('click');
|
||||
};
|
||||
return Pages;
|
||||
})();
|
||||
}).call(this);
|
||||
return $('#search_field').focus();
|
||||
}, 501);
|
||||
yaCounter7596904.hit(_ajax.getAnchor(), 'Artist Search', _ajax.referer);
|
||||
_ajax.setTitle('Artist Search');
|
||||
return false;
|
||||
};
|
||||
Pages.prototype.renderSettings = function(data) {
|
||||
$('.data-container').css({
|
||||
background: 'none'
|
||||
});
|
||||
$('.data-container .inner').html(data);
|
||||
yaCounter7596904.hit(_ajax.getAnchor(), 'Settings', _ajax.referer);
|
||||
_ajax.setTitle('Settings');
|
||||
$('.settings-container .tabs .tab').first().trigger('click');
|
||||
return false;
|
||||
};
|
||||
return Pages;
|
||||
})();
|
|
@ -1,285 +1,276 @@
|
|||
/* DO NOT MODIFY. This file was compiled Mon, 27 Jun 2011 17:49:39 GMT from
|
||||
* /Users/chez/Sites/beathaven/app/coffeescripts/player.coffee
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var Player;
|
||||
Player = (function() {
|
||||
function Player() {}
|
||||
Player.prototype.bar_width = 330;
|
||||
Player.prototype.jp = null;
|
||||
Player.prototype.scrobbled = false;
|
||||
Player.prototype.initJplayer = function() {
|
||||
var self;
|
||||
self = this;
|
||||
this.jp = $("#jplayer");
|
||||
this.jp.jPlayer({
|
||||
swfPath: "/js",
|
||||
supplied: "mp3",
|
||||
cssSelectorAncestor: "",
|
||||
cssSelector: {
|
||||
play: "#player .play",
|
||||
pause: "#player .pause",
|
||||
stop: "",
|
||||
videoPlay: "",
|
||||
seekBar: "",
|
||||
playBar: "",
|
||||
mute: "",
|
||||
unmute: "",
|
||||
volumeBar: "",
|
||||
volumeBarValue: "",
|
||||
currentTime: "",
|
||||
duration: ""
|
||||
}
|
||||
});
|
||||
this.jp.bind($.jPlayer.event.timeupdate, function(e) {
|
||||
var $obj, data;
|
||||
data = e.jPlayer.status;
|
||||
if (!Player.scrobbled && data.currentPercentAbsolute > 50) {
|
||||
$obj = $('.playlist-tracks li.now');
|
||||
self.scrobble($obj.attr('data-artist'), $obj.attr('data-album'), $obj.attr('data-track'));
|
||||
Player.scrobbled = true;
|
||||
}
|
||||
$('#player .progress .loaded').width(data.seekPercent * self.bar_width / 100);
|
||||
return $('#player .progress .played').width(data.currentPercentAbsolute * self.bar_width / 100);
|
||||
});
|
||||
this.jp.bind($.jPlayer.event.ended, function(e) {
|
||||
var next;
|
||||
next = self.nextTrack();
|
||||
if (!next) {
|
||||
$('#jplayer').jPlayer('clearMedia');
|
||||
$('#player .now-playing').html('Nothing left to <strike>lose</strike> play');
|
||||
$('#player .loaded, #player .played').width(0);
|
||||
return $('.playlist-tracks li').removeClass('now');
|
||||
} else {
|
||||
return self.setTrack(next);
|
||||
}
|
||||
});
|
||||
return false;
|
||||
};
|
||||
Player.prototype.addTrack = function(artist, album, track, length, autoplay) {
|
||||
var initial_count;
|
||||
if (!(autoplay != null)) {
|
||||
autoplay = false;
|
||||
var Player;
|
||||
Player = (function() {
|
||||
function Player() {}
|
||||
Player.prototype.bar_width = 330;
|
||||
Player.prototype.jp = null;
|
||||
Player.prototype.scrobbled = false;
|
||||
Player.prototype.initJplayer = function() {
|
||||
var self;
|
||||
self = this;
|
||||
this.jp = $("#jplayer");
|
||||
this.jp.jPlayer({
|
||||
swfPath: "/js",
|
||||
supplied: "mp3",
|
||||
cssSelectorAncestor: "",
|
||||
cssSelector: {
|
||||
play: ".player .play",
|
||||
pause: ".player .pause",
|
||||
stop: "",
|
||||
videoPlay: "",
|
||||
seekBar: "",
|
||||
playBar: "",
|
||||
mute: "",
|
||||
unmute: "",
|
||||
volumeBar: "",
|
||||
volumeBarValue: "",
|
||||
currentTime: "",
|
||||
duration: ""
|
||||
}
|
||||
initial_count = $('.playlist-tracks li').length;
|
||||
$('.playlist-tracks').append('\
|
||||
});
|
||||
this.jp.bind($.jPlayer.event.timeupdate, function(e) {
|
||||
var $obj, data;
|
||||
data = e.jPlayer.status;
|
||||
if (!_player.scrobbled && data.currentPercentAbsolute > 50) {
|
||||
$obj = $('.playlist-tracks li.now');
|
||||
self.scrobble($obj.attr('data-artist'), $obj.attr('data-album'), $obj.attr('data-track'));
|
||||
_player.scrobbled = true;
|
||||
}
|
||||
$('.player .progress .loaded').width(data.seekPercent * self.bar_width / 100);
|
||||
return $('.player .progress .played').width(data.currentPercentAbsolute * self.bar_width / 100);
|
||||
});
|
||||
this.jp.bind($.jPlayer.event.ended, function(e) {
|
||||
var next;
|
||||
next = self.nextTrack();
|
||||
if (!next) {
|
||||
$('#jplayer').jPlayer('clearMedia');
|
||||
$('.player .now-playing').html('Nothing left to <strike>lose</strike> play');
|
||||
$('.player .loaded, .player .played').width(0);
|
||||
return $('.playlist-tracks li').removeClass('now');
|
||||
} else {
|
||||
return self.setTrack(next);
|
||||
}
|
||||
});
|
||||
return false;
|
||||
};
|
||||
Player.prototype.addTrack = function(artist, album, track, length, autoplay) {
|
||||
var initial_count;
|
||||
if (!(autoplay != null)) {
|
||||
autoplay = false;
|
||||
}
|
||||
initial_count = $('.playlist-tracks li').length;
|
||||
$('.playlist-tracks').append('\
|
||||
<li id="i' + Math.round(Math.random() * 999999) + '" data-artist="' + artist.trim() + '" data-album="' + album.trim() + '" data-track="' + track.trim() + '" data-length="' + length + '">\
|
||||
<div class="item">\
|
||||
<div class="fade"></div>\
|
||||
<span class="title" title="' + artist.htmlsafe() + ' &mdash ' + track.htmlsafe() + '">' + artist + ' &mdash ' + track + '</span>\
|
||||
<span class="title" title="' + artist.htmlsafe() + " — " + track.htmlsafe() + '">' + artist + ' — ' + track + '</span>\
|
||||
<span class="duration">' + length + '</span>\
|
||||
<div class="remove">remove</div>\
|
||||
</div>\
|
||||
</li>');
|
||||
$('#playlist').html($('.playlist-tracks')).scrollbar();
|
||||
$('.playlist-tracks').sortable();
|
||||
if (autoplay) {
|
||||
return Player.setTrack($('.playlist-tracks li').last().attr('id').split('i')[1]);
|
||||
} else if (initial_count === 0 && !Player.hasTrack()) {
|
||||
return Player.setTrack($('.playlist-tracks li').first().attr('id').split('i')[1]);
|
||||
}
|
||||
};
|
||||
Player.prototype.setTrack = function(id) {
|
||||
var $obj, query;
|
||||
$obj = $('#i' + id);
|
||||
query = $obj.attr('data-artist') + ' &mdash ' + $obj.attr('data-track');
|
||||
$('#player .now-playing').html(query + '<div class="fade"></div>');
|
||||
$('.playlist-tracks li').removeClass('now');
|
||||
$obj.addClass('now');
|
||||
$('#player .loaded, #player .played').width(0);
|
||||
vkontakte.loadTracksData($obj.attr('data-artist'), $obj.attr('data-track'), $obj.attr('data-length'), function() {
|
||||
return player.playSource();
|
||||
});
|
||||
return this.updateNowListening($obj.attr('data-artist'), $obj.attr('data-album'), $obj.attr('data-track'));
|
||||
};
|
||||
Player.prototype.hasTrack = function() {
|
||||
if ($('#jplayer audio').length > 0) {
|
||||
return $('#jplayer audio').attr('src') != null;
|
||||
} else if ($('#jplayer object').length > 0) {
|
||||
$('#jplayer').jPlayer('play');
|
||||
true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
Player.prototype.playSource = function(url) {
|
||||
$('#jplayer').jPlayer('setMedia', {
|
||||
mp3: url
|
||||
});
|
||||
$('.playlist').html($('.playlist-tracks')).scrollbar();
|
||||
$('.playlist-tracks').sortable();
|
||||
if (autoplay) {
|
||||
return _player.setTrack($('.playlist-tracks li').last().attr('id').split('i')[1]);
|
||||
} else if (initial_count === 0 && !_player.hasTrack()) {
|
||||
return _player.setTrack($('.playlist-tracks li').first().attr('id').split('i')[1]);
|
||||
}
|
||||
};
|
||||
Player.prototype.setTrack = function(id) {
|
||||
var $obj, query;
|
||||
$obj = $('#i' + id);
|
||||
query = $obj.attr('data-artist') + ' — ' + $obj.attr('data-track');
|
||||
$('.player .now-playing').html(query + '<div class="fade"></div>');
|
||||
$('.playlist-tracks li').removeClass('now');
|
||||
$obj.addClass('now');
|
||||
$('.player .loaded, .player .played').width(0);
|
||||
_vkontakte.loadTracksData($obj.attr('data-artist'), $obj.attr('data-track'), $obj.attr('data-length'), function(url) {
|
||||
return _player.playSource(url);
|
||||
});
|
||||
return this.updateNowListening($obj.attr('data-artist'), $obj.attr('data-album'), $obj.attr('data-track'));
|
||||
};
|
||||
Player.prototype.hasTrack = function() {
|
||||
if ($('#jplayer audio').length > 0) {
|
||||
return $('#jplayer audio').attr('src') != null;
|
||||
} else if ($('#jplayer object').length > 0) {
|
||||
$('#jplayer').jPlayer('play');
|
||||
return this.scrobbled = false;
|
||||
};
|
||||
Player.prototype.nextTrack = function(manual) {
|
||||
var $li, cnt, rnd;
|
||||
manual = manual != null;
|
||||
cnt = $('.playlist-tracks li').length;
|
||||
if (!this.onShuffle()) {
|
||||
if ($('.playlist-tracks .now').next().length === 0) {
|
||||
if (Player.onRepeat() || manual) {
|
||||
return $('.playlist-tracks li').first().attr('id').split('i')[1];
|
||||
} else {
|
||||
false;
|
||||
}
|
||||
true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
Player.prototype.playSource = function(url) {
|
||||
$('#jplayer').jPlayer('setMedia', {
|
||||
mp3: url
|
||||
});
|
||||
$('#jplayer').jPlayer('play');
|
||||
return this.scrobbled = false;
|
||||
};
|
||||
Player.prototype.nextTrack = function(manual) {
|
||||
var $li, cnt, rnd;
|
||||
manual = manual != null;
|
||||
cnt = $('.playlist-tracks li').length;
|
||||
if (!this.onShuffle()) {
|
||||
if ($('.playlist-tracks .now').next().length === 0) {
|
||||
if (_player.onRepeat() || manual) {
|
||||
return $('.playlist-tracks li').first().attr('id').split('i')[1];
|
||||
} else {
|
||||
return $('.playlist-tracks .now').next().attr('id').split('i')[1];
|
||||
false;
|
||||
}
|
||||
} else if (cnt === 1) {
|
||||
return $('.playlist-tracks li').first().attr('id').split('i')[1];
|
||||
} else {
|
||||
while (true) {
|
||||
rnd = Math.floor(Math.random() * (cnt + .999));
|
||||
$li = $('.playlist-tracks li').eq(rnd);
|
||||
if ($li.length > 0 && !$li.hasClass('now')) {
|
||||
return $li.attr('id').split('i')[1];
|
||||
}
|
||||
return $('.playlist-tracks .now').next().attr('id').split('i')[1];
|
||||
}
|
||||
} else if (cnt === 1) {
|
||||
return $('.playlist-tracks li').first().attr('id').split('i')[1];
|
||||
} else {
|
||||
while (true) {
|
||||
rnd = Math.floor(Math.random() * (cnt + .999));
|
||||
$li = $('.playlist-tracks li').eq(rnd);
|
||||
if ($li.length > 0 && !$li.hasClass('now')) {
|
||||
return $li.attr('id').split('i')[1];
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
Player.prototype.prevTrack = function() {
|
||||
var $li, cnt, rnd;
|
||||
cnt = $('.playlist-tracks li').length;
|
||||
if (!Player.onShuffle()) {
|
||||
if ($('.playlist-tracks .now').prev().length === 0) {
|
||||
return $('.playlist-tracks li').last().attr('id').split('i')[1];
|
||||
} else {
|
||||
return $('.playlist-tracks .now').prev().attr('id').split('i')[1];
|
||||
}
|
||||
} else if (cnt === 1) {
|
||||
return $('.playlist-tracks li').first().attr('id').split('i')[1];
|
||||
}
|
||||
return false;
|
||||
};
|
||||
Player.prototype.prevTrack = function() {
|
||||
var $li, cnt, rnd;
|
||||
cnt = $('.playlist-tracks li').length;
|
||||
if (!_player.onShuffle()) {
|
||||
if ($('.playlist-tracks .now').prev().length === 0) {
|
||||
return $('.playlist-tracks li').last().attr('id').split('i')[1];
|
||||
} else {
|
||||
while (true) {
|
||||
rnd = Math.floor(Math.random() * (cnt + .999));
|
||||
$li = $('.playlist-tracks li').eq(rnd);
|
||||
if ($li.length > 0 && !$li.hasClass('now')) {
|
||||
return $li.attr('id').split('i')[1];
|
||||
}
|
||||
return $('.playlist-tracks .now').prev().attr('id').split('i')[1];
|
||||
}
|
||||
} else if (cnt === 1) {
|
||||
return $('.playlist-tracks li').first().attr('id').split('i')[1];
|
||||
} else {
|
||||
while (true) {
|
||||
rnd = Math.floor(Math.random() * (cnt + .999));
|
||||
$li = $('.playlist-tracks li').eq(rnd);
|
||||
if ($li.length > 0 && !$li.hasClass('now')) {
|
||||
return $li.attr('id').split('i')[1];
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
Player.prototype.onShuffle = function() {
|
||||
return $('#shuffle').hasClass('active');
|
||||
};
|
||||
Player.prototype.onRepeat = function() {
|
||||
return $('#repeat').hasClass('active');
|
||||
};
|
||||
Player.prototype.updateNowListening = function(artist, album, track) {
|
||||
if (session.user.lastfm_username) {
|
||||
return session.query('/lastfm/listening?r=' + Math.random(), {
|
||||
artist: artist,
|
||||
album: album,
|
||||
track: track
|
||||
});
|
||||
}
|
||||
};
|
||||
Player.prototype.scrobble = function(artist, album, track) {
|
||||
if (session.user.lastfm_username) {
|
||||
return session.query('/lastfm/scrobble?r=' + Math.random(), {
|
||||
artist: artist,
|
||||
album: album,
|
||||
track: track
|
||||
});
|
||||
}
|
||||
};
|
||||
return Player;
|
||||
})();
|
||||
$(function() {
|
||||
return player.initJplayer();
|
||||
});
|
||||
$('#player .controls .prev').live('click', function() {
|
||||
Player.setTrack(Player.prevTrack());
|
||||
return false;
|
||||
});
|
||||
$('#player .controls .next').live('click', function() {
|
||||
Player.setTrack(Player.nextTrack(true));
|
||||
return false;
|
||||
});
|
||||
$('#player .play').live('click', function() {
|
||||
if ($('.playlist-tracks li').length > 0 && !Player.hasTrack()) {
|
||||
player.setTrack($('.playlist-tracks li').first().attr('id').split('i')[1]);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
$('#player .progress').live('click', function(e) {
|
||||
$('#jplayer').jPlayer('playHead', Math.round((e.offsetX / Player.bar_width) * 100));
|
||||
return false;
|
||||
});
|
||||
$('#repeat, #shuffle').live('click', function() {
|
||||
$(this).toggleClass('active');
|
||||
return false;
|
||||
});
|
||||
$('#empty-playlist').live('click', function() {
|
||||
if (confirm('Are you sure?')) {
|
||||
$('.playlist-tracks li').remove();
|
||||
$('#jplayer').jPlayer('clearMedia');
|
||||
$('#player .now-playing').text('Add some music to playlist');
|
||||
$('#player .loaded, #player .played').width(0);
|
||||
};
|
||||
Player.prototype.onShuffle = function() {
|
||||
return $('#shuffle').hasClass('active');
|
||||
};
|
||||
Player.prototype.onRepeat = function() {
|
||||
return $('#repeat').hasClass('active');
|
||||
};
|
||||
Player.prototype.updateNowListening = function(artist, album, track) {
|
||||
if (_session.getUser().lastfm_username) {
|
||||
return _session.query('/lastfm/listening?r=' + Math.random(), {
|
||||
artist: artist,
|
||||
album: album,
|
||||
track: track
|
||||
});
|
||||
}
|
||||
return false;
|
||||
});
|
||||
$('.playlist-tracks li .fade, .playlist-tracks li .duration, .playlist-tracks li .remove').live('mouseover mouseout', function(e) {
|
||||
if (e.type === 'mouseover') {
|
||||
$(this).parent().find('.duration').hide();
|
||||
$(this).parent().find('.remove').show();
|
||||
} else {
|
||||
$(this).parent().find('.remove').hide();
|
||||
$(this).parent().find('.duration').show();
|
||||
};
|
||||
Player.prototype.scrobble = function(artist, album, track) {
|
||||
if (_session.getUser().lastfm_username) {
|
||||
return _session.query('/lastfm/scrobble?r=' + Math.random(), {
|
||||
artist: artist,
|
||||
album: album,
|
||||
track: track
|
||||
});
|
||||
}
|
||||
return false;
|
||||
});
|
||||
$('.playlist-tracks li .remove').live('click', function() {
|
||||
var $li;
|
||||
$li = $(this).parent().parent();
|
||||
if ($li.hasClass('now')) {
|
||||
$('#jplayer').jPlayer('clearMedia');
|
||||
$('#player .now-playing').text('...');
|
||||
$('#player .loaded, #player .played').width(0);
|
||||
}
|
||||
$li.remove();
|
||||
return false;
|
||||
});
|
||||
$('.playlist-tracks li').live('dblclick', function() {
|
||||
player.setTrack($(this).attr('id').split('i')[1]);
|
||||
return false;
|
||||
});
|
||||
$('.add-album').live('click', function() {
|
||||
var album, artist, item, length, track_name, _i, _len, _ref;
|
||||
artist = $('.artist-info .name').html();
|
||||
album = $(this).parent().parent().parent().find('h2.name').text().replace(/\s\([\d]{4}\)$/, '');
|
||||
_ref = $(this).parent().parent().parent().find('.tracklist li');
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
item = _ref[_i];
|
||||
track_name = $(item).find('.trackname').html();
|
||||
length = $(item).find('.length').html();
|
||||
Player.addTrack(artist, album, track_name, length);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
$('.add-track').live('click', function() {
|
||||
var album, artist, length, track_name;
|
||||
artist = $('.artist-info .name').html();
|
||||
album = $(this).parent().parent().parent().parent().find('h2.name').text().replace(/\s\([\d]{4}\)$/, '');
|
||||
track_name = $(this).parent().find('.trackname').html();
|
||||
length = $(this).parent().find('.length').html();
|
||||
Player.addTrack(artist, album, track_name, length);
|
||||
return false;
|
||||
});
|
||||
$('.tracklist li').live('mouseover mouseout', function(e) {
|
||||
if (e.type === 'mouseover') {
|
||||
$(this).find('.add-track').show();
|
||||
} else {
|
||||
$(this).find('.add-track').hide();
|
||||
}
|
||||
return false;
|
||||
});
|
||||
$('.tracklist li').live('dblclick', function(e) {
|
||||
var album, artist, length, track_name;
|
||||
artist = $('.artist-info .name').html();
|
||||
album = $(this).parent().parent().parent().find('h2.name').text().replace(/\s\([\d]{4}\)$/, '');
|
||||
track_name = $(this).find('.trackname').html();
|
||||
length = $(this).find('.length').html();
|
||||
Player.addTrack(artist, album, track_name, length, true);
|
||||
return false;
|
||||
});
|
||||
}).call(this);
|
||||
};
|
||||
return Player;
|
||||
})();
|
||||
$('.player .controls .prev').live('click', function() {
|
||||
_player.setTrack(_player.prevTrack());
|
||||
return false;
|
||||
});
|
||||
$('.player .controls .next').live('click', function() {
|
||||
_player.setTrack(_player.nextTrack(true));
|
||||
return false;
|
||||
});
|
||||
$('.player .play').live('click', function() {
|
||||
if ($('.playlist-tracks li').length > 0 && !_player.hasTrack()) {
|
||||
_player.setTrack($('.playlist-tracks li').first().attr('id').split('i')[1]);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
$('.player .progress').live('click', function(e) {
|
||||
$('#jplayer').jPlayer('playHead', Math.round((e.offsetX / _player.bar_width) * 100));
|
||||
return false;
|
||||
});
|
||||
$('#repeat, #shuffle').live('click', function() {
|
||||
$(this).toggleClass('active');
|
||||
return false;
|
||||
});
|
||||
$('#empty-playlist').live('click', function() {
|
||||
if (confirm('Are you sure?')) {
|
||||
$('.playlist-tracks li').remove();
|
||||
$('#jplayer').jPlayer('clearMedia');
|
||||
$('.player .now-playing').text('Add some music to playlist');
|
||||
$('.player .loaded, .player .played').width(0);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
$('.playlist-tracks li .fade, .playlist-tracks li .duration, .playlist-tracks li .remove').live('mouseover mouseout', function(e) {
|
||||
if (e.type === 'mouseover') {
|
||||
$(this).parent().find('.duration').hide();
|
||||
$(this).parent().find('.remove').show();
|
||||
} else {
|
||||
$(this).parent().find('.remove').hide();
|
||||
$(this).parent().find('.duration').show();
|
||||
}
|
||||
return false;
|
||||
});
|
||||
$('.playlist-tracks li .remove').live('click', function() {
|
||||
var $li;
|
||||
$li = $(this).parent().parent();
|
||||
if ($li.hasClass('now')) {
|
||||
$('#jplayer').jPlayer('clearMedia');
|
||||
$('.player .now-playing').text('...');
|
||||
$('.player .loaded, .player .played').width(0);
|
||||
}
|
||||
$li.remove();
|
||||
return false;
|
||||
});
|
||||
$('.playlist-tracks li').live('dblclick', function() {
|
||||
_player.setTrack($(this).attr('id').split('i')[1]);
|
||||
return false;
|
||||
});
|
||||
$('.add-album').live('click', function() {
|
||||
var album, artist, item, length, track_name, _i, _len, _ref;
|
||||
artist = $('.artist-info .name').html();
|
||||
album = $(this).parent().parent().parent().find('h2.name').text().replace(/\s\([\d]{4}\)$/, '');
|
||||
_ref = $(this).parent().parent().parent().find('.tracklist li');
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
item = _ref[_i];
|
||||
track_name = $(item).find('.trackname').html();
|
||||
length = $(item).find('.length').html();
|
||||
_player.addTrack(artist, album, track_name, length);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
$('.add-track').live('click', function() {
|
||||
var album, artist, length, track_name;
|
||||
artist = $('.artist-info .name').html();
|
||||
album = $(this).parent().parent().parent().parent().find('h2.name').text().replace(/\s\([\d]{4}\)$/, '');
|
||||
track_name = $(this).parent().find('.trackname').html();
|
||||
length = $(this).parent().find('.length').html();
|
||||
_player.addTrack(artist, album, track_name, length);
|
||||
return false;
|
||||
});
|
||||
$('.tracklist li').live('mouseover mouseout', function(e) {
|
||||
if (e.type === 'mouseover') {
|
||||
$(this).find('.add-track').show();
|
||||
} else {
|
||||
$(this).find('.add-track').hide();
|
||||
}
|
||||
return false;
|
||||
});
|
||||
$('.tracklist li').live('dblclick', function(e) {
|
||||
var album, artist, length, track_name;
|
||||
artist = $('.artist-info .name').html();
|
||||
album = $(this).parent().parent().parent().find('h2.name').text().replace(/\s\([\d]{4}\)$/, '');
|
||||
track_name = $(this).find('.trackname').html();
|
||||
length = $(this).find('.length').html();
|
||||
_player.addTrack(artist, album, track_name, length, true);
|
||||
return false;
|
||||
});
|
|
@ -1,81 +1,73 @@
|
|||
/* DO NOT MODIFY. This file was compiled Mon, 27 Jun 2011 17:49:39 GMT from
|
||||
* /Users/chez/Sites/beathaven/app/coffeescripts/search.coffee
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var Search;
|
||||
Search = (function() {
|
||||
function Search() {}
|
||||
Search.prototype.pics = [];
|
||||
Search.prototype.showSpinner = function() {
|
||||
$('.search-container input').attr({
|
||||
disabled: 'disabled'
|
||||
}).blur();
|
||||
$('.search-container img').show();
|
||||
$('.autocomplete-container').hide();
|
||||
$('.artist_loading.failed').hide();
|
||||
this.hideSuggestions();
|
||||
return false;
|
||||
};
|
||||
Search.prototype.hideSpinner = function() {
|
||||
$('.search-container input').removeAttr('disabled');
|
||||
$('.search_field').focus();
|
||||
$('.search-container img').hide();
|
||||
return false;
|
||||
};
|
||||
Search.prototype.showSuggestions = function(values) {
|
||||
var item, _i, _len;
|
||||
for (_i = 0, _len = values.length; _i < _len; _i++) {
|
||||
item = values[_i];
|
||||
$('.suggestions ul').append('\
|
||||
var Search;
|
||||
Search = (function() {
|
||||
function Search() {}
|
||||
Search.prototype.pics = [];
|
||||
Search.prototype.showSpinner = function() {
|
||||
$('.search-container input').attr({
|
||||
disabled: 'disabled'
|
||||
}).blur();
|
||||
$('.search-container img').show();
|
||||
$('.autocomplete-container').hide();
|
||||
$('.artist_loading.failed').hide();
|
||||
this.hideSuggestions();
|
||||
return false;
|
||||
};
|
||||
Search.prototype.hideSpinner = function() {
|
||||
$('.search-container input').removeAttr('disabled');
|
||||
$('.search_field').focus();
|
||||
$('.search-container img').hide();
|
||||
return false;
|
||||
};
|
||||
Search.prototype.showSuggestions = function(values) {
|
||||
var item, _i, _len;
|
||||
for (_i = 0, _len = values.length; _i < _len; _i++) {
|
||||
item = values[_i];
|
||||
$('.suggestions ul').append('\
|
||||
<li>\
|
||||
<a class="data artist">' + item.name + '</a>\
|
||||
' + (item.desc ? '<br/><span>' + item.desc(+'</span>') : '') + '\
|
||||
' + (item.desc != null ? '<br/><span>' + item.desc + '</span>' : '') + '\
|
||||
</li>');
|
||||
}
|
||||
$('.suggestions').show();
|
||||
return false;
|
||||
};
|
||||
Search.prototype.hideSuggestions = function() {
|
||||
$('.suggestions ul li').remove();
|
||||
$('.suggestions').hide();
|
||||
return false;
|
||||
};
|
||||
Search.prototype.showArtistPics = function(pics) {
|
||||
var pic, _i, _len;
|
||||
$('.artist_loading.ok, .artist_pics').show();
|
||||
for (_i = 0, _len = pics.length; _i < _len; _i++) {
|
||||
pic = pics[_i];
|
||||
if (this.pics.indexOf(pic) === -1) {
|
||||
this.pics.push(pic);
|
||||
$('.artist_pics').append('\
|
||||
}
|
||||
$('.suggestions').show();
|
||||
return false;
|
||||
};
|
||||
Search.prototype.hideSuggestions = function() {
|
||||
$('.suggestions ul li').remove();
|
||||
$('.suggestions').hide();
|
||||
return false;
|
||||
};
|
||||
Search.prototype.showArtistPics = function(pics) {
|
||||
var pic, _i, _len;
|
||||
$('.artist_loading.ok, .artist_pics').show();
|
||||
for (_i = 0, _len = pics.length; _i < _len; _i++) {
|
||||
pic = pics[_i];
|
||||
if (this.pics.indexOf(pic) === -1) {
|
||||
this.pics.push(pic);
|
||||
$('.artist_pics').append('\
|
||||
<div class="pic">\
|
||||
<img src="' + pic + '" alt=""/>\
|
||||
</div>');
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
Search.prototype.showError = function() {
|
||||
$('.artist_loading.ok, .artist_pics').hide();
|
||||
$('.artist_loading.failed').show();
|
||||
return this.pics = [];
|
||||
};
|
||||
return Search;
|
||||
})();
|
||||
$(function() {
|
||||
$('.search').live('click', function() {
|
||||
ajax.loadSearchPage();
|
||||
return false;
|
||||
});
|
||||
$('#search_form').live('submit', function() {
|
||||
$('.autocomplete-container').remove();
|
||||
ajax.loadArtistData($('#search_field').val());
|
||||
return false;
|
||||
});
|
||||
return $('.suggestions a').live('click', function() {
|
||||
$('#search_field').val($(this).text());
|
||||
return false;
|
||||
});
|
||||
});
|
||||
}).call(this);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
Search.prototype.showError = function() {
|
||||
$('.artist_loading.ok, .artist_pics').hide();
|
||||
$('.artist_loading.failed').show();
|
||||
return this.pics = [];
|
||||
};
|
||||
return Search;
|
||||
})();
|
||||
$('.search').live('click', function() {
|
||||
_ajax.go('/search/');
|
||||
return false;
|
||||
});
|
||||
$('#search_form').live('submit', function() {
|
||||
$('.autocomplete-container').remove();
|
||||
_ajax.loadArtistData($('#search_field').val());
|
||||
return false;
|
||||
});
|
||||
$('.suggestions a').live('click', function() {
|
||||
$('#search_field').val($(this).text());
|
||||
return false;
|
||||
});
|
|
@ -1,34 +1,36 @@
|
|||
/* DO NOT MODIFY. This file was compiled Mon, 27 Jun 2011 17:49:39 GMT from
|
||||
* /Users/chez/Sites/beathaven/app/coffeescripts/session.coffee
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var Session;
|
||||
Session = (function() {
|
||||
Session.prototype.vk_params = null;
|
||||
Session.prototype.user = null;
|
||||
function Session(vk_params) {
|
||||
this.vk_params = vk_params;
|
||||
var Session;
|
||||
Session = (function() {
|
||||
Session.prototype.vk_params = null;
|
||||
Session.prototype.user = null;
|
||||
function Session(params) {
|
||||
var attrs, key, _i, _len, _params;
|
||||
attrs = ['expire', 'mid', 'secret', 'sid', 'sig'];
|
||||
_params = {};
|
||||
for (_i = 0, _len = attrs.length; _i < _len; _i++) {
|
||||
key = attrs[_i];
|
||||
if (params[key] != null) {
|
||||
_params[key] = params[key];
|
||||
}
|
||||
}
|
||||
Session.prototype.query = function(url, params, callback) {
|
||||
var attr, q_params, _i, _len;
|
||||
q_params = this.vk_params;
|
||||
for (_i = 0, _len = params.length; _i < _len; _i++) {
|
||||
attr = params[_i];
|
||||
q_params[attr] = params[attr];
|
||||
}
|
||||
$.post(url, q_params, callback);
|
||||
return false;
|
||||
};
|
||||
Session.prototype.setVkParams = function(params) {
|
||||
var attrs, key, _i, _len;
|
||||
attrs = ['expire', 'mid', 'secret', 'sid', 'sig'];
|
||||
for (_i = 0, _len = attrs.length; _i < _len; _i++) {
|
||||
key = attrs[_i];
|
||||
this.vk_params[key] = params[key];
|
||||
}
|
||||
return false;
|
||||
};
|
||||
return Session;
|
||||
})();
|
||||
}).call(this);
|
||||
this.vk_params = _params;
|
||||
false;
|
||||
}
|
||||
Session.prototype.setUser = function(user) {
|
||||
this.user = user;
|
||||
return false;
|
||||
};
|
||||
Session.prototype.getUser = function() {
|
||||
return this.user;
|
||||
};
|
||||
Session.prototype.query = function(url, params, callback) {
|
||||
var attr, q_params, _i, _len;
|
||||
q_params = this.vk_params;
|
||||
for (_i = 0, _len = params.length; _i < _len; _i++) {
|
||||
attr = params[_i];
|
||||
q_params[attr] = params[attr];
|
||||
}
|
||||
$.post(url, q_params, callback);
|
||||
return false;
|
||||
};
|
||||
return Session;
|
||||
})();
|
|
@ -1,54 +1,48 @@
|
|||
/* DO NOT MODIFY. This file was compiled Mon, 27 Jun 2011 14:00:02 GMT from
|
||||
* /Users/chez/Sites/beathaven/app/coffeescripts/settings.coffee
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var Settings;
|
||||
Settings = (function() {
|
||||
function Settings() {}
|
||||
Settings.prototype.getAccountInfo = function(callback) {
|
||||
return session.query('/user/update/', {}, callback);
|
||||
};
|
||||
Settings.prototype.saveAccountInfo = function(params, callback) {
|
||||
return session.query('/user/update', params, callback);
|
||||
};
|
||||
Settings.prototype.loadFormData = function(form) {
|
||||
if (form === 'account') {
|
||||
$('.settings-container .form input[name$="username"]').val(session.user.name);
|
||||
return $('.settings-container .form input[name$="email"]').val(session.email);
|
||||
} else if (form === 'lastfm') {
|
||||
if (this.user.lastfm_username) {
|
||||
return $('.form-container input[name$="username"]').first().val(session.lastfm_username);
|
||||
}
|
||||
var Settings;
|
||||
Settings = (function() {
|
||||
function Settings() {}
|
||||
Settings.prototype.getAccountInfo = function(callback) {
|
||||
return _session.query('/user/update/', {}, callback);
|
||||
};
|
||||
Settings.prototype.saveAccountInfo = function(params, callback) {
|
||||
return _session.query('/user/update', params, callback);
|
||||
};
|
||||
Settings.prototype.loadFormData = function(form) {
|
||||
if (form === 'account') {
|
||||
$('.settings-container .form input[name$="username"]').val(_session.getUser().name);
|
||||
return $('.settings-container .form input[name$="email"]').val(_session.getUser().email);
|
||||
} else if (form === 'lastfm') {
|
||||
if (_session.getUser().lastfm_username) {
|
||||
return $('.form-container input[name$="username"]').first().val(_session.getUser().lastfm_username);
|
||||
}
|
||||
}
|
||||
};
|
||||
return Settings;
|
||||
})();
|
||||
$('.settings').live('click', function() {
|
||||
return _ajax.go('/settings/');
|
||||
});
|
||||
$('.settings-container .tabs .tab').live('click', function() {
|
||||
if (!$(this).hasClass('active')) {
|
||||
$('.settings-container .tabs .tab').removeClass('active');
|
||||
$(this).addClass('active');
|
||||
$('.form-container').html($('.forms .' + $(this).attr('data-fieldset')).html());
|
||||
return _settings.loadFormData($(this).attr('data-fieldset'));
|
||||
}
|
||||
});
|
||||
$('.lastfm-connect').live('click', function() {
|
||||
return window.open(_session.getUser().lastfm_login_url);
|
||||
});
|
||||
$('.settings-container .form input').live('blur', function() {
|
||||
var active_tab, params;
|
||||
active_tab = $('.settings-container .tabs .tab.active').attr('data-fieldset');
|
||||
if (active_tab === 'account') {
|
||||
params = {
|
||||
username: $('.settings-container .form input[name$="username"]').first().val(),
|
||||
email: $('.settings-container .form input[name$="email"]').first().val()
|
||||
};
|
||||
return Settings;
|
||||
})();
|
||||
$('.settings').live('click', function() {
|
||||
return ajax.loadSettingsPage();
|
||||
});
|
||||
$('.settings-container .tabs .tab').live('click', function() {
|
||||
if ($(this).hasClass('active')) {
|
||||
$('.settings-container .tabs .tab').removeClass('active');
|
||||
$(this).addClass('active');
|
||||
$('.form-container').html($('.forms .' + $(this).attr('data-fieldset')).html());
|
||||
return settings.loadFormData($(this).attr('data-fieldset'));
|
||||
}
|
||||
});
|
||||
$('.lastfm-connect').live('click', function() {
|
||||
return window.open(session.user.lastfm_login_url);
|
||||
});
|
||||
$('.settings-container .form input').live('blur', function() {
|
||||
var active_tab, params;
|
||||
active_tab = $('.settings-container .tabs .tab.active').attr('data-fieldset');
|
||||
if (active_tab === 'account') {
|
||||
params = {
|
||||
username: $('.settings-container .form input[name$="username"]').first().val(),
|
||||
email: $('.settings-container .form input[name$="email"]').first().val()
|
||||
};
|
||||
return settings.saveAccountInfo(params, function() {
|
||||
return $('#header-container .hello .greating').text('Hi there, ' + (params.username.length > 0 ? params.username : '%username%') + '!');
|
||||
});
|
||||
}
|
||||
});
|
||||
}).call(this);
|
||||
return _settings.saveAccountInfo(params, function() {
|
||||
return $('#header-container .hello .greating').text('Hi there, ' + (params.username.length > 0 ? params.username : '%username%') + '!');
|
||||
});
|
||||
}
|
||||
});
|
|
@ -1,121 +1,127 @@
|
|||
/* DO NOT MODIFY. This file was compiled Mon, 27 Jun 2011 17:49:39 GMT from
|
||||
* /Users/chez/Sites/beathaven/app/coffeescripts/vkontakte.coffee
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var Vkontakte;
|
||||
Vkontakte = (function() {
|
||||
Vkontakte.prototype.qr = [];
|
||||
function Vkontakte(api_id) {
|
||||
this.api_id = api_id;
|
||||
}
|
||||
Vkontakte.prototype.init = function() {
|
||||
VK.init({
|
||||
apiId: this.api_id,
|
||||
nameTransportPath: '/xd_receiver.html'
|
||||
var Vkontakte;
|
||||
Vkontakte = (function() {
|
||||
Vkontakte.prototype.qr = null;
|
||||
function Vkontakte(api_id) {
|
||||
this.api_id = api_id;
|
||||
}
|
||||
Vkontakte.prototype.init = function() {
|
||||
this.qr = [];
|
||||
VK.init({
|
||||
apiId: this.api_id
|
||||
});
|
||||
return VK.Auth.getLoginStatus(this.authInfo);
|
||||
};
|
||||
Vkontakte.prototype.authInfo = function(response) {
|
||||
var _session;
|
||||
if (typeof response !== 'undefined' && response.session) {
|
||||
_session = new Session(response.session);
|
||||
$('#vk_login, .auth_notice').hide();
|
||||
$('#vk_logout').css({
|
||||
display: 'block'
|
||||
});
|
||||
return VK.Auth.getLoginStatus(this.authInfo);
|
||||
};
|
||||
Vkontakte.prototype.authInfo = function(response) {
|
||||
if (typeof response !== 'undefined' && response.session) {
|
||||
session.setVkParams(response.session);
|
||||
$('#vk_login, .auth_notice').hide();
|
||||
$('#vk_logout').css({
|
||||
display: 'block'
|
||||
});
|
||||
if ($('#search_field').length > 0) {
|
||||
$('#search_field').focus();
|
||||
}
|
||||
return session.query('/user/auth', {}, function(ar) {
|
||||
if (ar.newbie) {
|
||||
VK.Api.call('getVariable', {
|
||||
key: 1281
|
||||
}, function(r) {
|
||||
return Session.query('/user/update', {
|
||||
name: r.response
|
||||
}, function(ar2) {
|
||||
session.user = ar2.user;
|
||||
return $('#header-container .hello .greating').text('Hi there, ' + (session.user.name ? session.user.name : '%username%') + '!');
|
||||
});
|
||||
if ($('#search_field').length > 0) {
|
||||
$('#search_field').focus();
|
||||
}
|
||||
_session.query('/user/auth', {}, function(ar) {
|
||||
if (ar.newbie) {
|
||||
VK.Api.call('getVariable', {
|
||||
key: 1281
|
||||
}, function(r) {
|
||||
return _session.query('/user/update', {
|
||||
name: r.response
|
||||
}, function(ar2) {
|
||||
_session.setUser(ar2.user);
|
||||
return $('.header-container .hello .greating').text('Hi there, ' + (_session.getUser().name ? _session.getUser().name : '%username%') + '!');
|
||||
});
|
||||
} else {
|
||||
session.user = ar.user;
|
||||
}
|
||||
return $('#header-container .hello .greating').text('Hi there, ' + (session.user.name ? session.user.name : '%username%') + '!');
|
||||
});
|
||||
} else {
|
||||
$('#vk_login, .auth_notice').css({
|
||||
display: 'block'
|
||||
});
|
||||
return $('#vk_logout').hide();
|
||||
}
|
||||
};
|
||||
Vkontakte.prototype.loadTracksData = function(artist, track, duration, callback) {
|
||||
var query, track_prepared;
|
||||
track_prepared = track.replace(/\(.*\)/i, '').split('/')[0];
|
||||
query = artist(+' ' + track_prepared);
|
||||
if (this.qr[query] != null) {
|
||||
return callback(this.qr[query]);
|
||||
} else {
|
||||
return VK.Api.call('audio.search', {
|
||||
q: query
|
||||
}, function(r) {
|
||||
var url;
|
||||
url = this.matchPerfectResult(r.response, artist, track, duration);
|
||||
this.qr[query] = url;
|
||||
return callback(url);
|
||||
});
|
||||
}
|
||||
};
|
||||
Vkontakte.prototype.matchPerfectResult = function(data, artist, track, duration) {
|
||||
var best_result, best_score, delta, item, score, _i, _len;
|
||||
duration = duration.split(':');
|
||||
duration = parseInt(duration[0], 10) * 60 + parseInt(duration[1], 10);
|
||||
best_score = 0;
|
||||
best_result = null;
|
||||
for (_i = 0, _len = data.length; _i < _len; _i++) {
|
||||
item = data[_i];
|
||||
score = 0;
|
||||
item.artist = item.artist.trim();
|
||||
item.title = item.title.trim();
|
||||
if (item.artist === artist) {
|
||||
score += 10;
|
||||
} else if (item.artist.split(artist).length === 2) {
|
||||
score += 5;
|
||||
} else if (item.title.split(artist).length === 2) {
|
||||
score += 4;
|
||||
}
|
||||
if (item.title === track) {
|
||||
score += 10;
|
||||
} else if (item.title.split(track).length === 2) {
|
||||
score += 5;
|
||||
}
|
||||
if (parseInt(item.duration, 10) === duration) {
|
||||
score += 15;
|
||||
});
|
||||
} else {
|
||||
delta = Math.abs(parseInt(item.duration, 10) - duration);
|
||||
if (delta < 10) {
|
||||
score += 10 - delta;
|
||||
}
|
||||
_session.setUser(ar.user);
|
||||
}
|
||||
if (score > best_score) {
|
||||
best_score = score;
|
||||
best_result = item;
|
||||
}
|
||||
if (score === 35) {
|
||||
return best_result.url;
|
||||
return $('.header-container .hello .greating').text('Hi there, ' + (_session.getUser().name ? _session.getUser().name : '%username%') + '!');
|
||||
});
|
||||
} else {
|
||||
_session = new Session({});
|
||||
$('#vk_login, .auth_notice').css({
|
||||
display: 'block'
|
||||
});
|
||||
$('#vk_logout').hide();
|
||||
}
|
||||
return window._session = _session;
|
||||
};
|
||||
Vkontakte.prototype.loadTracksData = function(artist, track, duration, callback) {
|
||||
var query, track_prepared, url;
|
||||
track_prepared = track.replace(/\(.*\)/i, '').split('/')[0];
|
||||
query = artist + ' ' + track_prepared;
|
||||
if (url = _vkontakte.getQR(query)) {
|
||||
return callback(url);
|
||||
} else {
|
||||
return VK.Api.call('audio.search', {
|
||||
q: query
|
||||
}, function(r) {
|
||||
r.response.splice(0, 1);
|
||||
url = _vkontakte.matchPerfectResult(r.response, artist, track, duration);
|
||||
_vkontakte.addQR(query, url);
|
||||
return callback(url);
|
||||
});
|
||||
}
|
||||
};
|
||||
Vkontakte.prototype.matchPerfectResult = function(data, artist, track, duration) {
|
||||
var best_result, best_score, delta, item, score, _i, _len;
|
||||
duration = duration.split(':');
|
||||
duration = parseInt(duration[0], 10) * 60 + parseInt(duration[1], 10);
|
||||
best_score = 0;
|
||||
best_result = null;
|
||||
for (_i = 0, _len = data.length; _i < _len; _i++) {
|
||||
item = data[_i];
|
||||
score = 0;
|
||||
item.artist = item.artist.trim();
|
||||
item.title = item.title.trim();
|
||||
if (item.artist === artist) {
|
||||
score += 10;
|
||||
} else if (item.artist.split(artist).length === 2) {
|
||||
score += 5;
|
||||
} else if (item.title.split(artist).length === 2) {
|
||||
score += 4;
|
||||
}
|
||||
if (item.title === track) {
|
||||
score += 10;
|
||||
} else if (item.title.split(track).length === 2) {
|
||||
score += 5;
|
||||
}
|
||||
if (parseInt(item.duration, 10) === duration) {
|
||||
score += 15;
|
||||
} else {
|
||||
delta = Math.abs(parseInt(item.duration, 10) - duration);
|
||||
if (delta < 10) {
|
||||
score += 10 - delta;
|
||||
}
|
||||
}
|
||||
return best_result.url;
|
||||
};
|
||||
return Vkontakte;
|
||||
})();
|
||||
$(function() {
|
||||
$('#vk_login').click(function() {
|
||||
return VK.Auth.login(vkontakte.authInfo, 8);
|
||||
});
|
||||
return $('#vk_logout').click(function() {
|
||||
return VK.Auth.logout(vkontakte.authInfo);
|
||||
});
|
||||
if (score > best_score) {
|
||||
best_score = score;
|
||||
best_result = item;
|
||||
}
|
||||
if (score === 35) {
|
||||
return best_result.url;
|
||||
}
|
||||
}
|
||||
return best_result.url;
|
||||
};
|
||||
Vkontakte.prototype.addQR = function(query, url) {
|
||||
return this.qr[query] = url;
|
||||
};
|
||||
Vkontakte.prototype.getQR = function(query) {
|
||||
if (this.qr[query] != null) {
|
||||
this.qr[query];
|
||||
}
|
||||
return false;
|
||||
};
|
||||
return Vkontakte;
|
||||
})();
|
||||
$(function() {
|
||||
$('#vk_login').click(function() {
|
||||
return VK.Auth.login(_vkontakte.authInfo(), 8);
|
||||
});
|
||||
}).call(this);
|
||||
return $('#vk_logout').click(function() {
|
||||
return VK.Auth.logout(_vkontakte.authInfo());
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue