PageSourceSearch

https://polosbn.bnnonline.it/SebinaOpac/sebinayou/js/sy/2.06.GoogleBooks.js

js bnnonline.it collected 2026-10-02 04:55:03 UTC 4,568 bytes, 158 lines download raw bytes

1var GoogleBooks = (function () {
2
3  var books = {};
4  var countBlock = -1;
5
6  function setCover(book) {
7    $("img[data='" + book.bib_key + "'][!analyzed]")
8        .each(
9            function() {
10              var $this = $(this);
11              $this.attr("analyzed", "true");
12              if (book.thumbnail_url !== null) {
13                $this.attr("src", book.thumbnail_url);
14              }
15            });
16  }
17
18  function setService(book) {
19    $(".googleBooks[data-isbn~='" + book.bib_key + "']")
20        .not("[data-done]")
21        .attr("data-done", true)
22        .each(
23            function() {
24              var $this = $(this);
25              var dataService = $this.attr("data-service");
26              if (dataService === "preview" && book.preview !== "noview") {
27                $this.html("<a title='" + i18n.js_gbook_preview + "' href='" + book.preview_url + "' target='_blank'><img src='http://www.google.com/intl/en/googlebooks/images/gbs_preview_sticker1.png'/></a>");
28                $this.show();
29              }
30              if (dataService === "info") {
31                $this.html("<a title='" + i18n.js_gbook_info + "' href='" + book.info_url + "' target='_blank'>" + i18n.js_gbook_label + "</a>");
32                $this.show();
33              }
34              if (dataService === "info-button") {
35                $this.html("<a title='" + i18n.js_gbook_info + "' href='" + book.info_url + "' target='_blank'><img src='"+SebinaYou.images+"/googlebook_button35.png' title='Google Books' alt='Google Books'></a>");
36                $this.show();
37              }
38            });
39  }
40
41  function call(googleBooksElements, type) {
42    if (typeof(googleBooksElements) === "string") {
43      googleBooksElements = $(googleBooksElements);
44    }
45    if (!googleBooksElements.length) {
46      return;
47    }
48
49    var bibkeys = "";
50    var callback = null;
51    googleBooksElements.each(
52        function() {
53          var $this = $(this);
54          var book;
55
56          if (type === "service") {
57            callback = GoogleBooks.replyService;
58
59            var isbn = get.data(this, "isbn");
60            if (is.string.blank(isbn)) {
61              return;
62            }
63            isbn = isbn.split(" ");
64            for (var i = 0; i < isbn.length; i++) {
65              book = books[isbn[i]];
66              if (typeof(book) === "undefined") {
67                bibkeys += isbn[i] + ",";
68                continue;
69              }
70              setService(book);
71              return;
72            }
73
74          } else if (type == "cover") {
75            callback = GoogleBooks.replyCover;
76
77            var data = $this.attr("data");
78            book = books[data];
79            if (typeof(book) === "undefined") {
80              bibkeys += data + ",";
81            } else {
82              setCover(book);
83            }
84          }
85        });
86
87    if (!is.string.blank(bibkeys)) {
88
89      var jsonScript = find("GoogleBooksearch_" + (++countBlock));
90      if (jsonScript) {
91        remove.node(jsonScript);
92      }
93
94      var id = "GoogleBooksearch_" + countBlock;
95      var src = "//books.google.com/books?bibkeys=" + bibkeys + "&jscmd=viewapi&callback=";
96      src += type === "service" ? "GoogleBooks.replyService" : "SebinaYou.GoogleBooks.replyCover";
97
98      $.getScript(src)
99        .done(
100            function(script, textStatus) {
101              // nope
102            })
103        .fail(
104            function(jqxhr, settings, exception) {
105              // nope
106            });
107
108      if(countBlock == 20) {
109        countBlock = -1;
110      }
111      return;
112    }
113
114    try {
115      callback.call();
116    } catch (e) {
117      // il caricamento di GoogleBooks fallisce per qualche motivo
118    }
119  }
120
121  return {
122
123    initService: function() {
124      call(".googleBooks", "service");
125    },
126
127    initCover: function() {
128      call("img[from='google']:not([analyzed])", "cover");
129    },
130
131    replyCover: function(booksInfo) {
132      $.each(booksInfo, function(i, book) {
133        books[book.bib_key] = book;
134        setCover(book);
135      });
136
137      $("img[from='google'][analyzed='true']")
138          .each(
139              function(i) {
140                var $this = $(this);
141                var src = $this.attr("src");
142                if (is.string.blank(src)) {
143                  $this.remove();
144                }
145              });
146    },
147
148    replyService: function(booksInfo) {
149      if (typeof booksInfo === "undefined") {
150        return;
151      }
152      $.each(booksInfo, function(i, book) {
153        books[book.bib_key] = book;
154        setService(book);
155      });
156    }
157  };
158})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.