Created
February 12, 2012 14:58
-
-
Save madr/1808920 to your computer and use it in GitHub Desktop.
Unobtrusive Anobii badge
This file contains 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
var BPs = {}; | |
var AnobiiBadge = (function(){ | |
var BADGE_URL = 'http://widgets.anobii.com/badge_result?settingId=4dd4b3916a743731'; | |
var bodyElm = document.getElementsByTagName('body')[0]; | |
return { | |
init: function(){ | |
var script = document.createElement('script'); | |
script.src = BADGE_URL; | |
script.type = 'text/javascript'; | |
bodyElm.appendChild(script); | |
if( script.readyState ){ | |
script.onreadystatechange = function(){ | |
if( script.readyState = 'complete' ) { | |
if(BPs['4dd4b3916a743731']) AnobiiBadge.install( BPs['4dd4b3916a743731'].items ); | |
} | |
} | |
}else{ | |
script.onload = function(){ | |
if(BPs['4dd4b3916a743731']) AnobiiBadge.install( BPs['4dd4b3916a743731'].items ); | |
} | |
} | |
}, | |
install: function(jsonData){ | |
var books = document.createElement('dl'); | |
var inner = ''; | |
for(var data, i = 0, max = jsonData.length; i<max; i++){ | |
data = jsonData[i]; | |
inner += '<dt><a href="'+data.link+'"><img src="'+data.image+'" alt=""></a></dt>'; | |
inner += '<dd><strong>'+data.title+'</strong> '+data.subtitle+'</dd>'; | |
inner += '<dd class="author">'+data.author+'</dd>'; | |
} | |
books.innerHTML = inner; | |
bodyElm.appendChild( books ); | |
} | |
} | |
})(); | |
AnobiiBadge.init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment