Created
April 27, 2009 16:03
-
-
Save imlucas/102569 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Override the default now oplaying to allow an event to buybble up when we chaaange the track | |
// This way we can listen for it easily without polling to check for Amie Street Links | |
function displayTrack(track, show) { | |
var trackId = track.trackId; | |
var title = track.title; | |
var artist = track.contributor; | |
var activeClass = (track.is_fav) ? "active" : ""; | |
var show = (show ? '' : 'style="display:none"') | |
html = '<li ' + show + ' class="now_playing favable">'; | |
html += '<form title="Add this track to your favorites" method="post" id="track_' + trackId + | |
'_fav" class="fav ' + activeClass + '" action="/tracks/' + trackId + | |
'/toggle_fav"><input type="image" src="/images/btn/blank.png" /></form>'; | |
html += "<span class='t'>" + title + " </span> "; | |
html += "<span class='a'>" + artist + "</span>"; | |
html += '<div id="track_details_'+trackId+'" class="track_details clear" style="display:none;">' + | |
'<div class="amazon"> ' + | |
'<img src="/images/icon/icon.amazon.png" class="trans-png" /> ' + | |
'<a href="http://www.amazon.com/gp/search?ie=UTF8&keywords='+escape(artist)+'%20+'+escape(title)+ | |
'&tag=8tracks-20&index=digital-music&linkCode=ur2&camp=1789&creative=9325" title="Download from Amazon.com" rel="external"">Download</a>' + | |
'<img src="http://www.assoc-amazon.com/e/ir?t=8tracks-20&l=ur2&o=1" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />' + | |
'</div>'; | |
html += '<div class="album">'; | |
if(track.album){ | |
html += 'Album: <span class="detail">' + track.album + '</span>'; | |
} | |
html += '</div>'; | |
if(track.year){ | |
html += '<div class="year">Year: <span class="detail">' + track.year + '</span></div>'; | |
} | |
html+= '</div></li>'; | |
$j('#tracks_played').prepend(html); | |
$j(document).trigger('8tracks:new-now-playing'); | |
} | |
// Just a little test to make sure it works | |
$j(document).bind('8tracks:new-now-playing', function(){ | |
console.debug('8tracks:now playing has been changed'); | |
}); | |
$j(document).bind('8tracks:new-now-playing', function(){ | |
var AFFILIATE_CODE = '8tracks'; | |
var getAlbumBuyLink = function(id){ | |
return 'http://amiestreet.com/order/prepare?albumIds='+id+'&pytr='+AFFILIATE_CODE; | |
} | |
var getSongBuyLink = function(id){ | |
return 'http://amiestreet.com/order/prepare?songIds='+id+'&pytr='+AFFILIATE_CODE; | |
} | |
var li = $j('li.now_playing'); | |
var track = li.find('.t').html(); | |
var artist = li.find('.a').html(); | |
$j.getJSON('http://amiestreet.com/api/v0.1/SearchApi/find.json?jsoncallback=?&artists='+artist+'&songs='+track, function(data){ | |
if(data.songs[0].found){ | |
var h = '<img src="http://amiestreet.com/favicon.ico" alt="Download from Amie Street" style="margin-left: 10px;" /> <a rel="external" href="'+getSongBuyLink(data.songs[0].id)+'">Download</a>'; | |
li.find('.amazon').append(h); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment