Bug 8264 - local cover images not working in IE8 [ prog ]
[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                         //IE HACK
32                         try {
33                             $(mydiv).append(img);
34                             $(mydiv).children('.no-image').remove();
35                         }
36                         catch(err){
37                         }
38                     } else {
39                         if (uselink) {
40                             var a = $("<a />").attr('href', '/cgi-bin/koha/catalogue/imageviewer.pl?biblionumber=' + $(mydiv).attr("class"));
41                             $(a).append(img);
42                             $(mydiv).append(a);
43                         } else {
44                             $(mydiv).append(img);
45                         }
46                         $(mydiv).children('.no-image').remove();
47                     }
48                 })
49         });
50     }
51 };