Koha/koha-tmpl/opac-tmpl/bootstrap/js/google-jackets.js
Owen Leonard 3d82116830
Bug 36566: Correct eslint errors in OPAC enhanced content JS
This patch fixes various eslint errors in enhanced content JS files:

- Consistent indentation
- Remove variables which are declared but not used
- Add missing semicolons
- Add missing "var" declarations

To test, apply the patch and clear your browser cache if necessary.

- Go to Administration -> System preferences and enable these
  preferences:
  - OPACAmazonCoverImages
  - BakerTaylorEnabled
  - GoogleJackets
  - OPACLocalCoverImages
  - OpenLibraryCovers
- Go to the OPAC and confirm that covers from these services appear
  correctly in search results and on detail pages.

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
2024-07-25 11:02:38 +01:00

85 lines
3.3 KiB
JavaScript

/* global __ */
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() {
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 (var id in booksInfo) {
var book = booksInfo[id];
$("[id^=gbs-thumbnail]."+book.bib_key).each(function() {
if (typeof(book.thumbnail_url) != "undefined") {
var img;
if ( $(this).data('use-data-link') ) {
var a = document.createElement("a");
a.href = book.thumbnail_url;
img = document.createElement("img");
img.src = book.thumbnail_url;
img.setAttribute('data-link', book.info_url);
a.append(img);
$(this).empty().append(a);
} else {
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 cover image available"));
$(this).empty().append(message);
}
});
}
this.done = 1;
}
};