ResearchTheatreEsoterist

Google Books Widget

From Urban Press

Jump to: navigation, search

Sneaky Google Book Preview

I wanted a transparent way to embed google book preview into my wiki, that only activated when users clicked on a link, and which could preview a specific page. This is the quick and dirty hack which resulted. The UI comes courtesy of Eric Martins OSX Style Modal Dialog.

The cool thing about this hack though is it uses the attributes within the link tag to locate and load the book and also turn to the correct page. For example:

  • (Carroll and Tenniel 1871, p 1)
  • (Berrington and Derrida 1988, p 58)
  • (Bakunin 1970 [1889], p 30)
  • Finally just for completeness here is one with no preview (Pratchett, p 30)

Technical Stuff

It uses an ISBN database call to get the title of the book - as google's full metadata results feeds are huge. The XML feed doesn't seem to be well formed though, as I kept getting parse errors, hence the hack around in the code. Google's embedded preview API also allows you to hilight a search term within the text. I may add this feature at some point, possibly by associating a div with the link somehow. It may take some thought. I use additional classes to differentiate between the loading state, an embedded preview, and books with no preview - these basically default to links to the books information page on google. Because link ids are assumed to be unique, in order to add more than one preview link to the same book you have to differentiate between them. I do this by adding a letter to the end of the isbn code, a then b and so on (they need to be sequential otherwise the script doesn't know where to look).

Caveat

The code is quick and dirty because it requires raw html rather than wikimarkup, as wikimarkup won't allow link tags and strips attributes from most other tags. It's therefore probably not useful for anyone running a public wiki. That said, it runs great outside the wiki environment, and if anyone wants to improve on it themselves, they are welcome to the code. Just let me know what you do with it.

Google Books Client
x