Bug 26037: openlibrary.org is hit on every Koha requests

This patch moves the inclusion of Open Library JavaScript from
opac-bottom.inc to the three templates where it might be used.

In addition, the Open Library JS has been modified to check for the
existence of the relevant markup on the page before executing a query.

Unrelated: The Open Library label is now hidden when the status returned
is "Not found." Previously this information was displayed.

To test, apply the patch and enable the OpenLibrarySearch system
preference.

 - Perform a search in the OPAC which will return results from Open
   Library. Some ISBNs: 0140423826, 0395082552, 0679436405.
   - On the search result page there should be an Open Library "Read
     now" button for each result that can be opened for reading in Open
     Library.
 - Add these titles to a list and view the list.
   - The "Read now" button should appear on the list page.
 - View the details for one of these titles.
   - The "Read now" button should appear on the page below the holdings.
 - Watch the browser's developer tools on these and other pages in the
   OPAC. There should be no errors in the console and no 404 errors in
   the network tab.

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>

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

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Owen Leonard 2020-07-27 12:26:41 +00:00 committed by Jonathan Druart
parent e1509855d3
commit 5bad8da970
5 changed files with 31 additions and 22 deletions

View file

@ -176,6 +176,10 @@ $.widget.bridge('uitooltip', $.ui.tooltip);
var MSG_OVERDRIVE_DOWNLOAD_AS = _( "Download as: " );
var MSG_OVERDRIVE_CANNOT_CHECKOUT = _("Item cannot be checked out. There are no available formats");
[% END %]
[% IF OpenLibraryCovers || OpenLibrarySearch %]
var NO_OL_JACKET = _("No cover image available");
var OL_PREVIEW = _("Preview");
[% END %]
[% IF ( OPACAmazonCoverImages || SyndeticsCoverImages ) %]
$(window).load(function() {
verify_images();
@ -231,16 +235,6 @@ $.widget.bridge('uitooltip', $.ui.tooltip);
</script>
[% END %]
[% IF OpenLibraryCovers || OpenLibrarySearch %]
[% Asset.js("js/openlibrary.js") | $raw %]
<script>
//<![CDATA[
var NO_OL_JACKET = _("No cover image available");
var OL_PREVIEW = _("Preview");
//]]>
</script>
[% END %]
[% IF OPACLocalCoverImages %]
[% Asset.js("js/localcovers.js") | $raw %]
<script>

View file

@ -1384,6 +1384,9 @@
[% Asset.js("js/verovio.js") | $raw %]
[% END %]
[% Asset.js("lib/emoji-picker/js/emoji-picker-all.min.js") | $raw %]
[% IF OpenLibraryCovers || OpenLibrarySearch %]
[% Asset.js("js/openlibrary.js") | $raw %]
[% END %]
<script>
window.emojiPicker = new EmojiPicker({
emojiable_selector: '[data-emojiable=true]',

View file

@ -619,7 +619,12 @@
[% Asset.js("js/authtoresults.js") | $raw %]
[% Asset.js("lib/hc-sticky.js") | $raw %]
[% IF ( OpacHighlightedWords ) %][% Asset.js("lib/jquery/plugins/jquery.highlight-3.js") | $raw %]
[% END %]<script>
[% END %]
[% IF OpenLibraryCovers || OpenLibrarySearch %]
[% Asset.js("js/openlibrary.js") | $raw %]
[% END %]
<script>
[% IF ( Koha.Preference( 'opacuserlogin' ) == 1 ) && ( Koha.Preference( 'RequestOnOpac' ) == 1 ) %]
function holdMultiple() {
var checkedBiblioNums = ""; // Separated by "/"

View file

@ -496,6 +496,7 @@
[% INCLUDE 'title-actions-menu.inc' items=itemsloo %]
[% INCLUDE "openlibrary-readapi.inc" bib = itemsloo %]
<!-- COinS / Openurl -->
<span class="Z3988" title="[% itemsloo.coins | html %]"></span>
</td>
@ -762,6 +763,9 @@
[% BLOCK jsinclude %]
[% Asset.js("lib/jquery/plugins/jquery.checkboxes.min.js") | $raw %]
[% Asset.js("lib/hc-sticky.js") | $raw %]
[% IF OpenLibraryCovers || OpenLibrarySearch %]
[% Asset.js("js/openlibrary.js") | $raw %]
[% END %]
<script>
var MSG_REMOVE_FROM_LIST = _("Are you sure you want to remove these items from the list?");
var MSG_REMOVE_ONE_FROM_LIST = _("Are you sure you want to remove this item from the list?");

View file

@ -112,6 +112,8 @@ var ol_readapi_automator =
// 'constants'
var readapi_bibids = ['isbn', 'lccn', 'oclc', 'olid', 'iaid', 'bibkeys'];
var magic_classname = 'ol_readapi_book';
var ol_readapi_books = $("." + magic_classname );
var result;
// added to book divs to correlate with API results
var magic_bookid = 'ol_bookid';
@ -171,9 +173,8 @@ function make_read_button(bookdata) {
function default_decorate_el_fn(el, bookdata) {
// Note that 'bookdata' may be undefined, if the Read API call
// didn't return results for this book
if (!bookdata) {
decoration = 'Not found';
} else {
var decoration;
if (bookdata) {
decoration = make_read_button(bookdata);
}
if (decoration) {
@ -216,15 +217,17 @@ function do_query(q, decorate_el_fn) {
});
}
// Do stuff
var q = create_query();
do_query(q);
if( ol_readapi_books.length > 0 ){
// Do stuff
var q = create_query();
do_query(q);
result = {
do_query: do_query,
create_query: create_query,
make_read_button: make_read_button
};
result = {
do_query: do_query,
create_query: create_query,
make_read_button: make_read_button
};
}
return result;
})(); // close anonymous scope