Jonathan Druart
fd6cbf2273
Bug 28179 added the gallery in the staff interface, and bug 28180 in the OPAC. OPAC and staff have different code, because the cover image providers are different. On bug 28180 we noticed that the OPAC needed additional code to handle OpenLibrary, Google Jacket and Coce, to differ the creation of the gallery to prevent Chocolat to be instantiated before the links (img src) are effectively in the DOM. To acchieve that we introduced a wait_for_images function, and added a "done" flag to the 3 "JS modules". However we haven't ported this code for the staff interface, which is also using Coce. Note that there was a bug at the OPAC as well for COCE, the ajax jQuery function is async, and so 'done' was set even if the call was not finished. Test plan: 0. Do not apply this patch 1. Enable LocalCoverImages and IntranetCoce 2. Pick a bibliographic record with an image returned from Coce 3. Add a local cover image 4. Go to the detail page 5. Open the gallery => Notice that you can notice a JS error and a loading icon on the second image. This behaviour is not always broken, it depends on the speed of the Coce server. If you don't see the problem reload the page. 6. Apply the patch and repeat => Notice that the cover slider block is longer to display the icon, but that the error is gone. 7. Confirm that there is no regression at the OPAC We could improve the situation here, and we could display the images in the slider, especially if the first image is a local image. But that's for another bug... Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
53 lines
1.9 KiB
JavaScript
53 lines
1.9 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);
|
|
});
|
|
}
|
|
},
|
|
}).then(function(){
|
|
// Cannot access 'this' from here
|
|
KOHA.coce.done = 1;
|
|
});
|
|
}
|
|
|
|
};
|