From: stevenaw
Date: Thu, 20 Jan 2011 16:28:56 +0000 (-0500)
Subject: Removed dependencies, fixed naming conventions [#169 state:peer-review-requested]
X-Git-Tag: v0.3~19^2~3
X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=871c126beba65a84d97eb677838db834d4ed861a;p=popcorn-js.git
Removed dependencies, fixed naming conventions [#169 state:peer-review-requested]
---
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
';
- $.each(data.artist.tags.tag, function(i,val) {
- htmlString += '- '+ this.name +'
';
- });
- htmlString += '
';
- htmlString += '
Similar
';
- $.each(data.artist.similar.artist, function(i,val) {
- htmlString += '- '+ this.name +'
';
- });
- htmlString += '
';
- 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
';
+
+ Popcorn.forEach( data.artist.tags.tag, function( val, i) {
+ htmlString += '- '+ val.name +'
';
+ });
+
+ htmlString += '
';
+ htmlString += '
Similar
';
+
+ Popcorn.forEach( data.artist.similar.artist, function( val, i) {
+ htmlString += '- '+ val.name +'
';
+ });
+
+ htmlString += '
';
+
+ _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 );