From 952bc38b131e4f7f537ae516335e7f2f0df5e989 Mon Sep 17 00:00:00 2001 From: Dan Scott Date: Thu, 2 Jun 2011 01:42:49 -0400 Subject: [PATCH] Don't make OpenLibrary requests without an ID It is rather silly to make requests if you have not pulled any IDs out of the records to pass along to OpenLibrary, so do not do that. Also refactor and add a bit more defensiveness. Signed-off-by: Dan Scott --- Open-ILS/web/opac/skin/default/js/result_common.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Open-ILS/web/opac/skin/default/js/result_common.js b/Open-ILS/web/opac/skin/default/js/result_common.js index a7e9fd776f..00194f1b52 100644 --- a/Open-ILS/web/opac/skin/default/js/result_common.js +++ b/Open-ILS/web/opac/skin/default/js/result_common.js @@ -451,24 +451,22 @@ function resultDisplayRecord(rec, pos, is_mr) { var r = table.rows[pos + 1]; var currentISBN = cleanISBN(rec.isbn()); - if (OpenLibraryLinks) { - var olspan = $n(r, 'openLibraryLink'); - if (currentISBN) { + if (currentISBN) { + isbnList.push(currentISBN); + if (OpenLibraryLinks) { + var olspan = $n(r, 'openLibraryLink'); olspan.setAttribute('name', olspan.getAttribute('name') + '-' + currentISBN ); } - } - if (googleBooksLink) { - var gbspan = $n(r, "googleBooksLink"); - if (currentISBN) { + if (googleBooksLink) { + var gbspan = $n(r, "googleBooksLink"); gbspan.setAttribute( 'name', gbspan.getAttribute('name') + '-' + currentISBN ); - isbnList.push(currentISBN); } } @@ -686,7 +684,7 @@ function resultBuildFormatIcons( row, rec, is_mr ) { } function fetchOpenLibraryLinks() { - if (isbnList && OpenLibraryLinks) { + if (isbnList.length > 0 && OpenLibraryLinks) { /* OpenLibrary supports a number of different identifiers: * ISBN: isbn: * LCCN: lccn: @@ -736,6 +734,11 @@ function renderOpenLibraryLinks(response) { } }); + /* If there are no books to read or borrow, move on */ + if (!ol_ebooks[isbn]) { + continue; + } + /* Now populate the results page with our ebook goodness*/ /* Go for the jugular - exact match with full access */ if (ol_ebooks[isbn]['exact_full']) { -- 2.11.0