Bug 18421: (follow-up) QA fixes
[koha.git] / koha-tmpl / intranet-tmpl / js / coce.js
1 if (KOHA === undefined || !KOHA) { var KOHA = {}; }
2
3
4 /**
5  * A namespace for Coce cover images cache
6  */
7 KOHA.coce = {
8
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>.
16    */
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.title = url; //FIXME: to delete
36             $(this).html(img);
37          });
38         }
39       }
40     });
41   }
42
43 };