[open-ils-commits] r12465 - in trunk/Open-ILS/web/opac/skin/default: js xml (dbs)
svn at svn.open-ils.org
svn at svn.open-ils.org
Sun Mar 8 00:48:11 EST 2009
Author: dbs
Date: 2009-03-08 00:48:08 -0500 (Sun, 08 Mar 2009)
New Revision: 12465
Modified:
trunk/Open-ILS/web/opac/skin/default/js/rdetail.js
trunk/Open-ILS/web/opac/skin/default/xml/page_rdetail.xml
Log:
Cherry-pick the "integrate Google Book Preview into record detail" feature based on a patch by Alexander O'Neill <aoneill at upei.ca> 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).
Modified: trunk/Open-ILS/web/opac/skin/default/js/rdetail.js
===================================================================
--- trunk/Open-ILS/web/opac/skin/default/js/rdetail.js 2009-03-07 21:34:43 UTC (rev 12464)
+++ trunk/Open-ILS/web/opac/skin/default/js/rdetail.js 2009-03-08 05:48:08 UTC (rev 12465)
@@ -199,6 +199,8 @@
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 @@
case "excerpt":
addCSSClass($('rdetail_excerpt_link'), 'rdetail_extras_selected');
unHideMe($('rdetail_excerpt_div'));
+ rdetailDisplayPreview();
break;
case "anotes":
@@ -703,12 +706,13 @@
$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);
var dHref = 'javascript:rdetailVolumeDetails('+
@@ -805,3 +809,97 @@
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()) );
+
+}
Modified: trunk/Open-ILS/web/opac/skin/default/xml/page_rdetail.xml
===================================================================
--- trunk/Open-ILS/web/opac/skin/default/xml/page_rdetail.xml 2009-03-07 21:34:43 UTC (rev 12464)
+++ trunk/Open-ILS/web/opac/skin/default/xml/page_rdetail.xml 2009-03-08 05:48:08 UTC (rev 12465)
@@ -7,13 +7,14 @@
<script language='javascript' type='text/javascript' src='<!--#echo var="OILS_OPAC_JS_HOST"-->/skin/default/js/holds.js'></script>
<script language='javascript' type='text/javascript' src='<!--#echo var="OILS_OPAC_JS_HOST"-->/skin/default/js/cn_browse.js'></script>
<script language='javascript' type='text/javascript' src='<!--#echo var="OILS_OPAC_JS_HOST"-->/skin/default/js/container.js'></script>
+ <script src='http://www.google.com/jsapi' type='text/javascript' language='javascript'></script>
+ <script type='text/javascript' src='http://books.google.com/books/api.js?key=notsupplied&v=0&callback=google.loader.callbacks.books'></script>
<script language='javascript' type='text/javascript'>
config.ids.rdetail = {};
config.ids.rdetail.view_marc = "rdetail_view_marc";
</script>
-
<table width='100%' id='np_table' class='hide_me' style='margin-top: 3px;'>
<tbody>
<tr class='color_4' style='height: 1em;'>
More information about the open-ils-commits
mailing list