<title>Popcorn LastFM Plug-in Demo</title>
<script src="../../popcorn.js"></script>
- <script src="../../test/jquery.js"></script>
<script src="popcorn.lastfm.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
end: 20, // seconds
artist: 'the beatles',
target: 'lastfmdiv'
+ } )
+ .lastfm({
+ start: 15, // seconds
+ end: 30, // seconds
+ artist: 'sdfsdfsdfdsddfsdfsdfsddfsf',
+ target: 'lastfmdiv'
} )
.lastfm({
start: 20, // seconds
<h1 id="qunit-header">Popcorn LastFM Plug-in Demo</h1>
<p> Artist information for 'yacht' will appear at 5 seconds and disappear at 15 seconds.</p>
<p> Artist information for 'The Beatles' will appear at 10 seconds and disappear at 20 seconds.</p>
+ <p> 'Unknown Artist' will appear at 15 seconds and disappear at 30 seconds.</p>
<p> Artist information for 'Coldplay' will appear at 20 seconds and disappear at 45 seconds.</p>
<p> Artist information for 'yacht' will appear at 25 seconds and disappear at 40 seconds.</p>
<div>
script.type = "text/javascript";
head.insertBefore( script, head.firstChild );
- _artists[options.artist] = "Information unavailable";
+ _artists[options.artist] = "Unknown Artist";
}
lastFMcallback = function(data){
- var htmlString = '<h3>'+data.artist.name+'</h3>';
- htmlString += '<a href="'+data.artist.url+'" target="_blank" style="float:left;margin:0 10px 0 0;"><img src="'+ data.artist.image[2]['#text'] +'" alt=""></a>';
- htmlString += '<p>'+ data.artist.bio.summary +'</p>';
- htmlString += '<hr /><p><h4>Tags</h4><ul>';
-
- Popcorn.forEach( data.artist.tags.tag, function( val, i) {
- htmlString += '<li><a href="'+ val.url +'">'+ val.name +'</a></li>';
- });
-
- htmlString += '</ul></p>';
- htmlString += '<hr /><p><h4>Similar</h4><ul>';
-
- Popcorn.forEach( data.artist.similar.artist, function( val, i) {
- htmlString += '<li><a href="'+ val.url +'">'+ val.name +'</a></li>';
- });
-
- htmlString += '</ul></p>';
-
- _artists[data.artist.name.toLowerCase()] = htmlString;
+ if (data.artist) {
+ var htmlString = '<h3>'+data.artist.name+'</h3>';
+ htmlString += '<a href="'+data.artist.url+'" target="_blank" style="float:left;margin:0 10px 0 0;"><img src="'+ data.artist.image[2]['#text'] +'" alt=""></a>';
+ htmlString += '<p>'+ data.artist.bio.summary +'</p>';
+ htmlString += '<hr /><p><h4>Tags</h4><ul>';
+
+ Popcorn.forEach( data.artist.tags.tag, function( val, i) {
+ htmlString += '<li><a href="'+ val.url +'">'+ val.name +'</a></li>';
+ });
+
+ htmlString += '</ul></p>';
+ htmlString += '<hr /><p><h4>Similar</h4><ul>';
+
+ Popcorn.forEach( data.artist.similar.artist, function( val, i) {
+ htmlString += '<li><a href="'+ val.url +'">'+ val.name +'</a></li>';
+ });
+
+ htmlString += '</ul></p>';
+
+ _artists[data.artist.name.toLowerCase()] = htmlString;
+ }
};
},
/**
test("Popcorn LastFM Plugin", function () {
var popped = Popcorn("#video"),
- expects = 5,
+ expects = 8,
count = 0,
interval,
interval2,
+ interval3,
lastfmdiv = document.getElementById('lastfmdiv');
expect( expects );
plus();
popped.lastfm({
- start: 1, // seconds
- end: 3, // seconds
- artist: 'yacht',
- target: 'lastfmdiv'
- } );
+ start: 1, // seconds
+ end: 4, // seconds
+ artist: 'yacht',
+ target: 'lastfmdiv'
+ } )
+ .lastfm({
+ start: 2.5, // seconds
+ end: 7, // seconds
+ artist: 'the beatles',
+ target: 'lastfmdiv'
+ } )
+ .lastfm({
+ start: 4.5, // seconds
+ end: 7, // seconds
+ artist: '',
+ target: 'lastfmdiv'
+ } );
interval = setInterval( function() {
- if( popped.currentTime() > 1 && popped.currentTime() < 3 ) {
- ok( /display: inline;/.test( lastfmdiv.innerHTML ), "Div contents are displayed" );
+ if( popped.currentTime() > 1 && popped.currentTime() < 4 ) {
+
+ equals ( lastfmdiv.childElementCount, 3, "lastfmdiv now has three inner elements" );
plus();
- ok( /img/.test( lastfmdiv.innerHTML ), "An image exists" );
+ equals (lastfmdiv.children[0].style.display , "inline", "yachtdiv is visible on the page" );
plus();
clearInterval( interval );
}
- }, 500);
+ }, 1000);
interval2 = setInterval( function() {
- if( popped.currentTime() > 3 ) {
- ok( /display: none;/.test( lastfmdiv.innerHTML ), "Div contents are hidden again" );
+ if( popped.currentTime() > 2.5 && popped.currentTime() < 3 ) {
+ equals (lastfmdiv.children[0].style.display , "inline", "yachtdiv is visible on the page" );
+ plus();
+ equals (lastfmdiv.children[1].style.display , "inline", "beatlesdiv is visible on the page" );
+ plus();
+ equals (lastfmdiv.children[2].style.display , "none", "nulldiv is not visible on the page" );
plus();
clearInterval( interval2 );
}
- }, 500);
+ }, 1000);
+
+ interval3 = setInterval( function() {
+ if( popped.currentTime() > 4.5 && popped.currentTime() < 7 ) {
+ equals (lastfmdiv.children[2].innerHTML , "Unknown Artist", "Artist information could not be found" );
+ plus();
+ clearInterval( interval3 );
+ }
+ }, 1000);
+
popped.volume(0);
popped.play();
-
});