Bug 27944: Add "requested" stage in article request process
[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_LOCAL_JACKET);
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                         if (uselink) {
42                             var a = $("<a />").attr('href', '/cgi-bin/koha/opac-imageviewer.pl?biblionumber=' + $(mydiv).attr("class"));
43                             $(a).append(img);
44                             $(mydiv).empty().append(a);
45                         } else {
46                             $(mydiv).empty().append(img);
47                         }
48                         $(mydiv).children('.no-image').remove();
49                     }
50                 })
51         });
52     },
53     GetCoverFromItemnumber: function(uselink) {
54         $("div[class^=local-thumbnail],span[class^=local-thumbnail]").each(function(i) {
55             var mydiv = this;
56             var message = document.createElement("span");
57             var imagenumber  = $(mydiv).data("imagenumber");
58             var biblionumber = $(mydiv).data("biblionumber");
59             $(message).attr("class","no-image");
60             $(message).html(NO_LOCAL_JACKET);
61             $(mydiv).parent().find('.no-image').remove();
62             $(mydiv).append(message);
63             var img = $("<img />").attr('src',
64                 '/cgi-bin/koha/opac-image.pl?thumbnail=1&imagenumber=' + imagenumber)
65                 .load(function () {
66                     this.setAttribute("class", "thumbnail");
67                     if (!this.complete || typeof this.naturalWidth == "undefined" || this.naturalWidth == 0) {
68                         //IE HACK
69                         try {
70                             $(mydiv).append(img);
71                             $(mydiv).children('.no-image').remove();
72                         }
73                         catch(err){
74                         };
75                     } else if (this.width > 1) { // don't show the silly 1px "no image" img
76                         if (uselink) {
77                             var a = $("<a />").attr('href', '/cgi-bin/koha/opac-imageviewer.pl?imagenumber=' + imagenumber + '&biblionumber=' + biblionumber);
78                             $(a).append(img);
79                             $(mydiv).empty().append(a);
80                         } else {
81                             $(mydiv).empty().append(img);
82                         }
83                         $(mydiv).children('.no-image').remove();
84                     }
85                 })
86         });
87     },
88 };