@@ -, +, @@ --- koha-tmpl/intranet-tmpl/js/coce.js | 6 ++-- .../prog/en/modules/catalogue/detail.tt | 33 +++++++++++++++++-- koha-tmpl/opac-tmpl/bootstrap/js/coce.js | 5 +-- 3 files changed, 37 insertions(+), 7 deletions(-) --- a/koha-tmpl/intranet-tmpl/js/coce.js +++ a/koha-tmpl/intranet-tmpl/js/coce.js @@ -20,7 +20,7 @@ KOHA.coce = { var id = $(this).attr("class"); // id=isbn if (id !== '') { ids.push(id); } }); - if (ids.length == 0) return; + if (ids.length == 0) { this.done = 1; return; } ids = ids.join(','); var coceURL = host + '/cover?id=' + ids + '&provider=' + provider; $.ajax({ @@ -44,7 +44,9 @@ KOHA.coce = { }); } }, - + }).then(function(){ + // Cannot access 'this' from here + KOHA.coce.done = 1; }); } --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -1600,9 +1600,36 @@ Note that permanent location is a code, and location may be an authval. }); }); - $(window).load(function() { - verify_cover_images(); - }); + + [% IF ( IntranetCoce && CoceProviders ) %] + 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() { + wait_for_images(verify_cover_images); + }); + [% ELSE %] + $(window).load(function() { + verify_cover_images; + }); + [% END %] [% IF ( Koha.Preference('NovelistSelectStaffEnabled') && Koha.Preference('NovelistSelectStaffProfile') && ( normalized_isbn || normalized_upc ) ) %] --- a/koha-tmpl/opac-tmpl/bootstrap/js/coce.js +++ a/koha-tmpl/opac-tmpl/bootstrap/js/coce.js @@ -44,9 +44,10 @@ KOHA.coce = { }); } }, - + }).then(function(){ + // Cannot access 'this' from here + KOHA.coce.done = 1; }); - this.done = 1; } }; --