Owen Leonard
7678c98bdf
The JavaScript which handles the display of Google book cover images includes a hard-coded "style" attribute. It may have been relevant to the design of the old prog template, but it doesn't seem to have any use in the Bootstrap one. This patch removes it. I have replaced the style attribute with a class in case someone needs a hook for some custom CSS. To test, apply the patch, enable the GoogleJackets system preference, and clear your browser cache if necessary. - Search for a title in the OPAC which has a Google book cover image associated with it. - View the detail page for that title. Confirm that the "Google Preview" link underneath the cover image looks correct. Signed-off-by: Marc Véron <veron@veron.ch> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Brendan A Gallagher <brendan@bywatersolutions.com>
76 lines
2.8 KiB
JavaScript
76 lines
2.8 KiB
JavaScript
if (typeof KOHA == "undefined" || !KOHA) {
|
|
var KOHA = {};
|
|
}
|
|
|
|
/**
|
|
* A namespace for Google related functions.
|
|
*/
|
|
KOHA.Google = {
|
|
|
|
|
|
/**
|
|
* Search all:
|
|
* <div title="biblionumber" id="isbn" class="gbs-thumbnail"></div>
|
|
* or
|
|
* <div title="biblionumber" id="isbn" class="gbs-thumbnail-preview"></div>
|
|
* and run a search with all collected isbns to Google Book Search.
|
|
* The result is asynchronously returned by Google and catched by
|
|
* gbsCallBack().
|
|
*/
|
|
GetCoverFromIsbn: function(newWindow) {
|
|
var bibkeys = [];
|
|
$("[id^=gbs-thumbnail]").each(function(i) {
|
|
bibkeys.push($(this).attr("class")); // id=isbn
|
|
});
|
|
bibkeys = bibkeys.join(',');
|
|
var scriptElement = document.createElement("script");
|
|
this.openInNewWindow=newWindow;
|
|
scriptElement.setAttribute("id", "jsonScript");
|
|
scriptElement.setAttribute("src",
|
|
"https://books.google.com/books?bibkeys=" + escape(bibkeys) +
|
|
"&jscmd=viewapi&callback=KOHA.Google.gbsCallBack");
|
|
scriptElement.setAttribute("type", "text/javascript");
|
|
document.documentElement.firstChild.appendChild(scriptElement);
|
|
|
|
},
|
|
|
|
/**
|
|
* Add cover pages <div
|
|
* and link to preview if div id is gbs-thumbnail-preview
|
|
*/
|
|
gbsCallBack: function(booksInfo) {
|
|
var target = '';
|
|
if (this.openInNewWindow) {
|
|
target = 'target="_blank" rel="noreferrer" ';
|
|
}
|
|
for (id in booksInfo) {
|
|
var book = booksInfo[id];
|
|
$("[id^=gbs-thumbnail]."+book.bib_key).each(function() {
|
|
var a = document.createElement("a");
|
|
a.href = book.info_url;
|
|
if (typeof(book.thumbnail_url) != "undefined") {
|
|
var img = document.createElement("img");
|
|
img.src = book.thumbnail_url;
|
|
$(this).empty().append(img);
|
|
var re = /^gbs-thumbnail-preview/;
|
|
if ( re.exec($(this).attr("id")) ) {
|
|
$(this).append(
|
|
'<div class="google-books-preview">' +
|
|
'<a '+target+'href="' +
|
|
book.info_url +
|
|
'"><img src="' +
|
|
'https://books.google.com/intl/en/googlebooks/images/gbs_preview_sticker1.gif' +
|
|
'"></a></div>'
|
|
);
|
|
}
|
|
} else {
|
|
var message = document.createElement("span");
|
|
$(message).attr("class","no-image");
|
|
$(message).html(NO_GOOGLE_JACKET);
|
|
$(this).empty().append(message);
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|
|
};
|