Jonathan Druart
1513cd66b6
If Coce is enabled by no image are returned by the service, then no other image will be displayed (actually un-hidden) The getURL is returning early if no image is returned by the service and the "done" flag is never set. Test plan: Add a local cover image to a bibliographic record (ktd biblionumber=14 is good) Set CoceHost = http://coce.bywatersolutions.com Select all CoceProviders Enable OpacCoce => If no image is returned by Coce then the local image should be displayed anyway Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
52 lines
1.8 KiB
JavaScript
52 lines
1.8 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) {
|
|
var ids = [];
|
|
$("[id^=coce-thumbnail]").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);
|
|
});
|
|
}
|
|
},
|
|
|
|
});
|
|
this.done = 1;
|
|
}
|
|
|
|
};
|