Last active
December 15, 2015 13:18
-
-
Save cfitz/5265810 to your computer and use it in GitHub Desktop.
quick coffeescript example how to pull bookjacket covers from Google Books in Blacklight. In the views, I added a span with .bookcover and an id of the isbn. AJAX grabs all the .bookcover id's, queries google, which returns JSONP that have all the images url. eh. you don't have to use google...you could just make your own controller that returns…
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
insertBookCoverImage = (data) -> | |
for id, values of data | |
imgId = values.bib_key.toLowerCase().replace(":", "_") | |
$("##{imgId}").attr("src", values.thumbnail_url) | |
addBookCovers = (ids) -> | |
url = "http://books.google.com/books?bibkeys=#{ids}&jscmd=viewapi&callback=?" | |
$.getJSON url, {}, insertBookCoverImage | |
$ -> | |
addBookCovers(( "ISBN:#{bookcover.id}," for bookcover in $('.bookcover[id]')).join(",")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment