BookLinker: a couple of minor tweaks

I’ve made a couple of small adjustments to the BookLinker plugin I announced yesterday.

  1. The popup will now be placed according to the available window width. I found that if the link appears close to the right margin of the browser screen, the popup could drift off-screen. Now, the popup’s left position will be based on the position of the link and the window width; ideally, the popup will be positioned directly above the link, but it will shift left accordingly.
  2. LibraryThing has many book cover images available, but it doesn’t have them all. If a book cover is not available, an appropriately-size “No image available” image will be loaded instead. (I actually like the way I got this to work, by registering an onLoad event on the image; because there’s some latency in the request from LibraryThing, who will send an invisible 1×1 image when no cover is available, I don’t really know until the image loads if I got anything good. Registering an onError didn’t work, since something will always load, but in the onLoad I check the image width and then swap as appropriate.)

I would really like to add an AJAX call, probably to LibraryThing, to retrieve more information about the book and display the author and title. Not as elaborate as the LibraryThing widget (you can build your own here or see mine in the left sidebar here), but a little more than blank space. This is a little beyond my PHP skills this morning, though maybe I’ll have a solution by tonight.