Bug 41128: Only use data rating if it's available

This patch prevents span elements being filled with "undefined"
which are then shown to screen readers and print output.

Test plan:
0. Apply the patch
1. Enable the following system preference: OpacStarRatings (results,
   details, and patron).
2. Check out an item to a user you can log in as (e.g. koha user)
3. Go to /cgi-bin/koha/opac-user.pl in the OPAC
4. Click "Print" on the toolbar above the summary table
5. Note that 5 occurrences of "undefined" do not appear next to the
   title in the print output

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
David Cook 2025-10-29 05:24:12 +00:00 committed by Lucas Gass
parent fbbf00c904
commit 4bb7582066
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
1 changed files with 5 additions and 1 deletions

View File

@ -70,7 +70,11 @@ $(document).ready(function () {
$(this).replaceWith(span);
} else {
var data_rating = $(this).attr("data-rating-value");
$(this).append('<span class="sr-only">' + data_rating + "</span>");
if (data_rating) {
$(this).append(
'<span class="sr-only">' + data_rating + "</span>"
);
}
}
});
});