Koha/koha-tmpl/opac-tmpl/bootstrap/js/coce.js
Jonathan Druart 13dccaaf05
Bug 32412: Do not reload COCE image for biblio
We do not want to fetch again the new image for the biblio record. We
only want to fetch those for the shelf browser.

Note that the third parameter 'covernewwindow' was not used.

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
2023-05-05 10:18:42 -03:00

55 lines
2 KiB
JavaScript

if (KOHA === undefined || !KOHA) { var KOHA = {}; }
/**
* A namespace for Coce cover images cache
*/
KOHA.coce = {
/**
* Search all:
* <div title="biblionumber" id="isbn" class="coce-thumbnail"></div>
* or
* <div title="biblionumber" id="isbn" class="coce-thumbnail-preview"></div>
* and run a search with all collected isbns to coce cover service.
* The result is asynchronously returned, and used to append <img>.
*/
getURL: function(host, provider, parent=null) {
var ids = [];
const thumbnail_selector = "[id^=coce-thumbnail]";
let thumbnail_nodes = parent ? parent.find(thumbnail_selector) : $(thumbnail_selector);
thumbnail_nodes.each(function() {
var id = $(this).attr("class"); // id=isbn
if (id !== '') { ids.push(id); }
});
if (ids.length == 0) { this.done = 1; return; }
ids = ids.join(',');
var coceURL = host + '/cover?id=' + ids + '&provider=' + provider;
$.ajax({
url: coceURL,
dataType: 'jsonp',
success: function(urlPerID) {
for (var id in urlPerID) {
var url = urlPerID[id];
$("[id^=coce-thumbnail]." + id).each(function() {
var img = document.createElement("img");
img.src = url;
img.alt = "Cover image";
img.onload = function() {
// image dimensions can't be known until image has loaded
if (img.height == 1 && img.width == 1) {
$(this).closest(".coce-coverimg").remove();
}
};
$(this).attr('href', url);
$(this).append(img);
});
}
},
}).then(function(){
// Cannot access 'this' from here
KOHA.coce.done = 1;
});
}
};