Skip to content

Instantly share code, notes, and snippets.

@cfitz
Last active December 15, 2015 13:18
Show Gist options
  • Save cfitz/5265810 to your computer and use it in GitHub Desktop.
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…
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