I have noticed that cover images are occasionally missing when the nodes are displayed in the grid associated with the default bookwall view. This is for books that have cover images which show in the full node view. Any suggestions for a fix? This is happening both on a dev site that I built and also the demo site that has been provided: http://drupalmty.com/millennium/millennium/bookwall

Comments

janusman’s picture

Title: Cover Images Missing in BookWall View » Google Books API not replacing missing cover images in Views
Category: support » task

The book wall or any other views listing with millennium items does not use the feature that allows Google Books API to replace missing images (which does work on normal node views).

I don't think it would be too hard to implement, just something that escaped my attention a while back. Should be a "task" since there's nothing to "fix" but rather something to add to the module.

I will mark this issue as such... as always, any help welcome!

janusman’s picture

Just a small update... this JS code would replace missing cover images in views with Google Book Search images (still missing: a patch for millennium.module). For now, copying-pasting this into Firebug works.

However, I am unsure if this constitutes a problem with the service's terms of use (Google requires a link back to them); I'll have to check that before making it part of the module... of course a possibility would be to enable that link, but that might get ugly... ideas welcome.

Drupal.behaviors.millenniumBookWall = function() {
  // If settings allow overriding the cover image, do it
  if (!Drupal.settings.millennium.gbooks_replace_covers) {
    return;
  }
  var covers = $(".views-field-cover-image img");
  if (covers.length == 0) {
    return;
  }
  var ids = '';
  var classname = '';
  .each(covers, function() {
    class = $(this).attr("class");
    if (class.substr(0,5) == 'isbn-') {
      if (ids) ids += ",";
      ids += class.substr(5);
    }
  });
  // callback=xxx tells the Gbooks API what function to call.
  var url = "http://books.google.com/books?jscmd=viewapi&bibkeys=" + ids + "&callback=Drupal.millenniumBookWall.process";
  $.getScript(url, function() {} );
}

Drupal.millenniumBookWall = {
  // Function that recieves and processes book information from the callback fired
  //   by the books API call above.
  process: function(booksInfo) {
    var bookInfo;
    var tmpImage = new Image();
    var destImgElement;
    var isbn;

    for (isbn in booksInfo) {
      bookInfo = booksInfo[isbn];
      if (bookInfo) {
        // If settings allow overriding the cover image, do it
        if (Drupal.settings.millennium.gbooks_replace_covers) {
          // Find image
          destImgElement = $("img.isbn-" + isbn);
          if (destImgElement.length == 1) {
            // If the current cover image's width <10, replace it with the google books image
            tmpImage.src = destImgElement.attr("src");
            if (tmpImage.width <10) {
              destImgElement.attr("src", bookInfo.thumbnail_url);
            }
          }
        }
      }
    }
  },
  // Callback when book not found
  notfound: function() {
  },
  // Callback when book found
  success: function() {
  }
}