Bug 32307: (follow-up) Fix gallery when Coce is enabled
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 25 Nov 2022 06:04:43 +0000 (07:04 +0100)
committerTomas Cohen Arazi <tomascohen@theke.io>
Mon, 20 Feb 2023 12:54:17 +0000 (09:54 -0300)
Yet another fix, this is porting the following change to the intranet:
  commit 1916c644808577beb3170d642f93b456bfcc5c56
  Bug 28180: Fix bug with first image does not exist

To recreate the problem:
Enable Coce
Go to biblionmber=5 detail
=> No image (but one is displayed on the search result)
Add a local cover image
=> Only the local cover image is displayed
Apply this patch
=> Both images are displayed
Remove the local cover image
=> Image from coce is displayed

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt

index 5330deb..2e20d2e 100644 (file)
@@ -1320,59 +1320,56 @@ Note that permanent location is a code, and location may be an authval.
             // Loop over each container in the template which contains covers
             $(".cover-slider").each(function(){
                 var lightbox_descriptions = [];
+                var first_shown = 0;
                 $(this).find(".cover-image").each( function( index ){
-                    var div = $(this);
-                    // Find the image in the container
-                    var img = div.find("img")[0];
-                    if( $(img).length > 0 ){
-                        var description = "";
-                        if( (img.complete != null) && (!img.complete) || img.naturalHeight == 0 ){
-                            // No image loaded in the container. Remove the slide
-                            div.remove();
-                        } else {
-                            // All slides start hidden. If this is the first one, show it.
-                            if( index == 0 ){
-                                div.show();
-                            }
-                            // Check if Amazon image is present
-                            if ( div.attr("id") == "amazon-bookcoverimg"  ) {
-                                w = img.width;
-                                h = img.height;
-                                if ((w == 1) || (h == 1)) {
-                                    // Amazon returned single-pixel placeholder
-                                    // Remove the container
-                                    div.remove();
-                                } else {
-                                    lightbox_descriptions.push(_("Amazon cover image (<a href='%s'>see the original image</a>)").format($(img).data('link')));
-                                }
-                            } else if( div.attr("id") == "custom-coverimg" ){
-                                if ( (img.complete != null) && (!img.complete) || img.naturalHeight == 0 ) {
-                                    // No image was loaded via the CustomCoverImages system preference
-                                    // Remove the container
-                                    div.remove();
-                                } else {
-                                    lightbox_descriptions.push("Custom cover image");
-                                }
-                            } else if ( div.attr("id") == "syndetics-bookcoverimg" ){
-                                    lightbox_descriptions.push(_("Syndetics cover image (<a href='%s'>see the original image</a>)").format($(img).data('link')));
+                var div = $(this);
+                // Find the image in the container
+                var img = div.find("img")[0];
+                if( $(img).length > 0 ){
+                    var description = "";
+                        // All slides start hidden. If this is the first one, show it.
+                        if( first_shown == 0 ){
+                            div.show();
+                            first_shown = 1;
+                        }
+                        // Check if Amazon image is present
+                        if ( div.attr("id") == "amazon-bookcoverimg"  ) {
+                            w = img.width;
+                            h = img.height;
+                            if ((w == 1) || (h == 1)) {
+                                // Amazon returned single-pixel placeholder
+                                // Remove the container
+                                div.remove();
+                            } else {
+                                lightbox_descriptions.push(_("Amazon cover image (<a href='%s'>see the original image</a>)").format($(img).data('link')));
                             }
-                            else if( div.hasClass("coce-coverimg" ) ){
-                                // Identify which service's image is being loaded by Coce
-                                var coce_description;
-                                if( $(img).attr("src").indexOf('amazon.com') >= 0 ){
-                                    coce_description = ("Coce image from Amazon.com");
-                                } else if( $(img).attr("src").indexOf('google.com') >= 0 ){
-                                    coce_description = _("Coce image from Google Books");
-                                } else if( $(img).attr("src").indexOf('openlibrary.org') >= 0 ){
-                                    coce_description = _("Coce image from Open Library");
-                                }
-                                div.find(".hint").html(coce_description);
-                                lightbox_descriptions.push(coce_description);
-                            } else if ( div.attr("class") == "cover-image local-coverimg" ) {
-                                lightbox_descriptions.push(_("Local cover image (<a href='%s'>edit</a>)").format($(img).data('link')));
+                        } else if( div.attr("id") == "custom-coverimg" ){
+                            if ( (img.complete != null) && (!img.complete) || img.naturalHeight == 0 ) {
+                                // No image was loaded via the CustomCoverImages system preference
+                                // Remove the container
+                                div.remove();
                             } else {
-                                lightbox_descriptions.push(_("Cover image source unknown"));
+                                lightbox_descriptions.push("Custom cover image");
                             }
+                        } else if ( div.attr("id") == "syndetics-bookcoverimg" ){
+                                lightbox_descriptions.push(_("Syndetics cover image (<a href='%s'>see the original image</a>)").format($(img).data('link')));
+                        }
+                        else if( div.hasClass("coce-coverimg" ) ){
+                            // Identify which service's image is being loaded by Coce
+                            var coce_description;
+                            if( $(img).attr("src").indexOf('amazon.com') >= 0 ){
+                                coce_description = ("Coce image from Amazon.com");
+                            } else if( $(img).attr("src").indexOf('google.com') >= 0 ){
+                                coce_description = _("Coce image from Google Books");
+                            } else if( $(img).attr("src").indexOf('openlibrary.org') >= 0 ){
+                                coce_description = _("Coce image from Open Library");
+                            }
+                            div.find(".hint").html(coce_description);
+                            lightbox_descriptions.push(coce_description);
+                        } else if ( div.attr("class") == "cover-image local-coverimg" ) {
+                            lightbox_descriptions.push(_("Local cover image (<a href='%s'>edit</a>)").format($(img).data('link')));
+                        } else {
+                            lightbox_descriptions.push(_("Cover image source unknown"));
                         }
                     }
                 });