View | Details | Raw Unified | Return to bug 7161
Collapse All | Expand All

(-)a/koha-tmpl/opac-tmpl/prog/en/js/openlibrary.js (-31 / +38 lines)
Lines 2-7 if (typeof KOHA == "undefined" || !KOHA) { Link Here
2
    var KOHA = {};
2
    var KOHA = {};
3
}
3
}
4
4
5
function keys(d) {
6
  var k = [];
7
  for (var i in d) {
8
    k.push(i);
9
  }
10
  return k;
11
}
5
/**
12
/**
6
 * A namespace for OpenLibrary related functions.
13
 * A namespace for OpenLibrary related functions.
7
 */
14
 */
Lines 27-70 KOHA.OpenLibrary = { Link Here
27
        scriptElement.setAttribute("id", "jsonScript");
34
        scriptElement.setAttribute("id", "jsonScript");
28
        scriptElement.setAttribute("src",
35
        scriptElement.setAttribute("src",
29
            "http://openlibrary.org/api/books?bibkeys=" + escape(bibkeys) +
36
            "http://openlibrary.org/api/books?bibkeys=" + escape(bibkeys) +
30
            "&callback=KOHA.OpenLibrary.olCallBack");
37
            "&callback=KOHA.OpenLibrary.olCallBack&jscmd=data");
31
        scriptElement.setAttribute("type", "text/javascript");
38
        scriptElement.setAttribute("type", "text/javascript");
32
        document.documentElement.firstChild.appendChild(scriptElement);
39
        document.documentElement.firstChild.appendChild(scriptElement);
33
40
34
    },
41
    },
35
42
43
44
36
    /**
45
    /**
37
     * Add cover pages <div
46
     * Add cover pages <div
38
     * and link to preview if div id is gbs-thumbnail-preview
47
     * and link to preview if div id is gbs-thumbnail-preview
39
     */
48
     */
40
    olCallBack: function(booksInfo) {
49
    olCallBack: function(booksInfo) {
41
       for (id in booksInfo) {
50
    for (id in booksInfo) {
42
          var book = booksInfo[id];
51
       var book = booksInfo[id];
43
          var isbn = book.bib_key.substring(5);
52
       var isbn = id.substring(5);
44
          
53
       $("."+isbn).each(function() {
45
          $("."+isbn).each(function() {
54
       var is_opacdetail = /openlibrary-thumbnail-preview/.exec($(this).attr("id"));
46
              var a = document.createElement("a");
55
           var a = document.createElement("a");
47
              a.href = book.info_url;
56
           a.href = booksInfo.url;
48
				      if (typeof(book.thumbnail_url) != "undefined") {
57
           if (book.cover) {
49
	               	var img = document.createElement("img");
58
               var img = document.createElement("img");
50
	                img.src = book.thumbnail_url;
59
               if (is_opacdetail) {
51
					        $(this).append(img);
60
		img.src = book.cover.medium;
52
                  var re = /^openlibrary-thumbnail-preview/;
61
		$(this).append(img);
53
                  if ( re.exec($(this).attr("id")) ) {
62
                $(this).append(
54
                      $(this).append(
63
                       '<div class="results_summary">' + '<a href="' + book.url + '">Preview</a></div>'
55
                        '<div style="margin-bottom:5px; margin-top:-5px;font-size:9px">' +
64
                   );
56
                        '<a href="' + 
65
               } else {
57
                        book.info_url + 
66
			img.src = book.cover.small;
58
                        '">Preview</a></div>' 
67
			$(this).append(img);
59
                      );
68
		}
60
                  }
69
           } else {
61
		     		} else {
70
               var message =  document.createElement("span");
62
				    	var message = document.createElement("span");
71
               $(message).attr("class","no-image");
63
					    $(message).attr("class","no-image");
72
               $(message).html(NO_OL_JACKET);
64
					    $(message).html(NO_OL_JACKET);
73
               $(this).append(message);
65
					    $(this).append(message);
74
           }
66
				    }
75
       });
67
        });
76
   }
68
      }
77
 }
69
    }
70
};
78
};
71
- 

Return to bug 7161