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