Bug 32302: Hide "ISBN" label when no ISBN data when sending list
[koha.git] / koha-tmpl / opac-tmpl / bootstrap / js / localcovers.js
1 if (typeof KOHA == "undefined" || !KOHA) {
2     var KOHA = {};
3 }
4
5 /**
6  * A namespace for local cover related functions.
7  */
8 KOHA.LocalCover = {
9
10
11     /**
12      * Search all:
13      *    <div title="biblionumber" id="isbn" class="openlibrary-thumbnail"></div>
14      * or
15      *    <div title="biblionumber" id="isbn" class="openlibrary-thumbnail-preview"></div>
16      * and run a search with all collected isbns to Open Library Book Search.
17      * The result is asynchronously returned by OpenLibrary and catched by
18      * olCallBack().
19      */
20     GetCoverFromBibnumber: function(uselink) {
21         $("div[id^=local-thumbnail],span[id^=local-thumbnail]").each(function(i) {
22             var mydiv = this;
23             var message = document.createElement("span");
24             $(message).attr("class","no-image");
25             $(message).html( __("No cover image available") );
26             $(mydiv).parent().find('.no-image').remove();
27             $(mydiv).append(message);
28             var img = $("<img />").attr('src',
29                 '/cgi-bin/koha/opac-image.pl?thumbnail=1&biblionumber=' + $(mydiv).attr("class"))
30                 .load(function () {
31                     this.setAttribute("class", "thumbnail");
32                     if (!this.complete || typeof this.naturalWidth == "undefined" || this.naturalWidth == 0) {
33                         //IE HACK
34                         try {
35                             $(mydiv).append(img);
36                             $(mydiv).children('.no-image').remove();
37                         }
38                         catch(err){
39                         };
40                     } else if (this.width > 1) { // don't show the silly 1px "no image" img
41                         $(mydiv).empty().append(img);
42                         $(mydiv).children('.no-image').remove();
43                     }
44                 })
45         });
46     },
47     GetCoverFromItemnumber: function(uselink) {
48         $("div[class^=local-thumbnail],span[class^=local-thumbnail]").each(function(i) {
49             var mydiv = this;
50             var message = document.createElement("span");
51             var imagenumber  = $(mydiv).data("imagenumber");
52             var biblionumber = $(mydiv).data("biblionumber");
53             $(message).attr("class","no-image");
54             $(message).html( __("No cover image available") );
55             $(mydiv).parent().find('.no-image').remove();
56             $(mydiv).append(message);
57             var img = $("<img />").attr('src',
58                 '/cgi-bin/koha/opac-image.pl?thumbnail=1&imagenumber=' + imagenumber)
59                 .load(function () {
60                     this.setAttribute("class", "thumbnail");
61                     if (!this.complete || typeof this.naturalWidth == "undefined" || this.naturalWidth == 0) {
62                         //IE HACK
63                         try {
64                             $(mydiv).append(img);
65                             $(mydiv).children('.no-image').remove();
66                         }
67                         catch(err){
68                         };
69                     } else if (this.width > 1) { // don't show the silly 1px "no image" img
70                         if (uselink) {
71                             var a = $("<a />").attr('href', '/cgi-bin/koha/opac-imageviewer.pl?imagenumber=' + imagenumber + '&biblionumber=' + biblionumber);
72                             $(a).append(img);
73                             $(mydiv).empty().append(a);
74                         } else {
75                             $(mydiv).empty().append(img);
76                         }
77                         $(mydiv).children('.no-image').remove();
78                     }
79                 })
80         });
81     },
82 };