Bug 23148: (follow-up) Replace gif files in the OPAC with pngs
[koha.git] / koha-tmpl / intranet-tmpl / js / coce.js
blob930d7c164752a9a2c4d0ef73bf9cafe0765964ad
1 if (KOHA === undefined || !KOHA) { var KOHA = {}; }
4 /**
5 * A namespace for Coce cover images cache
6 */
7 KOHA.coce = {
9 /**
10 * Search all:
11 * <div title="biblionumber" id="isbn" class="coce-thumbnail"></div>
12 * or
13 * <div title="biblionumber" id="isbn" class="coce-thumbnail-preview"></div>
14 * and run a search with all collected isbns to coce cover service.
15 * The result is asynchronously returned, and used to append <img>.
17 getURL: function(host,provider,newWindow) {
18 var ids = [];
19 $("[id^=coce-thumbnail]").each(function(i) {
20 var id = $(this).attr("class"); // id=isbn
21 if ( id !== '' ) { ids.push(id); }
22 });
23 if (ids.length == 0) return;
24 ids = ids.join(',');
25 var coceURL = host + '/cover?id=' + ids + '&provider=' + provider;
26 $.ajax({
27 url: coceURL,
28 dataType: 'jsonp',
29 success: function(urlPerID){
30 for (var id in urlPerID) {
31 var url = urlPerID[id];
32 $("[id^=coce-thumbnail]."+id).each(function() {
33 var img = document.createElement("img");
34 img.src = url;
35 img.classList.add("thumbnail");
36 img.alt = "Cover image";
37 img.onload = function(){
38 // image dimensions can't be known until image has loaded
39 if( img.height == 1 && img.width == 1 ){
40 $(this).remove();
43 $(this).html(img);
44 });
47 });