CoffeeScript integrated. Debugging
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
class Ajax
|
||||
|
||||
referer: false
|
||||
|
||||
loadArtistData: (name) ->
|
||||
search.showSpinner()
|
||||
name = name.split(' ').join('+')
|
||||
$.get '/artist/' +name+ '/', (data) ->
|
||||
if data.status?
|
||||
if data.status is 'loading'
|
||||
search.showArtistPics data.pics
|
||||
setTimeout () ->
|
||||
this.loadArtistData name
|
||||
, 3000
|
||||
else if data.status is 'corrected'
|
||||
ajax.loadArtistData data.page
|
||||
else if data.status is 'suggestions'
|
||||
search.hideSpinner()
|
||||
search.showSuggestions data.values
|
||||
else if data.status == 'loading_failed'
|
||||
search.hideSpinner()
|
||||
search.showError()
|
||||
else
|
||||
this.setArchor '/artist/' +name+ '/'
|
||||
pages.renderArtist data
|
||||
beathaven.redrawScrollbar()
|
||||
|
||||
loadSearchPage: ->
|
||||
$.get '/templates/search.html', (data) ->
|
||||
this.setArchor '/search/'
|
||||
pages.renderSearch data
|
||||
|
||||
loadSettingsPage: ->
|
||||
$.get '/templates/settings.html', (data) ->
|
||||
this.setArchor '/settings/'
|
||||
pages.renderSettings data
|
||||
|
||||
load404Page: ->
|
||||
$.get '/404.html', (data) ->
|
||||
$('.data-container .inner').html data
|
||||
beathaven.redrawScrollbar()
|
||||
|
||||
setArchor: (anchor) ->
|
||||
@referer = this.getAnchor()
|
||||
window.location.hash = '#' +anchor
|
||||
|
||||
getAnchor: () ->
|
||||
window.location.hash.substring 1;
|
||||
|
||||
setTitle: (title) ->
|
||||
document.title = title+ ' @ BeatHaven'
|
||||
|
||||
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()
|
||||
else
|
||||
this.load404Page()
|
||||
|
||||
|
||||
$ ->
|
||||
window.ajax = new Ajax()
|
||||
$('a.data.artist').live 'click', ->
|
||||
ajax.loadArtistData $(this).html()
|
||||
false
|
||||
$(window).bind 'hashchange', ->
|
||||
ajax.detectPage()
|
||||
@@ -0,0 +1,76 @@
|
||||
$ ->
|
||||
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()
|
||||
|
||||
$(window).resize ->
|
||||
beathaven.adjustSizes()
|
||||
window.setTimeout ->
|
||||
beathaven.checkRedrawScrollbar()
|
||||
, 500
|
||||
|
||||
class BeatHaven
|
||||
|
||||
last_height: false
|
||||
|
||||
init: ->
|
||||
this.drawInterface()
|
||||
this.adjustSizes()
|
||||
ajax.detectPage()
|
||||
|
||||
adjustSizes: ->
|
||||
$('.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()
|
||||
$('.playlist').scrollbar()
|
||||
|
||||
checkRedrawScrollbar: ->
|
||||
focused_id = false
|
||||
if document.activeElement.id?
|
||||
focused_id = document.activeElement.id;
|
||||
outer_height = $('.data-container > div').outerHeight()
|
||||
if outer_height > 300 and outer_height != @last_height
|
||||
@last_height = outer_height
|
||||
this.redrawScrollbar()
|
||||
if focused_id
|
||||
document.getElementById(focused_id).focus()
|
||||
focused_id = false
|
||||
window.setTimeout ->
|
||||
beathaven.checkRedrawScrollbar()
|
||||
, 500
|
||||
|
||||
redrawScrollbar: ->
|
||||
$('.data-container').html $('.data-container').find('.inner').first()
|
||||
$('.data-container').scrollbar()
|
||||
|
||||
|
||||
String::htmlsafe = ->
|
||||
replaces = [
|
||||
["\\", "\\\\"]
|
||||
["\"", """]
|
||||
["<", "<"]
|
||||
[">", ">"]
|
||||
]
|
||||
str = this
|
||||
for item in replaces
|
||||
str = str.replace item[0], item[1]
|
||||
str
|
||||
|
||||
String::trim = ->
|
||||
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)
|
||||
str
|
||||
@@ -0,0 +1,88 @@
|
||||
class Pages
|
||||
|
||||
renderArtist: (data) ->
|
||||
artist_info = $ '
|
||||
<div class="artist-info">
|
||||
<div class="pic">
|
||||
<img src="' +data.artist.pic+ '" alt="' +data.artist.name+ '" width="250" />
|
||||
</div>
|
||||
<h1 class="name">' +data.artist.name+ '</h1>
|
||||
<div class="info">
|
||||
' +data.artist.desc+ '
|
||||
</div>
|
||||
</div>'
|
||||
|
||||
albums_info = $ '<div class="albums"></div>'
|
||||
$.each data.albums, (i, album) ->
|
||||
if album.year?
|
||||
album_info = $ '
|
||||
<div class="album">
|
||||
<h2 class="name">' +album.name+ ' (' +album.year+ ')</h2>
|
||||
<div class="pic">
|
||||
<img src="' +(if album.pic then album.pic else '/images/kitteh.png')+ '" alt="' +album.name+ ' by ' +data.artist.name+ '" width="250" height="250"/>
|
||||
<div class="add-album-button-container">
|
||||
<div class="add-album button gray">Add to Now Playing</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tracklist"><ul></ul></div>
|
||||
</div>
|
||||
<div class="kaboom"></div>'
|
||||
|
||||
$.each album.tracks.album, (i, track) ->
|
||||
track_info = $ '
|
||||
<li>
|
||||
<div class="add-track button gray">+</div>
|
||||
<div class="track-container">
|
||||
<div class="fade"></div>
|
||||
<span class="index">' +(i+1)+ '</span>
|
||||
<div class="trackname" title="' +track.name.htmlsafe()+ '">' +track.name+ '</div>
|
||||
<div class="length">' +track.duration+ '</div>
|
||||
</div>
|
||||
</li>'
|
||||
|
||||
$(album_info).find('.tracklist ul').append(track_info)
|
||||
|
||||
$(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
|
||||
|
||||
renderSearch: (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 ->
|
||||
$('#search_field').bh_autocomplete
|
||||
serviceUrl: '/artist/autocomplete' # Страница для обработки запросов автозаполнения
|
||||
minChars: 2 # Минимальная длина запроса для срабатывания автозаполнения
|
||||
delimiter: /(,|;)\s*/ # Разделитель для нескольких запросов, символ или регулярное выражение
|
||||
maxHeight: 400 # Максимальная высота списка подсказок, в пикселях
|
||||
width: 415 # Ширина списка
|
||||
zIndex: 9999 # z-index списка
|
||||
deferRequestBy: 500 # Задержка запроса (мсек)
|
||||
onSelect: ->
|
||||
ajax.loadArtistData()
|
||||
$('#search_field').focus()
|
||||
, 501
|
||||
|
||||
yaCounter7596904.hit ajax.getAnchor(), 'Artist Search', ajax.referer
|
||||
ajax.setTitle 'Artist Search'
|
||||
|
||||
renderSettings: (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'
|
||||
|
||||
$ ->
|
||||
window.pages = new Pages()
|
||||
false
|
||||
@@ -0,0 +1,245 @@
|
||||
class Player
|
||||
|
||||
bar_width: 330
|
||||
jp: null
|
||||
scrobbled: false
|
||||
|
||||
initJplayer: ->
|
||||
self = this
|
||||
|
||||
@jp = $("#jplayer")
|
||||
@jp.jPlayer
|
||||
swfPath: "/js"
|
||||
supplied: "mp3"
|
||||
cssSelectorAncestor: ""
|
||||
cssSelector:
|
||||
play: "#player .play"
|
||||
pause: "#player .pause"
|
||||
stop: ""
|
||||
videoPlay: ""
|
||||
seekBar: ""
|
||||
playBar: ""
|
||||
mute: ""
|
||||
unmute: ""
|
||||
volumeBar: ""
|
||||
volumeBarValue: ""
|
||||
currentTime: ""
|
||||
duration: ""
|
||||
|
||||
@jp.bind $.jPlayer.event.timeupdate, (e) ->
|
||||
data = e.jPlayer.status
|
||||
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)
|
||||
|
||||
@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
|
||||
$('.playlist-tracks li').removeClass 'now'
|
||||
else
|
||||
self.setTrack next
|
||||
false
|
||||
|
||||
addTrack: (artist, album, track, length, autoplay) ->
|
||||
if not autoplay?
|
||||
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="duration">' +length+ '</span>
|
||||
<div class="remove">remove</div>
|
||||
</div>
|
||||
</li>'
|
||||
|
||||
$('#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])
|
||||
|
||||
setTrack: (id) ->
|
||||
$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'), ->
|
||||
player.playSource()
|
||||
this.updateNowListening $obj.attr('data-artist'), $obj.attr('data-album'), $obj.attr('data-track')
|
||||
|
||||
hasTrack: ->
|
||||
if $('#jplayer audio').length > 0
|
||||
return $('#jplayer audio').attr('src')?
|
||||
else if $('#jplayer object').length > 0
|
||||
$('#jplayer').jPlayer 'play'
|
||||
true
|
||||
false
|
||||
|
||||
playSource: (url) ->
|
||||
$('#jplayer').jPlayer 'setMedia', mp3: url
|
||||
$('#jplayer').jPlayer 'play'
|
||||
@scrobbled = false
|
||||
|
||||
nextTrack: (manual) ->
|
||||
manual = manual?
|
||||
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
|
||||
return $('.playlist-tracks li').first().attr('id').split('i')[1]
|
||||
else
|
||||
false
|
||||
else
|
||||
return $('.playlist-tracks .now').next().attr('id').split('i')[1]
|
||||
else if cnt == 1 # Single track in the playlist
|
||||
return $('.playlist-tracks li').first().attr('id').split('i')[1]
|
||||
else # Shuffle on
|
||||
while true
|
||||
rnd = Math.floor(Math.random() * (cnt + .999))
|
||||
$li = $('.playlist-tracks li').eq rnd
|
||||
if $li.length > 0 and not $li.hasClass 'now'
|
||||
return $li.attr('id').split('i')[1]
|
||||
false
|
||||
|
||||
prevTrack: ->
|
||||
cnt = $('.playlist-tracks li').length
|
||||
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
|
||||
return $('.playlist-tracks .now').prev().attr('id').split('i')[1]
|
||||
else if cnt == 1 # Single track in the playlist
|
||||
return $('.playlist-tracks li').first().attr('id').split('i')[1]
|
||||
else # Shuffle on
|
||||
while true
|
||||
rnd = Math.floor(Math.random() * (cnt + .999))
|
||||
$li = $('.playlist-tracks li').eq rnd
|
||||
if $li.length > 0 and not $li.hasClass 'now'
|
||||
return $li.attr('id').split('i')[1]
|
||||
false
|
||||
|
||||
onShuffle: ->
|
||||
return $('#shuffle').hasClass 'active'
|
||||
|
||||
onRepeat: ->
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
|
||||
# Player Controls
|
||||
|
||||
$('#player .controls .prev').live 'click', ->
|
||||
Player.setTrack Player.prevTrack()
|
||||
false
|
||||
|
||||
$('#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]
|
||||
false
|
||||
|
||||
$('#player .progress').live 'click', (e) ->
|
||||
$('#jplayer').jPlayer 'playHead', Math.round((e.offsetX / Player.bar_width) * 100)
|
||||
false
|
||||
|
||||
# Player Additional Controls
|
||||
|
||||
$('#repeat, #shuffle').live 'click', ->
|
||||
$(this).toggleClass 'active'
|
||||
false
|
||||
|
||||
$('#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
|
||||
false
|
||||
|
||||
# Playlist Actions
|
||||
|
||||
$('.playlist-tracks li .fade, .playlist-tracks li .duration, .playlist-tracks li .remove').live 'mouseover mouseout', (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()
|
||||
false
|
||||
|
||||
$('.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
|
||||
$li.remove()
|
||||
false
|
||||
|
||||
$('.playlist-tracks li').live 'dblclick', ->
|
||||
player.setTrack $(this).attr('id').split('i')[1]
|
||||
false
|
||||
|
||||
# Adding To Playlist actions
|
||||
|
||||
$('.add-album').live 'click', ->
|
||||
artist = $('.artist-info .name').html()
|
||||
album = $(this).parent().parent().parent().find('h2.name').text().replace /\s\([\d]{4}\)$/, ''
|
||||
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
|
||||
false
|
||||
|
||||
$('.add-track').live 'click', ->
|
||||
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
|
||||
false
|
||||
|
||||
$('.tracklist li').live 'mouseover mouseout', (e) ->
|
||||
if e.type == 'mouseover'
|
||||
$(this).find('.add-track').show()
|
||||
else
|
||||
$(this).find('.add-track').hide()
|
||||
false
|
||||
|
||||
$('.tracklist li').live 'dblclick', (e) ->
|
||||
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
|
||||
false
|
||||
@@ -0,0 +1,64 @@
|
||||
class Search
|
||||
|
||||
pics: []
|
||||
|
||||
showSpinner: ->
|
||||
$('.search-container input').attr(disabled: 'disabled').blur()
|
||||
$('.search-container img').show()
|
||||
$('.autocomplete-container').hide()
|
||||
$('.artist_loading.failed').hide()
|
||||
this.hideSuggestions()
|
||||
false
|
||||
|
||||
hideSpinner: ->
|
||||
$('.search-container input').removeAttr 'disabled'
|
||||
$('.search_field').focus()
|
||||
$('.search-container img').hide()
|
||||
false
|
||||
|
||||
showSuggestions: (values) ->
|
||||
for item in values
|
||||
$('.suggestions ul').append '
|
||||
<li>
|
||||
<a class="data artist">' +item.name+ '</a>
|
||||
' +(if item.desc then '<br/><span>'+ item.desc +'</span>' else '')+ '
|
||||
</li>'
|
||||
$('.suggestions').show()
|
||||
false
|
||||
|
||||
hideSuggestions: ->
|
||||
$('.suggestions ul li').remove()
|
||||
$('.suggestions').hide()
|
||||
false
|
||||
|
||||
showArtistPics: (pics) ->
|
||||
$('.artist_loading.ok, .artist_pics').show()
|
||||
for pic in pics
|
||||
if @pics.indexOf(pic) == -1
|
||||
@pics.push(pic);
|
||||
$('.artist_pics').append '
|
||||
<div class="pic">
|
||||
<img src="' +pic+ '" alt=""/>
|
||||
</div>'
|
||||
false
|
||||
|
||||
showError: ->
|
||||
$('.artist_loading.ok, .artist_pics').hide()
|
||||
$('.artist_loading.failed').show()
|
||||
@pics = []
|
||||
|
||||
|
||||
$ ->
|
||||
window.search = new Search()
|
||||
false
|
||||
|
||||
$('.search').live 'click', ->
|
||||
ajax.loadSearchPage()
|
||||
false
|
||||
$('#search_form').live 'submit', ->
|
||||
$('.autocomplete-container').remove()
|
||||
ajax.loadArtistData $('#search_field').val()
|
||||
false
|
||||
$('.suggestions a').live 'click', ->
|
||||
$('#search_field').val $(this).text()
|
||||
false
|
||||
@@ -0,0 +1,23 @@
|
||||
class Session
|
||||
|
||||
vk_params: null
|
||||
user: null
|
||||
|
||||
constructor: (@vk_params) ->
|
||||
|
||||
query: (url, params, callback) ->
|
||||
q_params = @vk_params
|
||||
for attr in params
|
||||
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
|
||||
@@ -0,0 +1,41 @@
|
||||
class Settings
|
||||
|
||||
getAccountInfo: (callback) ->
|
||||
session.query '/user/update/', {}, callback
|
||||
|
||||
saveAccountInfo: (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
|
||||
else if form == 'lastfm'
|
||||
if @user.lastfm_username
|
||||
$('.form-container input[name$="username"]').first().val session.lastfm_username
|
||||
|
||||
$ ->
|
||||
window.settings = new Settings()
|
||||
false
|
||||
|
||||
$('.settings') .live 'click', ->
|
||||
ajax.loadSettingsPage();
|
||||
|
||||
$('.settings-container .tabs .tab').live 'click', ->
|
||||
if $(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'
|
||||
|
||||
$('.lastfm-connect') .live 'click', ->
|
||||
window.open session.user.lastfm_login_url
|
||||
|
||||
$('.settings-container .form input').live 'blur', ->
|
||||
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()
|
||||
settings.saveAccountInfo params, ->
|
||||
$('#header-container .hello .greating').text 'Hi there, ' +(if params.username.length > 0 then params.username else '%username%')+ '!'
|
||||
@@ -0,0 +1,92 @@
|
||||
class Vkontakte
|
||||
|
||||
qr: []
|
||||
|
||||
constructor: (@api_id) ->
|
||||
|
||||
init: ->
|
||||
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
|
||||
|
||||
$('#vk_login, .auth_notice').hide()
|
||||
$('#vk_logout').css display: 'block'
|
||||
|
||||
$('#search_field').focus() if $('#search_field').length > 0
|
||||
|
||||
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%')+ '!'
|
||||
else
|
||||
session.user = ar.user
|
||||
|
||||
$('#header-container .hello .greating')
|
||||
.text 'Hi there, ' +( if session.user.name then session.user.name else '%username%')+ '!'
|
||||
else
|
||||
$('#vk_login, .auth_notice').css display: 'block'
|
||||
$('#vk_logout').hide()
|
||||
|
||||
loadTracksData: (artist, track, duration, callback) ->
|
||||
track_prepared = track.replace(/\(.*\)/i, '').split('/')[0];
|
||||
query = artist +' '+ track_prepared;
|
||||
if @qr[query]?
|
||||
callback @qr[query]
|
||||
else
|
||||
VK.Api.call 'audio.search', q: query, (r) ->
|
||||
url = this.matchPerfectResult r.response, artist, track, duration
|
||||
@qr[query] = url;
|
||||
callback url
|
||||
|
||||
matchPerfectResult: (data, artist, track, duration) ->
|
||||
duration = duration.split ':'
|
||||
|
||||
duration = parseInt(duration[0], 10) * 60 + parseInt(duration[1], 10)
|
||||
best_score = 0;
|
||||
best_result = null;
|
||||
for item in data
|
||||
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 is 2
|
||||
score += 5
|
||||
else if item.title.split(artist).length is 2
|
||||
score += 4
|
||||
|
||||
if item.title == track
|
||||
score += 10
|
||||
else if item.title.split(track).length is 2
|
||||
score += 5
|
||||
|
||||
if parseInt(item.duration, 10) == duration
|
||||
score += 15
|
||||
else
|
||||
delta = Math.abs parseInt(item.duration, 10) - duration
|
||||
score += (10 - delta) if delta < 10
|
||||
|
||||
if score > best_score
|
||||
best_score = score
|
||||
best_result = item
|
||||
|
||||
if score is 35
|
||||
return best_result.url
|
||||
|
||||
return best_result.url
|
||||
|
||||
$ ->
|
||||
$('#vk_login').click ->
|
||||
VK.Auth.login vkontakte.authInfo, 8
|
||||
$('#vk_logout').click ->
|
||||
VK.Auth.logout vkontakte.authInfo
|
||||
Reference in New Issue
Block a user