Owen Leonard
2484fb6ac5
This patch adds an onload function to the JavaScript which loads images from Coce. In the case where the image is 1 x 1 pixel the image should be removed. To test you should have Coce enabled and Amazon.com included in the list of sources. - Apply the patch and view the bibliographic details page under a variety of conditions: - A title which has a matching Amazon image: - The image should load as expected. - A title which doesn't have a matching Amazon image - The image should not be found in the source at all after the page has loaded. - Test with local cover images enabled Signed-off-by: Lucas Gass <lucas@bywatersolutions.com> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
50 lines
1.5 KiB
JavaScript
50 lines
1.5 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,newWindow) {
|
|
var ids = [];
|
|
$("[id^=coce-thumbnail]").each(function(i) {
|
|
var id = $(this).attr("class"); // id=isbn
|
|
if ( id !== '' ) { ids.push(id); }
|
|
});
|
|
if (ids.length == 0) 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.classList.add("thumbnail");
|
|
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).remove();
|
|
}
|
|
}
|
|
$(this).html(img);
|
|
});
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
};
|