Bug 25031: (QA follow-up) Avoid displaying extra navigation
authorOwen Leonard <oleonard@myacpl.org>
Thu, 23 Jul 2020 19:49:33 +0000 (19:49 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 24 Jul 2020 12:09:30 +0000 (14:09 +0200)
This patch reworks the construction of the navigation links in such a
way that they are built during a loop over an updated jQuery object.
Previously the stored variable might not reflect that some elements
had been removed.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt

index c09ccdb..d2376ab 100644 (file)
                             <div class="hint">Image from Adlibris</div>
                         </div>
                     [% END %]
+
                     [% IF ( AmazonCoverImages && normalized_isbn) %]
                         <div class="cover-image" id="amazon-bookcoverimg">
                             <a href="http://www.amazon[% AmazonTld | uri %]/gp/reader/[% normalized_isbn | uri %][% AmazonAssocTag | uri %]#reader-link">
                             <div class="hint">Image from Amazon.com</div>
                         </div>
                     [% END %]
+
                     [% IF ( IntranetCoce && CoceProviders && normalized_isbn ) %]
                         [% coce_id = normalized_ean || normalized_isbn %]
                         <div class="cover-image" id="coce-coverimg">
@@ -936,8 +938,7 @@ Note that permanent location is a code, and location may be an authval.
         // http://www.oreillynet.com/pub/a/javascript/2003/10/21/amazonhacks.html
         function verify_images() {
             // Loop over each container in the template which contains covers
-            var coverSlides = $(".cover-image");
-            coverSlides.each( function( index ){
+            $(".cover-image").each( function( index ){
                 var div = $(this);
                 // Find the image in the container
                 var img = div.find("img")[0];
@@ -977,24 +978,26 @@ Note that permanent location is a code, and location may be an authval.
                                 div.find(".hint").html(_("Coce image from Open Library"));
                             }
                         }
-                        // If more that one slide is present, add a navigation link
-                        // for activating the slide
-                        if( coverSlides.length > 1 ){
-                            var covernav = $("<a href=\"#\" data-num=\"" + index + "\" class=\"cover-nav\"></a>");
-                            if( index == 0 ){
-                                // Set the first navigation link as active
-                                $(covernav).addClass("nav-active");
-                            }
-                            $(covernav).html("<i class=\"fa fa-circle\"></i>");
-                            $("#cover-slides").addClass("cover-slides").append( covernav );
-                        }
                     }
                 }
             });
-            if( $(".cover-image").length < 2 ){
-                /* Don't show controls for switching between covers if there is only 1 */
-                $(".cover-nav").remove();
+
+            var coverSlides = $(".cover-image");
+            if( coverSlides.length > 1 ){
+                coverSlides.each(function( index ){
+                    // If more that one slide is present, add a navigation link
+                    // for activating the slide
+                    var covernav = $("<a href=\"#\" data-num=\"" + index + "\" class=\"cover-nav\"></a>");
+                    if( index == 0 ){
+                        // Set the first navigation link as active
+                        $(covernav).addClass("nav-active");
+                    }
+                    $(covernav).html("<i class=\"fa fa-circle\"></i>");
+                    $("#cover-slides").addClass("cover-slides").append( covernav );
+
+                });
             }
+
             if( $(".cover-image:visible").length < 1 ){
                 $("#cover-slides").remove();
             }