Koha/koha-tmpl/opac-tmpl/bootstrap/js/google-jackets.js
Owen Leonard 85a4779f9a
Bug 34026: Move translatable cover-handling strings out of opac-bottom.inc
This patch removes several instances from opac-bottom.inc where we
define strings for translation and use in separate JavaScript files. The
JavaScript files are updated to use the __() function to mark strings
for translation.

Note: Definition of the variable NO_COCE_JACKET is removed because it is
unused.

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

- In the staff interface, enable OPAC cover image services:
  - OPACAmazonCoverImages
  - BakerTaylorEnabled
  - GoogleJackets
  - OpenLibraryCovers

- In the OPAC, perform a search and confirm that there are no JS errors
  on the search results page related to cover images.
- Check the bibliographic detail page as well.

To confirm that the strings are being picked up for translation, run the
update process for another language, e.g.

perl misc/translator/translate update fr-FR

Then check the newly-built po file: fr-FR-messages-js.po. It should
list the updated files:

 koha-tmpl/opac-tmpl/bootstrap/js/amazonimages.js:8
 koha-tmpl/opac-tmpl/bootstrap/js/amazonimages.js:10
 koha-tmpl/opac-tmpl/bootstrap/js/bakertaylorimages.js:7
 koha-tmpl/opac-tmpl/bootstrap/js/google-jackets.js:77
 koha-tmpl/opac-tmpl/bootstrap/js/openlibrary.js:63

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
2023-10-09 11:41:14 -03:00

84 lines
3.3 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() {
if (typeof(book.thumbnail_url) != "undefined") {
if ( $(this).data('use-data-link') ) {
var a = document.createElement("a");
a.href = book.thumbnail_url;
var img = document.createElement("img");
img.src = book.thumbnail_url;
img.setAttribute('data-link', book.info_url);
a.append(img)
$(this).empty().append(a);
} else {
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 cover image available"));
$(this).empty().append(message);
}
});
}
this.done = 1;
}
};