From 871c126beba65a84d97eb677838db834d4ed861a Mon Sep 17 00:00:00 2001 From: stevenaw Date: Thu, 20 Jan 2011 11:28:56 -0500 Subject: [PATCH] Removed dependencies, fixed naming conventions [#169 state:peer-review-requested] --- plugins/lastfm/popcorn.lastfm.html | 14 +++++- plugins/lastfm/popcorn.lastfm.js | 81 +++++++++++++++++++----------- 2 files changed, 66 insertions(+), 29 deletions(-) diff --git a/plugins/lastfm/popcorn.lastfm.html b/plugins/lastfm/popcorn.lastfm.html index 078c84d..e5da20a 100644 --- a/plugins/lastfm/popcorn.lastfm.html +++ b/plugins/lastfm/popcorn.lastfm.html @@ -16,12 +16,24 @@ artist: 'yacht', target: 'lastfmdiv' } ) - .lastfm({ + .lastfm({ + start: 10, // seconds + end: 20, // seconds + artist: 'the beatles', + target: 'lastfmdiv' + } ) + .lastfm({ start: 20, // seconds end: 45, // seconds artist: 'Coldplay', target: 'lastfmdiv' } ) + .lastfm({ + start: 25, // seconds + end: 40, // seconds + artist: 'yacht', + target: 'lastfmdiv' + } ) }, false); diff --git a/plugins/lastfm/popcorn.lastfm.js b/plugins/lastfm/popcorn.lastfm.js index ad390ff..789fae7 100644 --- a/plugins/lastfm/popcorn.lastfm.js +++ b/plugins/lastfm/popcorn.lastfm.js @@ -1,4 +1,5 @@ // PLUGIN: LASTFM +var lastFMcallback; (function (Popcorn) { @@ -24,8 +25,11 @@ } ) * */ - Popcorn.plugin( "lastfm" , { - + Popcorn.plugin( "lastfm" , (function(){ + + var _artists = []; + + return { manifest: { about:{ name: "Popcorn LastFM Plugin", @@ -42,31 +46,49 @@ }, _setup: function( options ) { - options.container = document.createElement( 'div' ); - options.container.style.display = "none"; + options._container = document.createElement( 'div' ); + options._container.style.display = "none"; + options._container.innerHTML = ""; + + options.artist = options.artist.toLowerCase(); + if ( document.getElementById( options.target ) ) { - document.getElementById( options.target ).appendChild( options.container ); + document.getElementById( options.target ).appendChild( options._container ); } - - var htmlString = "";; - $.getJSON("http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist="+ options.artist +"&api_key=30ac38340e8be75f9268727cb4526b3d&format=json&callback=?", - function(data){ - htmlString += '

'+data.artist.name+'

'; - htmlString += ''; - htmlString += '

'+ data.artist.bio.summary +'

'; - htmlString += '

Tags

'; - htmlString += '

Similar

'; - options.container.innerHTML = htmlString; - } - ); + + if(!_artists[options.artist]) { + var loadScriptTime = (new Date).getTime(); + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + + script.src = "http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist="+ options.artist +"&api_key=30ac38340e8be75f9268727cb4526b3d&format=json&callback=lastFMcallback"; + script.type = "text/javascript"; + head.insertBefore( script, head.firstChild ); + + _artists[options.artist] = "Unknown information"; + } + + lastFMcallback = function(data){ + var htmlString = '

'+data.artist.name+'

'; + htmlString += ''; + htmlString += '

'+ data.artist.bio.summary +'

'; + htmlString += '

Tags

'; + htmlString += '

Similar

'; + + _artists[data.artist.name.toLowerCase()] = htmlString; + }; }, /** * @member LastFM @@ -75,7 +97,8 @@ * options variable */ start: function( event, options ) { - options.container.style.display = "inline"; + options._container.innerHTML = _artists[options.artist]; + options._container.style.display = "inline"; }, /** * @member LastFM @@ -84,8 +107,10 @@ * options variable */ end: function( event, options ) { - options.container.style.display = "none"; + options._container.style.display = "none"; + options._container.innerHTML = ""; } - }); + }; + })()); })( Popcorn ); -- 2.43.0