Koha/koha-tmpl/opac-tmpl/bootstrap/js/openlibrary.js
Owen Leonard 049bd2da23 Bug 13341 - Hard-coded "Preview" text in OPAC openlibrary.js
The OpenLibrary JavaScript includes an untranslated string, "Preview."
This patch move the string to the template so that it can be translated.

To test, apply the patch and test that the translator picks up the
string:

1. From misc/translator run 'perl translate update [lang]' (e.g. de-DE)
2. Edit misc/translator/po/[lang]-opac-bootstrap.po and add a
   translation for the updated "Preview" string
3. Remove the "#, fuzzy" marker from that entry
4. From misc/translator run 'perl translate install [lang]'
5. Enable the [lang] translation for the OPAC in system preferences
6. Enable the OpenLibraryCovers system preference.
7. In the OPAC switch to the [lang] translation.
7. View the detail page for a title for which there is an OpenLibrary
   cover image. Below it you should see a preview link with the
   translated string you added in step 2.

Works as expected.
Signed-off-by: Marc Véron <veron@veron.ch>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
2014-12-28 20:44:26 -03:00

67 lines
2.5 KiB
JavaScript

if (typeof KOHA == "undefined" || !KOHA) {
var KOHA = {};
}
/**
* A namespace for OpenLibrary related functions.
*/
KOHA.OpenLibrary = {
/**
* Search all:
* <div title="biblionumber" id="isbn" class="openlibrary-thumbnail"></div>
* or
* <div title="biblionumber" id="isbn" class="openlibrary-thumbnail-preview"></div>
* and run a search with all collected isbns to Open Library Book Search.
* The result is asynchronously returned by OpenLibrary and catched by
* olCallBack().
*/
GetCoverFromIsbn: function() {
var bibkeys = [];
$("[id^=openlibrary-thumbnail]").each(function(i) {
bibkeys.push("ISBN:" + $(this).attr("class")); // id=isbn
});
bibkeys = bibkeys.join(',');
var scriptElement = document.createElement("script");
scriptElement.setAttribute("id", "jsonScript");
scriptElement.setAttribute("src",
"http://openlibrary.org/api/books?bibkeys=" + escape(bibkeys) +
"&callback=KOHA.OpenLibrary.olCallBack&jscmd=data");
scriptElement.setAttribute("type", "text/javascript");
document.documentElement.firstChild.appendChild(scriptElement);
},
/**
* Add cover pages <div
* and link to preview if div id is gbs-thumbnail-preview
*/
olCallBack: function(booksInfo) {
for (id in booksInfo) {
var book = booksInfo[id];
var isbn = id.substring(5);
$("[id^=openlibrary-thumbnail]."+isbn).each(function() {
var is_opacdetail = /openlibrary-thumbnail-preview/.exec($(this).attr("id"));
var a = document.createElement("a");
a.href = booksInfo.url;
if (book.cover) {
var img = document.createElement("img");
if (is_opacdetail) {
img.src = book.cover.medium;
$(this).empty().append(img);
$(this).append('<div class="results_summary">' + '<a href="' + book.url + '">' + OL_PREVIEW + '</a></div>');
} else {
img.src = book.cover.medium;
img.height = '110';
$(this).append(img);
}
} else {
var message = document.createElement("span");
$(message).attr("class","no-image");
$(message).html(NO_OL_JACKET);
$(this).append(message);
}
});
}
}
};