From a01e80513b3fe07f307637b1a2ee54223d9736da Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Fri, 22 Dec 2023 21:47:49 +0000 Subject: [PATCH] Bug 35647: Use callback when waiting for Coce to load 1. Turn on all CoceProviders and IntranetCoce. 2. Set CoceHost to 'https://coce.bywatersolutions.com' 3. Do a search and notice that no Coce images load on the results page. 4. Apply patch, clear browser cache and try again. 5. Images should load. --- .../intranet-tmpl/prog/js/pages/results.js | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/pages/results.js b/koha-tmpl/intranet-tmpl/prog/js/pages/results.js index 511dc7d1c1..042e6aa7ff 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/pages/results.js +++ b/koha-tmpl/intranet-tmpl/prog/js/pages/results.js @@ -46,8 +46,8 @@ function verify_cover_images() { if ( (img.complete != null) && (!img.complete) || img.naturalHeight == 0 ) { /* No image was loaded via the CustomCoverImages system preference */ /* Remove the container */ - blanks.push( coverId ); div.remove(); + blanks.push( coverId ); } } @@ -75,10 +75,9 @@ function verify_cover_images() { } } /* /IF image loaded */ } else { - blanks.push( coverId ); div.remove(); + blanks.push( coverId ); } /* /IF there is an image tag */ - /* console.log( coverImages ); */ }); /* Show the first cover image slide after empty ones have been removed */ @@ -100,8 +99,28 @@ function verify_cover_images() { }); } +let counter_wait = 0; +function wait_for_images(cb){ + + var loaded = 1; + counter_wait++; + + if ( loaded ) { + loaded = KOHA.coce.done; + } + + if (!loaded && counter_wait < 50) {// Do not wait more than 5 seconds + window.setTimeout(function(){wait_for_images(cb);}, 100); + } else { + if (counter_wait >= 50 ) { + console.log("Could not retrieve the images") + } + cb(); + } +} + $(window).load(function() { - verify_cover_images(); + wait_for_images(verify_cover_images); }); var Sticky; -- 2.30.2