1 <script type="text/javascript">
6 * @param {DOM object} isbn The form element containing the input parameters "isbns"
8 function searchForGBPreview( isbn ) {
9 dojo.require("dojo.io.script");
10 dojo.io.script.get({"url": "https://www.google.com/jsapi"});
11 dojo.io.script.get({"url": "https://www.googleapis.com/books/v1/volumes", "content": { "q": "isbn:" + isbn, "callback": "GBPreviewCallback"}});
15 * This function is the call-back function for the JSON scripts which
16 * executes a Google book search response.
18 * @param {JSON} GBPBookInfo is the JSON object pulled from the Google books service.
20 function GBPreviewCallback(GBPBookInfo) {
21 if (GBPBookInfo.totalItems < 1) return;
23 var accessInfo = GBPBookInfo.items[0].accessInfo;
28 if ( accessInfo.embeddable ) {
29 /* Add a button below the book cover image to load the preview. */
30 var GBPBadge = document.createElement( 'img' );
31 GBPBadge.id = 'gbpbadge';
32 GBPBadge.src = 'https://www.google.com/intl/[% ctx.locale.substr(0,2) %]/googlebooks/images/gbs_preview_button1.gif';
33 GBPBadge.title = dojo.byId('rdetail_title').innerHTML;
34 GBPBadge.style.border = 0;
35 GBPBadge.style.margin = '0.5em 0 0 0';
36 GBPBadgelink = document.createElement('a');
37 GBPBadgelink.href = 'javascript:GBDisplayPreview();';
38 GBPBadgelink.appendChild( GBPBadge );
39 dojo.byId('rdetail_title_div').appendChild( GBPBadgelink );
44 * This is called when the user clicks on the 'Preview' link. We assume
45 * a preview is available from Google if this link was made visible.
47 function GBDisplayPreview() {
48 var GBPreviewPane = document.createElement('div');
49 GBPreviewPane.id = 'rdetail_preview_div';
50 GBPreviewPane.style.height = '800px';
51 GBPreviewPane.style.width = '600px';
52 GBPreviewPane.style.display = 'block';
53 var GBClear = document.createElement('div');
54 GBClear.style.padding = '1em';
55 dojo.byId('canvas_main').insertBefore(GBPreviewPane, dojo.byId('rdetail_record_details'));
56 dojo.byId('canvas_main').insertBefore(GBClear, dojo.byId('rdetail_record_details'));
57 if (GBPreviewPane.getAttribute('loaded') == null || GBPreviewPane.getAttribute('loaded') == "false" ) {
58 google.load("books", "0", {"callback" : GBPViewerLoadCallback, "language": "[% ctx.locale.substr(0,2) %]"} );
59 GBPreviewPane.setAttribute('loaded', 'true');
63 function GBPViewerLoadCallback() {
64 var GBPViewer = new google.books.DefaultViewer(dojo.byId('rdetail_preview_div'));
65 GBPViewer.load('ISBN:' + GBisbns[0]);
67 dojo.byId('gbpbadge').style.display = 'none';
70 dojo.addOnLoad(function() {
71 var spans = dojo.query('li.rdetail_isbns span.rdetail_value');
72 for (var i = 0; i < spans.length; i++) {
73 var prop = spans[i].getAttribute('itemprop');
77 var isbn = spans[i].textContent || spans[i].innerText;
81 isbn = isbn.toString().replace(/^\s+/,"");
82 var idx = isbn.indexOf(" ");
84 isbn = isbn.substring(0, idx);
86 isbn = isbn.toString().replace(/-/g,"");
94 searchForGBPreview(GBisbns[0]);