|
Lines 9-25
KOHA.OpenLibrary = new function() {
Link Here
|
| 9 |
|
9 |
|
| 10 |
/** |
10 |
/** |
| 11 |
* Search all: |
11 |
* Search all: |
| 12 |
* <div title="biblionumber" id="isbn" class="openlibrary-thumbnail"></div> |
12 |
* <div title="biblionumber" class="openlibrary-thumbnail"></div> |
| 13 |
* or |
13 |
* and run a search with all collected isbns and olids to Open Library Book Search. |
| 14 |
* <div title="biblionumber" id="isbn" class="openlibrary-thumbnail-preview"></div> |
|
|
| 15 |
* and run a search with all collected isbns to Open Library Book Search. |
| 16 |
* The result is asynchronously returned by OpenLibrary and catched by |
14 |
* The result is asynchronously returned by OpenLibrary and catched by |
| 17 |
* olCallBack(). |
15 |
* olCallBack(). |
| 18 |
*/ |
16 |
*/ |
| 19 |
this.GetCoverFromIsbn = function() { |
17 |
this.GetCover = function() { |
| 20 |
var bibkeys = []; |
18 |
var bibkeys = []; |
| 21 |
$("[id^=openlibrary-thumbnail]").each(function(i) { |
19 |
$("[id^=openlibrary-thumbnail]").each(function(i) { |
| 22 |
bibkeys.push("ISBN:" + $(this).attr("class")); // id=isbn |
20 |
let isbn = $(this).data("isbn"); |
|
|
21 |
if ( isbn ) bibkeys.push("ISBN:" + isbn); |
| 22 |
let olid = $(this).data("olid"); |
| 23 |
if ( olid ) bibkeys.push("OLID:" + olid); |
| 23 |
}); |
24 |
}); |
| 24 |
bibkeys = bibkeys.join(','); |
25 |
bibkeys = bibkeys.join(','); |
| 25 |
var scriptElement = document.createElement("script"); |
26 |
var scriptElement = document.createElement("script"); |
|
Lines 38-69
KOHA.OpenLibrary = new function() {
Link Here
|
| 38 |
this.olCallBack = function(booksInfo) { |
39 |
this.olCallBack = function(booksInfo) { |
| 39 |
for (id in booksInfo) { |
40 |
for (id in booksInfo) { |
| 40 |
var book = booksInfo[id]; |
41 |
var book = booksInfo[id]; |
| 41 |
var isbn = id.substring(5); |
42 |
let isbn; let olid; |
| 42 |
$("[id^=openlibrary-thumbnail]."+isbn).each(function() { |
43 |
id.split(';').forEach((e) => { |
| 43 |
var a = document.createElement("a"); |
44 |
let identifier = e.split(':') |
| 44 |
a.href = booksInfo.url; |
45 |
if ( identifier[0] == 'ISBN' ) { |
| 45 |
if (book.cover) { |
46 |
isbn = identifier[1]; |
| 46 |
if ( $(this).data('use-data-link') ) { |
47 |
} else if ( identifier[0] == 'OLID' ) { |
| 47 |
var a = document.createElement("a"); |
48 |
olid = identifier[1]; |
| 48 |
a.href = book.cover.large; |
|
|
| 49 |
var img = document.createElement("img"); |
| 50 |
img.src = book.cover.medium; |
| 51 |
img.setAttribute('data-link', book.cover.large); |
| 52 |
a.append(img) |
| 53 |
$(this).empty().append(a); |
| 54 |
} else { |
| 55 |
var img = document.createElement("img"); |
| 56 |
img.src = book.cover.medium; |
| 57 |
img.height = '110'; |
| 58 |
$(this).append(img); |
| 59 |
} |
| 60 |
} else { |
| 61 |
var message = document.createElement("span"); |
| 62 |
$(message).attr("class","no-image"); |
| 63 |
$(message).html(NO_OL_JACKET); |
| 64 |
$(this).append(message); |
| 65 |
} |
49 |
} |
| 66 |
}); |
50 |
}); |
|
|
51 |
|
| 52 |
let elt = isbn ? $("[id^=openlibrary-thumbnail][data-isbn=%s]".format(isbn)) : $('*[data-olid="%s"]'.format(olid)); |
| 53 |
var a = document.createElement("a"); |
| 54 |
a.href = booksInfo.url; |
| 55 |
if (book.cover) { |
| 56 |
if ( $(elt).data('use-data-link') ) { |
| 57 |
var a = document.createElement("a"); |
| 58 |
a.href = book.cover.large; |
| 59 |
var img = document.createElement("img"); |
| 60 |
img.src = book.cover.medium; |
| 61 |
img.setAttribute('data-link', book.cover.large); |
| 62 |
a.append(img) |
| 63 |
$(elt).empty().append(a); |
| 64 |
} else { |
| 65 |
var img = document.createElement("img"); |
| 66 |
img.src = book.cover.medium; |
| 67 |
img.height = '110'; |
| 68 |
$(elt).append(img); |
| 69 |
} |
| 70 |
} else { |
| 71 |
var message = document.createElement("span"); |
| 72 |
$(message).attr("class","no-image"); |
| 73 |
$(message).html(NO_OL_JACKET); |
| 74 |
$(elt).append(message); |
| 75 |
} |
| 67 |
} |
76 |
} |
| 68 |
this.done = 1; |
77 |
this.done = 1; |
| 69 |
} |
78 |
} |