function searchForGBPreview( isbn ) {
dojo.require("dojo.io.script");
dojo.io.script.get({"url": "https://www.google.com/jsapi"});
- dojo.io.script.get({"url": "http://books.google.com/books", "content": { "bibkeys": isbn, "jscmd": "viewapi", "callback": "GBPreviewCallback"}});
+ dojo.io.script.get({"url": "https://www.googleapis.com/books/v1/volumes", "content": { "q": "isbn:" + isbn, "callback": "GBPreviewCallback"}});
}
/**
* @param {JSON} GBPBookInfo is the JSON object pulled from the Google books service.
*/
function GBPreviewCallback(GBPBookInfo) {
- var GBPreviewDiv = document.getElementById("rdetail_preview_div");
- var GBPBook;
+ if (GBPBookInfo.totalItems < 1) return;
- for ( i in GBPBookInfo ) {
- GBPBook = GBPBookInfo[i];
- }
-
- if ( !GBPBook ) {
+ var accessInfo = GBPBookInfo.items[0].accessInfo;
+ if ( !accessInfo ) {
return;
}
- if ( GBPBook.preview != "noview" ) {
+ if ( accessInfo.embeddable ) {
// Add a button below the book cover image to load the preview.
GBPBadge = document.createElement( 'img' );
- GBPBadge.src = 'http://books.google.com/intl/en/googlebooks/images/gbs_preview_button1.gif';
+ GBPBadge.src = 'https://www.google.com/intl/en/googlebooks/images/gbs_preview_button1.gif';
GBPBadge.title = $('rdetail_preview_badge').innerHTML;
GBPBadge.style.border = 0;
GBPBadgelink = document.createElement( 'a' );
}
function unhideGoogleBooksLink (data) {
- for ( var i in data ) {
- //if (data[i].preview == 'noview') continue;
+ for (var i = 0; i < data.items.length; i++) {
+ var item = data.items[i];
+
+ var gbspan;
+ for (var j = 0; j < item.volumeInfo.industryIdentifiers.length; j++) {
+ // XXX: As of 11-17-2011, some items do not return their own ISBN
+ // as an identifier, so this code fails. For example:
+ // https://www.googleapis.com/books/v1/volumes?q=isbn:0743243560&callback=unhideGoogleBooksLink
+ // It seems the only way around this would be doing a separate
+ // search for each result rather than one search for the whole
+ // page. Informal testing seems to indicate that these books
+ // are generally Google-unfriendly (no previews, not embeddable),
+ // so we will live without them for now.
+ var ident = item.volumeInfo.industryIdentifiers[j].identifier;
+ gbspan = $n(document.documentElement, 'googleBooksLink-' + ident);
+ if (gbspan) break;
+ }
+ if (!gbspan) continue;
- var gbspan = $n(document.documentElement, 'googleBooksLink-' + i);
var gba = $n(gbspan, "googleBooks-link");
gba.setAttribute(
'href',
- data[i].info_url
+ item.volumeInfo.infoLink
+ // XXX: we might consider constructing the above link ourselves,
+ // as the link provided populates the search box with our original
+ // multi-item search. Something like:
+ // 'http://books.google.com/books?id=' + item.id
+ // Postive: cleaner display
+ // Negative: more fragile (link format subject to change; likely
+ // enough to matter?)
);
removeCSSClass( gbspan, 'hide_me' );
}
if (googleBooksLink) {
var gbspan = $n(r, "googleBooksLink");
+ // Google never has dashes in the ISBN, records sometimes do;
+ // remove them to match results list
+ // XXX: consider making part of cleanISBN(), or we can work around
+ // this if we move to one request per record
gbspan.setAttribute(
'name',
- gbspan.getAttribute('name') + '-' + currentISBN
+ gbspan.getAttribute('name') + '-' + currentISBN.toString().replace(/-/g,"")
);
}
var scriptElement = document.createElement("script");
scriptElement.setAttribute("id", "jsonScript");
scriptElement.setAttribute("src",
- "http://books.google.com/books?bibkeys=" +
- escape(isbnList.join(', ')) + "&jscmd=viewapi&callback=unhideGoogleBooksLink");
+ "https://www.googleapis.com/books/v1/volumes?q=" +
+ escape('isbn:' + isbnList.join(' | isbn:')) + "&callback=unhideGoogleBooksLink");
scriptElement.setAttribute("type", "text/javascript");
// make the request to Google Book Search
document.documentElement.firstChild.appendChild(scriptElement);