Bug 13385: Add field 508 to XSLT (OPAC and staff)
[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                     if (!this.complete || typeof this.naturalWidth == "undefined" || this.naturalWidth == 0) {
32                         //IE HACK
33                         try {
34                             $(mydiv).append(img);
35                             $(mydiv).children('.no-image').remove();
36                         }
37                         catch(err){
38                         };
39                     } else {
40                         if (uselink) {
41                             var a = $("<a />").attr('href', '/cgi-bin/koha/opac-imageviewer.pl?biblionumber=' + $(mydiv).attr("class"));
42                             $(a).append(img);
43                             $(mydiv).empty().append(a);
44                         } else {
45                             $(mydiv).empty().append(img);
46                         }
47                         $(mydiv).children('.no-image').remove();
48                     }
49                 })
50         });
51     }
52 };