Project folder cleanup
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
var Ajax = {
|
||||
|
||||
referer: false,
|
||||
|
||||
loadArtistData: function(name) {
|
||||
Search.showSpinner();
|
||||
name = name.split(' ').join('+');
|
||||
$.get('/artist/'+ name +'/', function(data){
|
||||
if (typeof data.status != 'undefined') {
|
||||
if (data.status == 'loading') {
|
||||
Search.showArtistPics(data.pics);
|
||||
setTimeout(function() {
|
||||
Ajax.loadArtistData(name);
|
||||
}, 3000);
|
||||
} else if (data.status == 'corrected') {
|
||||
Ajax.loadArtistData(data.page);
|
||||
} else if (data.status == 'suggestions') {
|
||||
Search.hideSpinner();
|
||||
Search.showSuggestions(data.values);
|
||||
} else if (data.status == 'error') {
|
||||
Ajax.load404Page();
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
Ajax.setArchor('/artist/'+ name +'/');
|
||||
Pages.renderArtist(data);
|
||||
beathaven.redrawScrollbar();
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
loadSearchPage: function() {
|
||||
$.get('/search.html', function(data){
|
||||
Ajax.setArchor('/search/');
|
||||
Pages.renderSearch(data);
|
||||
})
|
||||
},
|
||||
|
||||
loadSettingsPage: function() {
|
||||
$.get('/settings.html', function(data){
|
||||
Ajax.setArchor('/settings/');
|
||||
Pages.renderSettings(data);
|
||||
})
|
||||
},
|
||||
|
||||
loadWheePage: function() {
|
||||
$.get('/demo/whee.html', function(data){
|
||||
$('#data-container .inner').html(data);
|
||||
})
|
||||
},
|
||||
|
||||
load404Page: function() {
|
||||
$.get('/demo/404.html', function(data){
|
||||
$('#data-container .inner').html(data);
|
||||
beathaven.redrawScrollbar();
|
||||
})
|
||||
},
|
||||
|
||||
setArchor: function(anchor) {
|
||||
Ajax.referer = Ajax.getAnchor();
|
||||
window.location.hash = '#'+ anchor;
|
||||
},
|
||||
|
||||
getAnchor: function() {
|
||||
return window.location.hash.substring(1);
|
||||
},
|
||||
|
||||
setTitle: function(title) {
|
||||
document.title = title +' @ BeatHaven';
|
||||
},
|
||||
|
||||
detectPage: function() {
|
||||
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.load404Page();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$(function(){
|
||||
$('a.data.artist').live('click', function(){
|
||||
Ajax.loadArtistData($(this).html());
|
||||
return false;
|
||||
});
|
||||
//$(window).bind('hashchange', Ajax.detectPage);
|
||||
})
|
||||
@@ -0,0 +1,113 @@
|
||||
var Audio = {
|
||||
|
||||
audio: null,
|
||||
|
||||
tid: null,
|
||||
tinterval: 300,
|
||||
ttime: 0,
|
||||
|
||||
play: function() {
|
||||
try {
|
||||
this.audio.play();
|
||||
} catch(e) {}
|
||||
},
|
||||
|
||||
pause: function() {
|
||||
try {
|
||||
this.audio.pause();
|
||||
} catch(e) {}
|
||||
},
|
||||
|
||||
rewind: function() {
|
||||
try {
|
||||
this.audio.currentTime = 0;
|
||||
} catch(e) {}
|
||||
},
|
||||
|
||||
addTrack: function(id, url) {
|
||||
if ($('#a'+ id).length == 0) {
|
||||
$('#audiobox').html('<audio id="a'+ id +'" src="'+ url +'"></audio>')
|
||||
}
|
||||
},
|
||||
|
||||
setTrack: function(id) {
|
||||
this.audio = document.getElementById('a'+ id);
|
||||
$(this.audio).bind('play',function() {
|
||||
$('#player .controls .play').hide();
|
||||
$('#player .controls .pause').show();
|
||||
}).bind('pause ended', function() {
|
||||
$('#player .controls .pause').hide();
|
||||
$('#player .controls .play').show();
|
||||
});
|
||||
this.ttime = 0;
|
||||
},
|
||||
|
||||
getLoadedPercent: function() {
|
||||
try {
|
||||
return Audio.audio.buffered.end(0) / Audio.audio.duration;
|
||||
} catch(e) {}
|
||||
return 0;
|
||||
},
|
||||
|
||||
getPlayedPercent: function() {
|
||||
try {
|
||||
return Audio.audio.currentTime / Audio.audio.duration;
|
||||
} catch(e) {}
|
||||
return 0;
|
||||
},
|
||||
|
||||
getListenedPercent: function() {
|
||||
try {
|
||||
if (Audio.audio.duration < 30 || Audio.ttime < 0) {
|
||||
return -1;
|
||||
}
|
||||
return Audio.ttime / 1000 / Audio.audio.duration;
|
||||
} catch(e) {}
|
||||
return -1;
|
||||
},
|
||||
|
||||
setPlayedPercent: function(val) {
|
||||
if (typeof(this.audio.duration) != undefined) {
|
||||
this.audio.currentTime = Math.round(val * this.audio.duration / 100);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
skipToPercent: function(val) {
|
||||
try {
|
||||
this.audio.currentTime = this.audio.duration * val;
|
||||
} catch(e) {}
|
||||
},
|
||||
|
||||
startListener: function() {
|
||||
Audio.killListener();
|
||||
Audio.tid = window.setTimeout(Audio.startListener, Audio.tinterval);
|
||||
if (Audio.ttime !== -1) {
|
||||
Audio.ttime += Audio.tinterval;
|
||||
}
|
||||
Player.updateUI(
|
||||
Audio.getLoadedPercent(),
|
||||
Audio.getPlayedPercent(),
|
||||
Audio.getListenedPercent()
|
||||
);
|
||||
var pp = Audio.getPlayedPercent();
|
||||
if (pp > 0.5) {
|
||||
Audio.ttime = -1;
|
||||
}
|
||||
},
|
||||
|
||||
killListener: function() {
|
||||
try {
|
||||
window.clearTimeout(Audio.tid);
|
||||
} catch(e) {}
|
||||
}
|
||||
}
|
||||
|
||||
$('#player .controls .play').live('click', function(){
|
||||
Audio.play();
|
||||
});
|
||||
|
||||
$('#player .controls .pause').live('click', function(){
|
||||
Audio.pause();
|
||||
});
|
||||
@@ -0,0 +1,50 @@
|
||||
$(function(){
|
||||
if (document.location.host != 'beathaven.org' && document.location.host != 'localhost') {
|
||||
document.location.href = 'http://beathaven.org/'+ document.location.hash;
|
||||
}
|
||||
beathaven.init();
|
||||
$(window).resize(beathaven.adjustSizes)
|
||||
window.setTimeout(beathaven.checkRedrawScrollbar, 500);
|
||||
})
|
||||
var beathaven = {
|
||||
|
||||
last_height: false,
|
||||
|
||||
init: function () {
|
||||
this.drawInterface();
|
||||
this.adjustSizes();
|
||||
Ajax.detectPage();
|
||||
},
|
||||
|
||||
drawInterface: function() {
|
||||
},
|
||||
|
||||
adjustSizes: function() {
|
||||
$('#data-container').height($(window).height() - $('#header-container').height());
|
||||
$('#data-container').width($(window).width() - $('#player').width()).scrollbar();
|
||||
$('#player-container').height($(window).height());
|
||||
$('#playlist').height($(window).height() - $('#player').height()).scrollbar();
|
||||
},
|
||||
|
||||
checkRedrawScrollbar: function() {
|
||||
var focused_id = false;
|
||||
if (typeof document.activeElement.id !== 'undefined') {
|
||||
focused_id = document.activeElement.id;
|
||||
}
|
||||
var outer_height = $('#data-container > div').outerHeight();
|
||||
if (outer_height > 300 && outer_height != beathaven.last_height) {
|
||||
beathaven.last_height = outer_height;
|
||||
beathaven.redrawScrollbar();
|
||||
}
|
||||
if (focused_id) {
|
||||
document.getElementById(focused_id).focus();
|
||||
focused_id = false;
|
||||
}
|
||||
window.setTimeout(beathaven.checkRedrawScrollbar, 500);
|
||||
},
|
||||
|
||||
redrawScrollbar: function() {
|
||||
$('#data-container').html($('#data-container').find('.inner').first());
|
||||
$('#data-container').scrollbar();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
var Pages = {
|
||||
|
||||
renderArtist: function(data){
|
||||
var 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>\
|
||||
');
|
||||
|
||||
var albums_info = $('<div class="albums"></div>');
|
||||
$.each(data.albums, function(i, album){
|
||||
if (album.year != null) {
|
||||
var album_info = $('\
|
||||
<div class="album">\
|
||||
<h2 class="name">'+ album.name +' ('+ album.year +')</h2>\
|
||||
<div class="pic">\
|
||||
<img src="'+ (album.pic ? album.pic : '/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, function(i, track){
|
||||
var track_info = $('\
|
||||
<li>\
|
||||
<div class="add-track button gray">+</div>\
|
||||
<div class="track-container">\
|
||||
<span class="index">'+ (i+1) +'</span>\
|
||||
<div class="trackname">'+ 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: 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, // z-index списка
|
||||
deferRequestBy: 500, // Задержка запроса (мсек)
|
||||
onSelect: Ajax.loadArtistData
|
||||
});
|
||||
$('#search_field').focus();
|
||||
}, 501)
|
||||
|
||||
yaCounter7596904.hit(Ajax.getAnchor(), 'Artist Search', Ajax.referer);
|
||||
Ajax.setTitle('Artist Search');
|
||||
},
|
||||
|
||||
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');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
var Player = {
|
||||
|
||||
bar_width: 330,
|
||||
|
||||
getTrackUrl: function(data) {
|
||||
|
||||
},
|
||||
|
||||
addTrack: function(artist, track, length) {
|
||||
$('.playlist-tracks').append('\
|
||||
<li id="i'+ Math.round(Math.random() * 999999) +'">\
|
||||
<div class="item">\
|
||||
<div class="fade"></div>\
|
||||
<span class="title">'+ artist +' — '+ track +'</span>\
|
||||
<span class="duration">'+ length +'</span>\
|
||||
<div class="remove">remove</div>\
|
||||
</div>\
|
||||
</li>\
|
||||
');
|
||||
|
||||
$('#playlist').html($('.playlist-tracks')).scrollbar();
|
||||
$('.playlist-tracks').sortable();
|
||||
},
|
||||
|
||||
setTrack: function(id) {
|
||||
var $obj = $('#i'+ id);
|
||||
var query = $obj.find('.title').text();
|
||||
var length = $obj.find('.duration').text();
|
||||
var tmp = query.split(' — ');
|
||||
|
||||
$('#player .now-playing').html(query);
|
||||
$('.playlist-tracks li').removeClass('now');
|
||||
$obj.addClass('now');
|
||||
$('#player .loaded, #player .played').width(0);
|
||||
|
||||
loadTracksData(tmp[0], tmp[1], length, Player.playSource);
|
||||
Player.updateNowListening(tmp[0], tmp[1]);
|
||||
},
|
||||
|
||||
playSource: function(url) {
|
||||
var id = $('.playlist-tracks .now').attr('id').split('i')[1];
|
||||
Audio.pause();
|
||||
Audio.rewind();
|
||||
Audio.addTrack(id, url);
|
||||
Audio.setTrack(id);
|
||||
Audio.play();
|
||||
Audio.startListener();
|
||||
},
|
||||
|
||||
nextTrack: function() {
|
||||
if (true) { // Shuffle off
|
||||
if ($('.playlist-tracks .now').next().length == 0 && true) { // Last track in the playlist and repeat is on
|
||||
return $('.playlist-tracks li').first().attr('id').split('i')[1];
|
||||
} else {
|
||||
return $('.playlist-tracks .now').next().attr('id').split('i')[1];
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
prevTrack: function() {
|
||||
if (true) { // Shuffle off
|
||||
if ($('.playlist-tracks .now').prev().length == 0 && true) { // 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];
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
updateUI: function(buffered, played, listened) {
|
||||
$('#player .loaded').width(Math.round(buffered * this.bar_width));
|
||||
$('#player .played').width(Math.round(played * this.bar_width));
|
||||
if (played == 1) {
|
||||
Audio.killListener();
|
||||
Player.setTrack(Player.nextTrack());
|
||||
}
|
||||
if (played > 0.5 && listened > 0) {
|
||||
var tmp = $('#player .now-playing').text().split(' — ');
|
||||
Player.scrobble(tmp[0], tmp[1]);
|
||||
}
|
||||
},
|
||||
|
||||
reset: function() {
|
||||
Audio.pause();
|
||||
Audio.killListener();
|
||||
$('#player .loaded, #player .played').width(0);
|
||||
$('#player .now-playing').text('Select track');
|
||||
},
|
||||
|
||||
updateNowListening: function(artist, track) {
|
||||
Session.query('/lastfm/listening?r='+ Math.random(), {'artist': artist, 'track': track})
|
||||
},
|
||||
|
||||
scrobble: function(artist, track) {
|
||||
Session.query('/lastfm/scrobble?r='+ Math.random(), {'artist': artist, 'track': track})
|
||||
}
|
||||
}
|
||||
|
||||
$('#player .controls .prev').live('click', function(){
|
||||
Player.setTrack(Player.prevTrack());
|
||||
});
|
||||
|
||||
$('#player .controls .next').live('click', function(){
|
||||
Player.setTrack(Player.nextTrack());
|
||||
});
|
||||
|
||||
$('.add-album').live('click', function() {
|
||||
var artist = $('.artist-info .name').html();
|
||||
$(this).parent().parent().parent().find('.tracklist li').each(function(i, item){
|
||||
var track_name = $(item).find('.trackname').html();
|
||||
var length = $(item).find('.length').html();
|
||||
Player.addTrack(artist, track_name, length);
|
||||
});
|
||||
})
|
||||
$('.add-track').live('click', function(){
|
||||
var artist = $('.artist-info .name').html();
|
||||
var track_name = $(this).parent().find('.trackname').html();
|
||||
var length = $(this).parent().find('.length').html();
|
||||
Player.addTrack(artist, track_name, length);
|
||||
});
|
||||
|
||||
$('.tracklist li').live('mouseover mouseout', function(e){
|
||||
if (e.type == 'mouseover') {
|
||||
$(this).find('.add-track').show();
|
||||
} else {
|
||||
$(this).find('.add-track').hide();
|
||||
}
|
||||
});
|
||||
|
||||
$('.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();
|
||||
}
|
||||
});
|
||||
|
||||
$('.playlist-tracks li .remove').live('click', function(){
|
||||
var $li = $(this).parent().parent();
|
||||
if ($li.hasClass('now')) {
|
||||
Player.reset();
|
||||
}
|
||||
$li.remove();
|
||||
});
|
||||
|
||||
$('.playlist-tracks li').live('dblclick', function(){
|
||||
Player.setTrack($(this).attr('id').split('i')[1]);
|
||||
});
|
||||
|
||||
$('#player .progress').live('click', function(e){
|
||||
Audio.skipToPercent(e.offsetX / Player.bar_width);
|
||||
});
|
||||
@@ -0,0 +1,64 @@
|
||||
var Search = {
|
||||
|
||||
pics: [],
|
||||
|
||||
showSpinner: function() {
|
||||
$('#search-container input').attr('disabled', 'disabled').blur();
|
||||
$('#search-container img').show();
|
||||
$('.autocomplete-container').hide();
|
||||
Search.hideSuggestions();
|
||||
},
|
||||
|
||||
hideSpinner: function() {
|
||||
$('#search-container input').removeAttr('disabled');
|
||||
$('#search_field').focus();
|
||||
$('#search-container img').hide();
|
||||
},
|
||||
|
||||
showSuggestions: function(values) {
|
||||
for (var i = 0; i < values.length; i++) {
|
||||
$('.suggestions ul').append('\
|
||||
<li>\
|
||||
<a class="data artist">'+ values[i].name +'</a>\
|
||||
'+ (values[i].desc ? '<br/><span>'+ values[i].desc +'</span>' : '') +'\
|
||||
</li>\
|
||||
');
|
||||
}
|
||||
$('.suggestions').show();
|
||||
},
|
||||
|
||||
hideSuggestions: function() {
|
||||
$('.suggestions ul li').remove();
|
||||
$('.suggestions').hide();
|
||||
},
|
||||
|
||||
showArtistPics: function(pics) {
|
||||
$('.artist_loading, .artist_pics').show();
|
||||
for (var i = 0; i < pics.length; i++) {
|
||||
if (Search.pics.indexOf(pics[i]) === -1) {
|
||||
Search.pics.push(pics[i]);
|
||||
$('.artist_pics').append('\
|
||||
<div class="pic">\
|
||||
<img src="'+ pics[i] +'" alt=""/>\
|
||||
</div>\
|
||||
');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$(function(){
|
||||
$('.search').live('click', function(){
|
||||
Ajax.loadSearchPage();
|
||||
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;
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
var Session = {
|
||||
|
||||
user_id: null,
|
||||
vk_params: {},
|
||||
|
||||
query: function(url, params, callback) {
|
||||
var q_params = this.vk_params;
|
||||
for (attr in params) {
|
||||
q_params[attr] = params[attr];
|
||||
}
|
||||
$.post(url, q_params, callback);
|
||||
},
|
||||
|
||||
setVkParams: function(params) {
|
||||
attrs = ['expire', 'mid', 'secret', 'sid', 'sig'];
|
||||
for (var i = 0; i < attrs.length; i++) {
|
||||
this.vk_params[attrs[i]] = params[attrs[i]];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
var Settings = {
|
||||
|
||||
lastfm_login_url: null,
|
||||
|
||||
getAccountInfo: function(callback) {
|
||||
Session.query('/user/update', {}, callback);
|
||||
},
|
||||
|
||||
saveAccountInfo: function(params, callback) {
|
||||
Session.query('/user/update', params, callback);
|
||||
},
|
||||
|
||||
loadFormData: function(form) {
|
||||
if (form == 'account') {
|
||||
this.getAccountInfo(function(data){
|
||||
$('.settings-container .form input[name$="username"]').val(data.username);
|
||||
$('.settings-container .form input[name$="email"]').val(data.email);
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$('.settings').live('click', function() {
|
||||
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());
|
||||
Settings.loadFormData($(this).attr('data-fieldset'));
|
||||
}
|
||||
if ($(this).attr('data-fieldset') == 'lastfm') {
|
||||
Session.query('/lastfm/getinfo', {}, function(data){
|
||||
if (data.connected) {
|
||||
$('.form-container input[name$="username"]').first().val(data.username);
|
||||
} else {
|
||||
Settings.lastfm_login_url = data.lastfm_login_url;
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
$('.lastfm-connect').live('click', function(){
|
||||
window.open(Settings.lastfm_login_url);
|
||||
});
|
||||
|
||||
$('.settings-container .form input').live('blur', function(){
|
||||
var 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, function(){
|
||||
$('#header-container .hello .greating').text('Hi there, '+ (params.username.length > 0 ? params.username : '%username%') +'!');
|
||||
});
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,85 @@
|
||||
function authInfo(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();
|
||||
}
|
||||
Session.query('/user/auth', {}, function(ar){
|
||||
if (!ar.username) {
|
||||
VK.Api.call('getVariable', {key: 1281}, function(r) {
|
||||
Session.query('/user/update', {'name': r.response}, function(ar2) {
|
||||
$('#header-container .hello .greating').text('Hi there, '+ (ar2.username ? ar2.username : '%username%') +'!');
|
||||
});
|
||||
});
|
||||
}
|
||||
$('#header-container .hello .greating').text('Hi there, '+ (ar.username ? ar.username : '%username%') +'!');
|
||||
Session.user_id = ar.id;
|
||||
});
|
||||
} else {
|
||||
$('#vk_login, .auth_notice').css('display', 'block');
|
||||
$('#vk_logout').hide();
|
||||
}
|
||||
}
|
||||
$(function(){
|
||||
VK.init({
|
||||
apiId: (document.location.host == 'beathaven.org' ? 2335068 : 2383163),
|
||||
nameTransportPath: "/xd_receiver.html"
|
||||
});
|
||||
VK.Auth.getLoginStatus(authInfo);
|
||||
$('#vk_login').click(function(){
|
||||
VK.Auth.login(authInfo, 8);
|
||||
});
|
||||
$('#vk_logout').click(function(){
|
||||
VK.Auth.logout(authInfo);
|
||||
});
|
||||
})
|
||||
|
||||
function loadTracksData(artist, track, duration, callback) {
|
||||
track_prepared = track.replace(/\(.*\)/i, '').split('/')[0];
|
||||
VK.Api.call('audio.search', {q: artist +' '+ track_prepared}, function(r){
|
||||
callback(matchPerfectResult(r.response, artist, track, duration));
|
||||
})
|
||||
}
|
||||
|
||||
function matchPerfectResult(data, artist, track, duration) {
|
||||
var duration = duration.split(':');
|
||||
if (duration[1].charAt(0) === '0') {
|
||||
duration[1] = duration[1].substring(1);
|
||||
}
|
||||
duration = parseInt(duration[0]) * 60 + parseInt(duration[1]);
|
||||
var best_score = 0;
|
||||
var best_result = null;
|
||||
for (var i = 1; i < data.length; i++) {
|
||||
var score = 0;
|
||||
if (data[i].artist === artist) {
|
||||
score += 10;
|
||||
} else if (data[i].artist.split(artist).length === 2) {
|
||||
score += 5;
|
||||
} else if (data[i].title.split(artist).length === 2) {
|
||||
score += 4;
|
||||
}
|
||||
if (data[i].title === track) {
|
||||
score += 10;
|
||||
} else if (data[i].title.split(track).length === 2) {
|
||||
score += 5;
|
||||
}
|
||||
if (parseInt(data[i].duration) === duration) {
|
||||
score += 15;
|
||||
} else {
|
||||
var delta = Math.abs(parseInt(data[i].duration) - duration);
|
||||
if (delta < 10) {
|
||||
score += (10 - delta);
|
||||
}
|
||||
}
|
||||
if (score > best_score) {
|
||||
best_score = score;
|
||||
best_result = data[i];
|
||||
}
|
||||
if (score === 35) {
|
||||
return best_result.url;
|
||||
}
|
||||
}
|
||||
return best_result.url;
|
||||
}
|
||||
Reference in New Issue
Block a user