1 <script type="text/javascript">
3 var GBPreviewLink = '';
4 var GBPreviewShowing = false;
8 * @param {DOM object} isbn The form element containing the input parameters "isbns"
10 function searchForGBPreview( isbn ) {
11 dojo.require("dojo.io.script");
12 dojo.io.script.get({"url": "https://www.google.com/jsapi"});
13 dojo.io.script.get({"url": "https://www.googleapis.com/books/v1/volumes", "content": { "q": "isbn:" + isbn, "callback": "GBPreviewCallback"}});
17 * This function is the call-back function for the JSON scripts which
18 * executes a Google book search response.
20 * @param {JSON} GBPBookInfo is the JSON object pulled from the Google books service.
22 function GBPreviewCallback(GBPBookInfo) {
23 if (GBPBookInfo.totalItems < 1) return;
25 var accessInfo = GBPBookInfo.items[0].accessInfo;
30 if ( accessInfo.embeddable ) {
31 GPPreviewLink = GBPBookInfo.items[0].volumeInfo.previewLink;
32 if ( !GPPreviewLink) {
35 /* Add a button below the book cover image to load the preview. */
36 var GBPBadge = document.createElement( 'img' );
37 GBPBadge.id = 'gbpbadge';
38 GBPBadge.src = 'https://www.google.com/intl/[% ctx.locale.substr(0,2) %]/googlebooks/images/gbs_preview_button1.gif';
39 GBPBadge.title = dojo.byId('rdetail_title').innerHTML;
40 GBPBadge.style.border = 0;
41 GBPBadge.style.margin = '0.5em 0 0 0';
42 GBPBadgelink = document.createElement('a');
43 GBPBadgelink.id = 'gbpbadge_link';
44 GBPBadgelink.href = 'javascript:GBDisplayPreview(true);';
45 GBPBadgelink.appendChild( GBPBadge );
46 dojo.byId('rdetail_title_div').appendChild( GBPBadgelink );
47 unHideMe(dojo.byId('gbp_extra'));
52 * This is called when the user clicks on the 'Preview' link. We assume
53 * a preview is available from Google if this link was made visible.
55 function GBDisplayPreview(scroll_to_div) {
56 var GBPreviewPane = document.createElement('div');
57 GBPreviewPane.id = 'rdetail_preview_div';
58 GBPreviewPane.style.height = '800px';
59 GBPreviewPane.style.width = '600px';
60 GBPreviewPane.style.display = 'block';
61 var GBClear = document.createElement('div');
62 GBClear.style.padding = '1em';
63 dojo.byId('gbp_extra_container').appendChild(GBPreviewPane);
64 dojo.byId('gbp_extra_container').appendChild(GBClear);
65 if (GBPreviewPane.getAttribute('loaded') == null || GBPreviewPane.getAttribute('loaded') == "false" ) {
66 google.load("books", "0", {"callback" : GBPViewerLoadCallback, "language": "[% ctx.locale.substr(0,2) %]"} );
67 GBPreviewPane.setAttribute('loaded', 'true');
69 if (scroll_to_div) document.location.hash = '#gbp_extra';
72 function GBPViewerLoadCallback() {
73 var GBPViewer = new google.books.DefaultViewer(dojo.byId('rdetail_preview_div'));
74 GBPViewer.load(GPPreviewLink);
76 var GBPBadgelink = dojo.byId('gbpbadge_link');
77 GBPBadgelink.href = 'javascript:GBShowHidePreview(true);';
79 dojo.byId('gbp_extra_links').getElementsByTagName('a'),
81 link.href = 'javascript:GBShowHidePreview();';
84 hideMe(dojo.byId('gbp_arrow_link'));
85 unHideMe(dojo.byId('gbp_arrow_down_link'));
86 GBPreviewShowing = true;
89 function GBShowHidePreview(from_button) {
90 if (!GBPreviewShowing) {
91 dojo.byId('gbp_extra_container').style.display = 'inherit';
92 hideMe(dojo.byId('gbp_arrow_link'));
93 unHideMe(dojo.byId('gbp_arrow_down_link'));
94 GBPreviewShowing = true;
95 } else if (!from_button) { // button can open, but shouldn't close
96 dojo.byId('gbp_extra_container').style.display = 'none';
97 unHideMe(dojo.byId('gbp_arrow_link'));
98 hideMe(dojo.byId('gbp_arrow_down_link'));
99 GBPreviewShowing = false;
101 // button should always scroll
102 if (from_button) document.location.hash = '#gbp_extra';
105 dojo.addOnLoad(function() {
106 var spans = dojo.query('li.rdetail_isbns span.rdetail_value');
107 for (var i = 0; i < spans.length; i++) {
108 var prop = spans[i].getAttribute('property');
112 var isbn = spans[i].textContent || spans[i].innerText;
116 isbn = isbn.toString().replace(/^\s+/,"");
117 var idx = isbn.indexOf(" ");
119 isbn = isbn.substring(0, idx);
121 isbn = isbn.toString().replace(/-/g,"");
128 if (GBisbns.length) {
129 searchForGBPreview(GBisbns[0]);