[Koha] How can I keep only one cover image in OPAC?

Eric Phetteplace ephetteplace at cca.edu
Sun Jul 10 14:34:58 NZST 2022


OK this is how we handle cover images on the search results and opac
details pages:
https://github.com/cca/koha_snippets/blob/main/catalog-js/double-cover-img.js

let selector = $('.coverimages').length ? '.coverimages' : '#bookcover'
if ($(selector).length && !!MutationObserver) {
let observer = new MutationObserver((mutations) => {
for (let mutation of mutations) {
let covers = $(mutation.target).closest(selector)
if (covers.find('[id*="-thumbnail"] img').length === 2) {
covers.find('[id^="coce-thumbnail"]').remove()
}
}
})
Array.from(document.querySelectorAll(selector)).forEach((el) => {
observer.observe(el, { subtree: true, childList: true })
})
}

It's more complicated than you'd expect because cover images from COCE are
loaded asynchronously and, as far as I know, Koha doesn't give you any
event hooks to know when they've loaded. So I set up a mutation observer to
watch the cover image elements for both pages and remove the COCE one if
there are two. I haven't tested if this works if you're using Amazon and
local cover images but I assume, if it does not, it is a small adjustment.

Best,

ERIC PHETTEPLACE Systems Librarian, Libraries (he/him)

ephetteplace at cca.edu | o 510.594.3660 (cca)

5212 Broadway | Oakland, CA | 94618

CCA is situated on the traditional unceded lands of the Ohlone peoples.

Black-owned bookstores in Oakland: Ashay by the Bay
<https://ashaybythebay.com/>, Marcus Books
<https://www.facebook.com/marcus.books/>

:(){ :|: & };:


On Fri, Jul 8, 2022 at 1:00 PM Eric Phetteplace <ephetteplace at cca.edu>
wrote:

> We've done this with jQuery in OpacUserJS. Whenever we have a local cover
> image, we prefer it. I don't understand the use case for displaying
> multiple cover images (they should be identical or one is wrong, no?). I'm
> away from my laptop but can share our script later, though I'm sure the new
> image display for opac-details breaks it.
>
> Best,
> Eric Phetteplace
> Systems Librarian
> California College of the Arts
>
> On Fri, Jul 8, 2022, 11:19 Victor Barroso Oliveira <vbovictor at gmail.com>
> wrote:
>
>> The question is when he retrieves an incorrect Amazon book cover.
>> For this case, I choose to store the cover locally, but the opac displays
>> both images (Amazon and local).
>> In this case how could I remove only the cover presentation from Amazon.
>>
>> Em sex., 8 de jul. de 2022 às 14:46, Owen Leonard <oleonard at myacpl.org>
>> escreveu:
>>
>> > > How can I keep only one cover image in OPAC?
>> >
>> > If you are using OPACAmazonCoverImages you're not keeping anything,
>> > you're loading the image directly from Amazon (if they have one with a
>> > matching ISBN).
>> >
>> > OPACLocalCoverImages allows you to manually upload a cover image for a
>> > record, so you have complete control over whether something has a
>> > local cover image.
>> >
>> > -- Owen
>> >
>> > --
>> > Web Developer
>> > Athens County Public Libraries
>> > (740) 737-6006
>> > https://www.myacpl.org
>> >
>> _______________________________________________
>>
>> Koha mailing list  http://koha-community.org
>> Koha at lists.katipo.co.nz
>> Unsubscribe: https://lists.katipo.co.nz/mailman/listinfo/koha
>>
>


More information about the Koha mailing list