Bug 1633: [SIGNED-OFF] Display local cover images
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / 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]").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).append(message);
27             var img = $("<img />").attr('src',
28                 '/cgi-bin/koha/catalogue/image.pl?thumbnail=1&biblionumber=' + $(mydiv).attr("class"))
29                 .load(function () {
30                     if (!this.complete || typeof this.naturalWidth == "undefined" || this.naturalWidth == 0) {
31                     } else {
32                         if (uselink) {
33                             var a = $("<a />").attr('href', '/cgi-bin/koha/catalogue/imageviewer.pl?biblionumber=' + $(mydiv).attr("class"));
34                             $(a).append(img);
35                             $(mydiv).append(a);
36                         } else {
37                             $(mydiv).append(img);
38                         }
39                         $(mydiv).children('.no-image').remove();
40                     }
41                 })
42         });
43     }
44 };