var Player = { bar_width: 330, getTrackUrl: function(data) { }, addTrack: function(artist, track, length) { $('.playlist-tracks').append('\
  • \
    \ '+ artist +' — '+ track +'\ '+ length +'\
    \
  • \ '); }, setTrack: function(obj) { var id = $(obj).attr('id'); var query = $(obj).find('.title').html(); var length = $(obj).find('.duration').html(); $('#player .now-playing').html(query); $('.playlist-tracks li').removeClass('now'); $('#'+ id).addClass('now'); loadTracksData(query, this.playSource); }, playSource: function(url) { Audio.setTrack(url); Audio.play(); Audio.startListener(); }, updateUI: function(buffered, played) { $('#player .loaded').width(Math.round(buffered * this.bar_width)); $('#player .played').width(Math.round(played * this.bar_width)); } } $('.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').live('dblclick', function(){ Player.setTrack(this); }); $(function(){ Audio.init(); });