From e51156227f2842cae9880f0776c96ee5251caa31 Mon Sep 17 00:00:00 2001 From: dbs Date: Sun, 8 Mar 2009 05:48:08 +0000 Subject: [PATCH] Cherry-pick the "integrate Google Book Preview into record detail" feature based on a patch by Alexander O'Neill from http://vre.upei.ca/dev/node/422 I integrated the code directly into rdetail.js and edited it to remove unnecessary helper functions. Tested with Firefox 3 (Linux), Internet Explorer 7, Google Chrome, and Safari 3.2.1 (Windows). git-svn-id: svn://svn.open-ils.org/ILS/trunk@12465 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/web/opac/skin/default/js/rdetail.js | 108 ++++++++++++++++++++- .../web/opac/skin/default/xml/page_rdetail.xml | 3 +- 2 files changed, 105 insertions(+), 6 deletions(-) diff --git a/Open-ILS/web/opac/skin/default/js/rdetail.js b/Open-ILS/web/opac/skin/default/js/rdetail.js index f379b0723e..61f67e5d19 100644 --- a/Open-ILS/web/opac/skin/default/js/rdetail.js +++ b/Open-ILS/web/opac/skin/default/js/rdetail.js @@ -199,6 +199,8 @@ function _rdetailDraw(r) { var href = $('rdetail.jacket_attrib_link').getAttribute('href') +cleanISBN(record.isbn()); $('rdetail.jacket_attrib_link').setAttribute('href', href); } + rdetailCheckForPreview(); + } else { hideMe($("rdetail.jacket_attrib_div")); hideMe($("rdetail_img_link")); @@ -377,6 +379,7 @@ function rdetailShowExtra(type, args) { case "excerpt": addCSSClass($('rdetail_excerpt_link'), 'rdetail_extras_selected'); unHideMe($('rdetail_excerpt_div')); + rdetailDisplayPreview(); break; case "anotes": @@ -703,11 +706,12 @@ function rdetailBuildBrowseInfo(row, cn, local, orgNode, cl) { $n(row, 'rdetail_callnumber_cell').appendChild(text(cn)); - if (rdetailShowCopyLocation) { - var cl_cell = $n(row, 'rdetail_copylocation_cell'); - cl_cell.appendChild(text(cl)); - unHideMe(cl_cell); - } + if (rdetailShowCopyLocation) { + var cl_cell = $n(row, 'rdetail_copylocation_cell'); + cl_cell.appendChild(text(cl)); + + unHideMe(cl_cell); + } _debug('setting action clicks for cn ' + cn); @@ -805,3 +809,97 @@ function _rdetailSortStatuses(a, b) { return parseInt(a.id()) - parseInt(b.id()); } +function rdetailCheckForPreview() { + + var p = document.createElement('p'); + p.appendChild( document.createTextNode('Loading... ' ) ); + p.id = 'loading'; + $('rdetail_excerpt_div').appendChild(p); + searchForPreview( cleanISBN(record.isbn()) ); + +} + +/** + * + * @param {DOM object} query The form element containing the + * input parameters "isbns" + */ +function searchForPreview( isbn ) { + + // Delete any previous Google Booksearch JSON queries. + var jsonScript = document.getElementById("jsonScript"); + if (jsonScript) { + jsonScript.parentNode.removeChild(jsonScript); + } + // Add a script element with the src as the user's Google Booksearch query. + // JSON output is specified by including the alt=json-in-script argument + // and the callback function is also specified as a URI argument. + var scriptElement = document.createElement("script"); + + scriptElement.setAttribute("id", "jsonScript"); + scriptElement.setAttribute("src", + "http://books.google.com/books?bibkeys=" + + isbn + "&jscmd=viewapi&callback=previewCallback"); + scriptElement.setAttribute("type", "text/javascript"); + // make the request to Google booksearch + document.documentElement.firstChild.appendChild(scriptElement); +} + +/** + * This function is the call-back function for the JSON scripts which + * executes a Google book search response. + * + * @param {JSON} booksInfo is the JSON object pulled from the Google books service. + */ +function previewCallback(bookInfo) { + // Clear any old data to prepare to display the Loading... message. + var div = document.getElementById("rdetail_excerpt_div"); + var book; + + for ( i in bookInfo ) { + book = bookInfo[i]; + } + + if ( !book ) { + return; + } + + if ( book.preview != "noview" ) { + if ( book.preview == 'full' ) { + setText( $('rdetail_excerpt_link_a'), 'Full Text' ); + $('rdetail_excerpt_link_a').title = 'See the full text of this book.'; + } + + // Add a button below the book cover image to load the preview. + badge = document.createElement( 'img' ); + badge.src = 'http://books.google.com/intl/en/googlebooks/images/gbs_preview_button1.gif'; + badge.title = 'Show a preview of this book from Google Book Search'; + badge.style.border = 0; + badgelink = document.createElement( 'a' ); + badgelink.href = 'javascript:rdetailShowExtra("excerpt");'; + badgelink.appendChild( badge ); + $('rdetail_image_cell').appendChild( badgelink ); + + unHideMe( $('rdetail_excerpt_link' ) ); + $('rdetail_excerpt_div').style.height = 600; + } +} + +/** + * This is called when the user clicks on the 'Excerpt' link. We assume + * a preview is available from Google if this link was made visible. + */ +function rdetailDisplayPreview() { + previewPane = $('rdetail_excerpt_div'); + if ( $('rdetail_excerpt_div').getAttribute('loaded') == null || $('rdetail_excerpt_div').getAttribute('loaded') == "false" ) { + google.load("books", "0", {"callback" : rdetailViewerLoadCallback, "language": "hy"} ); + $('rdetail_excerpt_div').setAttribute('loaded', 'true'); + } +} + +function rdetailViewerLoadCallback() { + + var viewer = new google.books.DefaultViewer(document.getElementById('rdetail_excerpt_div')); +  viewer.load('ISBN:' + cleanISBN(record.isbn()) ); + +} diff --git a/Open-ILS/web/opac/skin/default/xml/page_rdetail.xml b/Open-ILS/web/opac/skin/default/xml/page_rdetail.xml index 3a362745e2..9d259ce59f 100644 --- a/Open-ILS/web/opac/skin/default/xml/page_rdetail.xml +++ b/Open-ILS/web/opac/skin/default/xml/page_rdetail.xml @@ -7,13 +7,14 @@ + + - -- 2.11.0