2 <script type="text/javascript">
4 /* Checks to see if a given type of added content has data to show.
5 * The first arg to callback() is boolean indicating the presence of data */
6 function acIsAvailable(ident, type, callback) {
7 var url = '/opac/extras/ac/' + type + '/html/' + ident;
10 failOk : true, // http://bugs.dojotoolkit.org/ticket/11568
11 error : function(err) { callback(false, ident, type); },
12 load : function(result) { callback(true, ident, type); }
16 [%- # XXX revisit when ident=ctx.bre_id
17 ident = ctx.record_attrs.isbn_clean || ctx.record_attrs.upc;
19 FOR type IN ctx.added_content.keys;
20 IF ctx.added_content.$type.status == '3' # status unknown %]
22 dojo.addOnLoad(function() {
23 var ident = '[% ident %]';
24 var type = '[% type %]';
26 acIsAvailable(ident, type, function(avail, ident, type) {
29 [% IF CGI.param('expand') == 'addedcontent' %]
31 // if the content is available, un-hide the tab
32 dojo.removeClass(dojo.byId('ac:' + type), 'hidden');
35 // if no default type is selected on the main tab link
36 // set one here, since we have available content
38 var link = dojo.query('[name=addedcontent]')[0];
39 var href = link.getAttribute('href');
40 if (!href.match('[\&;]ac=')) {
41 href = href.replace('#addedcontent', ';ac=' + type + '#addedcontent');
42 dojo.attr(link, 'href', href);
43 dojo.attr(dojo.query('[name=addedcontent_lbl]')[0], 'href', href);
50 [% END; # IF status unknown
55 [%- IF ctx.google_books_preview -%]
56 <script type="text/javascript">
57 var GBisbns = Array();
61 * @param {DOM object} isbn The form element containing the input parameters "isbns"
63 function searchForGBPreview( isbn ) {
64 dojo.require("dojo.io.script");
65 dojo.io.script.get({"url": "https://www.google.com/jsapi"});
66 dojo.io.script.get({"url": "https://www.googleapis.com/books/v1/volumes", "content": { "q": "isbn:" + isbn, "callback": "GBPreviewCallback"}});
70 * This function is the call-back function for the JSON scripts which
71 * executes a Google book search response.
73 * @param {JSON} GBPBookInfo is the JSON object pulled from the Google books service.
75 function GBPreviewCallback(GBPBookInfo) {
76 if (GBPBookInfo.totalItems < 1) return;
78 var accessInfo = GBPBookInfo.items[0].accessInfo;
83 if ( accessInfo.embeddable ) {
84 /* Add a button below the book cover image to load the preview. */
85 var GBPBadge = document.createElement( 'img' );
86 GBPBadge.id = 'gbpbadge';
87 GBPBadge.src = 'https://www.google.com/intl/[% ctx.locale.substr(0,2) %]/googlebooks/images/gbs_preview_button1.gif';
88 GBPBadge.title = dojo.byId('rdetail_title').innerHTML;
89 GBPBadge.style.border = 0;
90 GBPBadge.style.margin = '0.5em 0 0 0';
91 GBPBadgelink = document.createElement('a');
92 GBPBadgelink.href = 'javascript:GBDisplayPreview();';
93 GBPBadgelink.appendChild( GBPBadge );
94 dojo.byId('rdetail_title_div').appendChild( GBPBadgelink );
99 * This is called when the user clicks on the 'Preview' link. We assume
100 * a preview is available from Google if this link was made visible.
102 function GBDisplayPreview() {
103 var GBPreviewPane = document.createElement('div');
104 GBPreviewPane.id = 'rdetail_preview_div';
105 GBPreviewPane.style.height = '800px';
106 GBPreviewPane.style.width = '600px';
107 GBPreviewPane.style.display = 'block';
108 var GBClear = document.createElement('div');
109 GBClear.style.padding = '1em';
110 dojo.byId('canvas_main').insertBefore(GBPreviewPane, dojo.byId('rdetail_record_details'));
111 dojo.byId('canvas_main').insertBefore(GBClear, dojo.byId('rdetail_record_details'));
112 if (GBPreviewPane.getAttribute('loaded') == null || GBPreviewPane.getAttribute('loaded') == "false" ) {
113 google.load("books", "0", {"callback" : GBPViewerLoadCallback, "language": "[% ctx.locale.substr(0,2) %]"} );
114 GBPreviewPane.setAttribute('loaded', 'true');
118 function GBPViewerLoadCallback() {
119 var GBPViewer = new google.books.DefaultViewer(dojo.byId('rdetail_preview_div'));
120 GBPViewer.load('ISBN:' + GBisbns[0]);
122 dojo.byId('gbpbadge').style.display = 'none';
125 dojo.addOnLoad(function() {
126 var spans = dojo.query('li.rdetail_isbns span.rdetail_value');
127 for (var i = 0; i < spans.length; i++) {
128 var prop = spans[i].getAttribute('itemprop');
132 var isbn = spans[i].textContent || spans[i].innerText;
136 isbn = isbn.toString().replace(/^\s+/,"");
137 var idx = isbn.indexOf(" ");
139 isbn = isbn.substring(0, idx);
141 isbn = isbn.toString().replace(/-/g,"");
148 searchForGBPreview(GBisbns[0]);