Bug 4314 Flag for SSL Enabled to fix 3rd Party Enhanced Content in OPAC
[koha.git] / koha-tmpl / opac-tmpl / prog / en / js / google-jackets.js
1 if (typeof KOHA == "undefined" || !KOHA) {
2     var KOHA = {};
3 }
4
5 /**
6  * A namespace for Google related functions.
7  */
8 KOHA.Google = {
9
10
11     /**
12      * Search all:
13      *    <div title="biblionumber" id="isbn" class="gbs-thumbnail"></div>
14      * or
15      *    <div title="biblionumber" id="isbn" class="gbs-thumbnail-preview"></div>
16      * and run a search with all collected isbns to Google Book Search.
17      * The result is asynchronously returned by Google and catched by
18      * gbsCallBack().
19      */
20     GetCoverFromIsbn: function() {
21         var bibkeys = [];
22         $("div [id^=gbs-thumbnail]").each(function(i) {
23             bibkeys.push($(this).attr("class")); // id=isbn
24         });
25         bibkeys = bibkeys.join(',');
26         var scriptElement = document.createElement("script");
27         scriptElement.setAttribute("id", "jsonScript");
28         scriptElement.setAttribute("src",
29             "http://books.google.com/books?bibkeys=" + escape(bibkeys) +
30             "&jscmd=viewapi&callback=KOHA.Google.gbsCallBack");
31         scriptElement.setAttribute("type", "text/javascript");
32         document.documentElement.firstChild.appendChild(scriptElement);
33
34     },
35
36     /**
37      * Add cover pages <div
38      * and link to preview if div id is gbs-thumbnail-preview
39      */
40     gbsCallBack: function(booksInfo) {
41         for (id in booksInfo) {
42             var book = booksInfo[id];
43             $("."+book.bib_key).each(function() {
44                 var a = document.createElement("a");
45                 a.href = book.info_url;
46                                 if (typeof(book.thumbnail_url) != "undefined") {
47                         var img = document.createElement("img");
48                         img.src = book.thumbnail_url;
49                                         $(this).append(img);
50                     var re = /^gbs-thumbnail-preview/;
51                     if ( re.exec($(this).attr("id")) ) {
52                         $(this).append(
53                             '<div style="margin-bottom:5px; margin-top:-5px;font-size:9px">' +
54                             '<a href="' + 
55                             book.info_url + 
56                             '"><img src="' +
57                             'http://books.google.com/intl/en/googlebooks/images/gbs_preview_sticker1.gif' +
58                             '"></a></div>' 
59                             );
60                     }
61                                 } else {
62                                         var message = document.createElement("span");
63                                         $(message).attr("class","no-image");
64                                         $(message).html(NO_GOOGLE_JACKET);
65                                         $(this).append(message);
66                                 }
67             });
68         }
69     }
70 };