|
Lines 2-7
if (typeof KOHA == "undefined" || !KOHA) {
Link Here
|
| 2 |
var KOHA = {}; |
2 |
var KOHA = {}; |
| 3 |
} |
3 |
} |
| 4 |
|
4 |
|
|
|
5 |
function get_cover(data) { |
| 6 |
if (data.cover && data.cover.small) { |
| 7 |
return data.cover.small; |
| 8 |
} |
| 9 |
return "undefined"; |
| 10 |
} |
| 11 |
|
| 12 |
function get_ebook(data) { |
| 13 |
var buttons = { |
| 14 |
'full access': |
| 15 |
"http://openlibrary.org/images/button-read-open-library.png", |
| 16 |
'lendable': |
| 17 |
"http://openlibrary.org/images/button-borrow-open-library.png", |
| 18 |
'checkedout': |
| 19 |
"http://openlibrary.org/images/button-checked-out-open-library.png" |
| 20 |
}; |
| 21 |
|
| 22 |
var result = ""; |
| 23 |
if (data["ebooks"] != "undefined") { |
| 24 |
/* Ebooks are available */ |
| 25 |
var ebooks = data["ebooks"]; |
| 26 |
for (idx in ebooks) { |
| 27 |
var ebook = ebooks[idx]; |
| 28 |
if (ebook["availability"] == "full") { |
| 29 |
result = '<a href="' + ebook["read_url"] + '">' + '<img src="' + buttons["full access"] + '"/></a>'; |
| 30 |
} |
| 31 |
if (ebook["availability"] == "borrow") { |
| 32 |
if(ebook.checkedout) { |
| 33 |
result = '<a href="' + ebook["borrow_url"] + '">' + '<img src="' + buttons["checkedout"] + '"/></a>'; |
| 34 |
} else { |
| 35 |
result = '<a href="' + ebook["borrow_url"] + '">' + '<img src="' + buttons["lendable"] + '"/></a>'; |
| 36 |
} |
| 37 |
} |
| 38 |
} |
| 39 |
} |
| 40 |
return result; |
| 41 |
} |
| 42 |
|
| 43 |
function keys(d) { |
| 44 |
var k = []; |
| 45 |
for (var i in d) { |
| 46 |
k.push(i); |
| 47 |
} |
| 48 |
return k; |
| 49 |
} |
| 5 |
/** |
50 |
/** |
| 6 |
* A namespace for OpenLibrary related functions. |
51 |
* A namespace for OpenLibrary related functions. |
| 7 |
*/ |
52 |
*/ |
|
Lines 27-70
KOHA.OpenLibrary = {
Link Here
|
| 27 |
scriptElement.setAttribute("id", "jsonScript"); |
72 |
scriptElement.setAttribute("id", "jsonScript"); |
| 28 |
scriptElement.setAttribute("src", |
73 |
scriptElement.setAttribute("src", |
| 29 |
"http://openlibrary.org/api/books?bibkeys=" + escape(bibkeys) + |
74 |
"http://openlibrary.org/api/books?bibkeys=" + escape(bibkeys) + |
| 30 |
"&callback=KOHA.OpenLibrary.olCallBack"); |
75 |
"&callback=KOHA.OpenLibrary.olCallBack&jscmd=data"); |
| 31 |
scriptElement.setAttribute("type", "text/javascript"); |
76 |
scriptElement.setAttribute("type", "text/javascript"); |
| 32 |
document.documentElement.firstChild.appendChild(scriptElement); |
77 |
document.documentElement.firstChild.appendChild(scriptElement); |
| 33 |
|
78 |
|
| 34 |
}, |
79 |
}, |
| 35 |
|
80 |
|
|
|
81 |
|
| 82 |
|
| 36 |
/** |
83 |
/** |
| 37 |
* Add cover pages <div |
84 |
* Add cover pages <div |
| 38 |
* and link to preview if div id is gbs-thumbnail-preview |
85 |
* and link to preview if div id is gbs-thumbnail-preview |
| 39 |
*/ |
86 |
*/ |
| 40 |
olCallBack: function(booksInfo) { |
87 |
olCallBack: function(booksInfo) { |
| 41 |
for (id in booksInfo) { |
88 |
for (id in booksInfo) { |
| 42 |
var book = booksInfo[id]; |
89 |
var book = booksInfo[id]; |
| 43 |
var isbn = book.bib_key.substring(5); |
90 |
var isbn = id.substring(5); |
| 44 |
|
91 |
$("."+isbn).each(function() { |
| 45 |
$("."+isbn).each(function() { |
92 |
console.log($(this).attr("id")); |
| 46 |
var a = document.createElement("a"); |
93 |
var is_opacdetail = /openlibrary-thumbnail-preview/.exec($(this).attr("id")); |
| 47 |
a.href = book.info_url; |
94 |
/*console.log([is_opacdetail,this]); |
| 48 |
if (typeof(book.thumbnail_url) != "undefined") { |
95 |
var cover = get_cover(book);*/ |
| 49 |
var img = document.createElement("img"); |
96 |
var ebook = get_ebook(book); |
| 50 |
img.src = book.thumbnail_url; |
97 |
var a = document.createElement("a"); |
| 51 |
$(this).append(img); |
98 |
a.href = booksInfo.url; |
| 52 |
var re = /^openlibrary-thumbnail-preview/; |
99 |
if (book.cover) { |
| 53 |
if ( re.exec($(this).attr("id")) ) { |
100 |
var img = document.createElement("img"); |
| 54 |
$(this).append( |
101 |
if (is_opacdetail) { |
| 55 |
'<div style="margin-bottom:5px; margin-top:-5px;font-size:9px">' + |
102 |
img.src = book.cover.medium; |
| 56 |
'<a href="' + |
103 |
$(this).append(img); |
| 57 |
book.info_url + |
104 |
$(this).append( |
| 58 |
'">Preview</a></div>' |
105 |
'<div class="results_summary">' + '<a href="' + book.url + '">Preview</a></div>' |
| 59 |
); |
106 |
); |
| 60 |
} |
107 |
$(this).append( |
| 61 |
} else { |
108 |
'<div class="results_summary">' +ebook+'</div>' |
| 62 |
var message = document.createElement("span"); |
109 |
); |
| 63 |
$(message).attr("class","no-image"); |
110 |
} else { |
| 64 |
$(message).html(NO_OL_JACKET); |
111 |
img.src = book.cover.small; |
| 65 |
$(this).append(message); |
112 |
$(this).append(img); |
| 66 |
} |
113 |
} |
| 67 |
}); |
114 |
} else { |
| 68 |
} |
115 |
var message = document.createElement("span"); |
| 69 |
} |
116 |
$(message).attr("class","no-image"); |
|
|
117 |
$(message).html(NO_OL_JACKET); |
| 118 |
$(this).append(message); |
| 119 |
} |
| 120 |
}); |
| 121 |
} |
| 122 |
} |
| 70 |
}; |
123 |
}; |
| 71 |
- |
|
|